python scratch,wince 開發_正運動技術運動控制卡應用開發教程之Python

 2023-11-30 阅读 26 评论 0

摘要:眾所周知,Python作為一門面向對象的新興開發語言,具有完善的基礎代碼庫,實用性與代碼可讀性強,被越來越多的人應用于智能裝備的運動控制。  今天正運動技術與大家分享一下運動控制卡應用開發教程之Python。  在正式學習之前,我們先了解

眾所周知,Python作為一門面向對象的新興開發語言,具有完善的基礎代碼庫,實用性與代碼可讀性強,被越來越多的人應用于智能裝備的運動控制。

  今天正運動技術與大家分享一下運動控制卡應用開發教程之Python。

  在正式學習之前,我們先了解一下正運動技術的運動控制卡ECI2418和ECI2618。這兩款產品分別是4軸,6軸運動控制卡。

python scratch、

065b4f0b99a36c3de694b03868edc799.png

  ECI2418支持4軸脈沖輸入與編碼器反饋,板載24點輸入,16點輸出,2AD,2DA,支持手輪接口,其中特定輸出支持高速PWM控制。

7996708d1d3ebbfe87aecc4d1adcd1a5.png

  ECI2618支持6軸脈沖輸入與編碼器反饋,板載24點輸入,16點輸出,2AD,2DA,支持手輪接口,其中特定輸出支持高速PWM控制。

scratch怎么運行。

5c894d803ef02e7fecfc00deae6f7cbf.png

  ECI2418,ECI2618均使用同一套API函數,均支持C、C++、C#、LabView、Python、Delphi等開發語言,支持VC6.0、VB6.0、Qt、.Net等平臺,支持Windows、Linux、WinCE、iMac等操作系統。

以下是Python語言的開發流程。

0f99778ddbaf89af84880a69964e70ee.png

scratch2.0編程、1、新建項目。

  打開Pycharm軟件進行操作,點擊Create New Project新建項目。

a4eebf3f68ecb245f5be79f1fa8157cf.png

2、設置Python項目存放路徑。

  此過程主要包含三步:

  選擇Python項目→選擇Python項目將存放的路徑→創建Python項目。

f86ccb2bf184b4910e495a136c7cea91.png

  3、新建Python文件。

  在Python項目中新建Python文件,右鍵CratPython文件夾,選擇“New→PythonFile”,創建新的Python 文件。

88007ce8c99faa6a96e809cbbd151fa8.png

  選擇“New→Python File”

  創建新的Python 文件

4、將Python動態庫復制到Python項目中。

7faa478b77b6982a21f755e012b798d0.png

5、模塊導入并加載動態鏈接庫。

  首先把Python中的兩個模塊導入(platform和ctypes模塊),其中ctypes模塊提供和C語言兼容的數據類型,能夠很方便地調用動態鏈接庫中輸出的C接口函數。

importplatform

import ctypes

#運行環境判斷

  systype = platform.system()

ifsystype == 'Windows':

ifplatform.architecture()[0] == '64bit':

   zauxdll = ctypes.WinDLL( './zauxdll64.dll')

   print( 'Windows x64')

else:

   zauxdll = ctypes.WinDLL( './zauxdll.dll')

   print( 'Windows x86')

elifsystype == 'Darwin':

   zmcdll = ctypes.CDLL( './zmotion.dylib')

   print( "macOS")

elif systype == 'Linux':

   zmcdll = ctypes.CDLL( './libzmotion.so')

   print( "Linux")

else:

  print( "Not Supported!!")

6、通過加載導入的動態庫鏈接庫,調用ZMotion PC函數手冊中的函數。

1)使用操作。

  首先根據控制器連接方式用連接函數連接控制器,輸出控制器句柄,利用控制器的句柄我們就可以對庫函數進行操作。

  即“打開PC函數手冊→搜索想要的函數功能→查看函數說明→通過剛才加載的動態鏈接庫返回的zauxdll對象進行調用”。

5112249755b2f5b2bf0289740b11be3f.png

2)通過ip連接函數接口返回的控制器句柄handle,對控制器的句柄handle操作。

ef4ce1a9af7aa70d1ca3124db64b6401.png

  #####控制器連接#####

def connect(self, ip, console=[]):

ifself.handle.value is not None:

   self.disconnect()

  ip_bytes = ip.encode( 'utf-8')

  p_ip = ctypes.c_char_p(ip_bytes)

   print( "Connecting to", ip, "...")

   ret = zauxdll.ZAux_OpenEth(p_ip, ctypes.pointer(self.handle))

   msg = "Connected"

ifret == 0:

   msg = ip + " Connected"

   self.sys_ip = ip

   self.is_connected = True

else:

   msg = "Connection Failed, Error " + str(ret)

   self.is_connected = False

   console.append(msg)

   console.append(self.sys_info)

returnret

# 斷開連接

def disconnect(self):

  ret = zauxdll.ZAux_Close(self.handle)

  self.is_connected = False

return ret

3)軸參數設置。

#####軸參數設置####

  # 設置軸類型

def set_atype(self, iaxis, iValue):

   ret = zauxdll.ZAux_Direct_SetAtype(self.handle, iaxis, iValue)

ifret == 0:

   print( "Set Axis (", iaxis, ") Atype:", iValue)

else:

   print( "Set Axis (", iaxis, ") Atype fail!")

returnret

 # 設置脈沖當量

def set_units(self, iaxis, iValue):

   ret = zauxdll.ZAux_Direct_SetUnits(self.handle, iaxis, ctypes.c_float(iValue))

if ret == 0:

   print( "Set Axis (", iaxis, ") Units:", iValue)

else:

   print( "Set Axis (", iaxis, ") Units fail!")

returnret

  # 設置軸加速度

def set_accel(self, iaxis, iValue):

   ret = zauxdll.ZAux_Direct_SetAccel(self.handle, iaxis, ctypes.c_float(iValue))

ifret == 0:

   print( "Set Axis (", iaxis, ") Accel:", iValue)

else:

   print( "Set Accel (", iaxis, ") Accel fail!")

returnret

# 設置軸減速度

def set_decel(self, iaxis, iValue):

   ret = zauxdll.ZAux_Direct_SetDecel(self.handle, iaxis, ctypes.c_float(iValue))

ifret == 0:

   print( "Set Axis (", iaxis, ") Decel:", iValue)

else:

   print( "Set Axis (", iaxis, ") Decel fail!")

returnret

# 設置軸運行速度

def set_speed(self, iaxis, iValue):

   ret = zauxdll.ZAux_Direct_SetAccel(self.handle, iaxis, ctypes.c_float(iValue))

ifret == 0:

   print( "Set Axis (", iaxis, ") Speed:", iValue)

else:

   print( "Set Axis (", iaxis, ") Speed fail!")

returnret

4)軸參數讀取。

  #####軸參數讀取####

  # 讀取軸類型

def get_atype(self, iaxis):

   iValue = (ctypes.c_int)()

   ret = zauxdll.ZAux_Direct_GetAtype(self.handle, iaxis, ctypes.byref(iValue))

ifret == 0:

   print( "Get Axis (", iaxis, ") Atype:", iValue.value)

else:

   print( "Get Axis (", iaxis, ") Atype fail!")

return ret

# 讀取軸脈沖當量

def get_units(self, iaxis):

   iValue = (ctypes.c_float)()

   ret = zauxdll.ZAux_Direct_GetUnits(self.handle, iaxis, ctypes.byref(iValue))

if ret == 0:

   print( "Get Axis (", iaxis, ") Units:", iValue.value)

else:

   print( "Get Axis (", iaxis, ") Units fail!")

returnret

# 讀取軸加速度

def get_accel(self, iaxis):

   iValue = (ctypes.c_float)()

   ret = zauxdll.ZAux_Direct_GetAccel(self.handle, iaxis, ctypes.byref(iValue))

ifret == 0:

   print( "Get Axis (", iaxis, ") Accel:", iValue.value)

else:

   print( "Get Axis (", iaxis, ") Accel fail!")

returnret

# 讀取軸減速度

def get_decel(self, iaxis):

   iValue = (ctypes.c_float)()

   ret = zauxdll.ZAux_Direct_GetDecel(self.handle, iaxis, ctypes.byref(iValue))

if ret == 0:

   print( "Get Axis (", iaxis, ") Decel:", iValue.value)

else:

   print( "Get Axis (", iaxis, ") Decel fail!")

returnret

# 讀取軸運行速度

def get_speed(self, iaxis):

   iValue = (ctypes.c_float)()

   ret = zauxdll.ZAux_Direct_GetSpeed(self.handle, iaxis, ctypes.byref(iValue))

ifret == 0:

   print( "Get Axis (", iaxis, ") Speed:", iValue.value)

else:

   print( "Get Axis (", iaxis, ") Speed fail!")

returnret

5)單軸運動。

  #####運動調用####

  # 直線運動

def move(self, iaxis, iValue):

   ret = zauxdll.ZAux_Direct_Single_Move(self.handle, iaxis, iValue)

ifret == 0:

   print( "Axis (", iaxis, ") Move:",iValue)

else:

   print( "Axis (", iaxis, ") Move Fail")

returnret

6)運行程序,輸出結果。

  調用封裝好的函數→運行→輸出程序運行結果。

#####功能使用####

  zaux = ZMCWrapper()

# 連接控制器ip 默認192.168.0.11

  zaux.connect( "192.168.0.11")

# 設置軸0參數

  zaux.set_atype(0, 1)

  zaux.set_units(0, 100)

  zaux.set_accel(0, 1000)

  zaux.set_decel(0, 1000)

  zaux.set_speed(0, 1000)

# 獲取軸0參數

  zaux.get_atype(0)

  zaux.get_units(0)

  zaux.get_accel(0)

  zaux.get_decel(0)

  zaux.get_speed(0)

# 運動

  zaux.move(0, 100) # 軸0直線運動移動100

a8c1804e22633817a4d2c31bc745d7a8.png

  運行并輸出程序運行結果

  正運動技術運動控制卡應用開發教程之Python就分享到這里,更多精彩內容,請關注我們的公眾號。

  本文由正運動小助手原創,歡迎大家轉載,共同學習,一起提高中國智能制造水平。文章版權歸正運動技術所有,如有轉載請注明文章來源。

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/186784.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息