Official website download address :[OFFICIAL]Dobot Magician Download Center | DOBOT
stay Python There are two files in the demo .
(1)DobotControl.py:Dobot Interface secondary packaging
(2)DobotDllType.py: Specific implementation documents
Running DobotControl.py Before , Please put Dobot DLLS Directory added to python In the running directory of , Or add it to the system environment variable .
Different versions Python Need corresponding Demo The corresponding version of . for example ,64 Bit Python You should use 64 Bit Python demo, and 32 Bit Python You should use 32 Bit Python demo, Otherwise the program will report an error .
DobotDllType.py Encapsulates the Dobot DLL Of C Type interface , This is a Dobot Of Python Interface . load DLL An example of .( Please ensure that the Dobot DLL Directory added to system environment variables , To ensure correct loading DLL.)
def load():
if platform.system() == "Windows":
print(" Yours dll yes 64 position , In order to run smoothly , Please guarantee your python So is the environment 64 position ")
print("python The environment is :",platform.architecture())
return CDLL("./DobotDll.dll", RTLD_GLOBAL)
elif platform.system() == "Darwin":
return CDLL("./libDobotDll.dylib", RTLD_GLOBAL)
elif platform.system() == "Linux":
return cdll.loadLibrary("libDobotDll.so")
When calling the interface related to motion (PTP、JOG etc. ) when , Ben DEMO Use queue mode .
(1) load DLL And get the Store object (API). When calling Python API when , This object will be used .
api = dType.load()
(2) Connect to Dobot Magician and print connection information . After successful connection , The relevant code will be processed .
state = dType.ConnectDobot(api, "", 115200)[0]
print("Connect status:",CON_STR[state])
if (state == dType.DobotConnect.DobotConnect_NoError):
#Dobot Operation code
dType.DisconnectDobot(api)
(3) Control queue :
dType.SetQueuedCmdClear(api) # Clear queue
dType.SetQueuedCmdStartExec(api) # Start the queue
dType.SetQueuedCmdStopExec(api) # Stop queue
(4) Set the motion parameters
dType.SetHOMEParams(api, 200, 200, 200, 200, isQueued = 1)
dType.SetPTPJointParams(api, 200, 200, 200, 200, 200, 200, 200, 200, isQueued = 1)
dType.SetPTPCommonParams(api, 100, 100, isQueued = 1)
(5) take PTP The command is downloaded to the queue , And get the index of the last command .
for i in range(0, 5):
if i % 2 == 0:
offset = 50
else:
offset = -50
lastIndex = dType.SetPTPCmd(api, dType.PTPMode.PTPMOVLXYZMode, 200 + offset, offset, offset, offset, isQueued = 1)[0]
(6) Wait for the last motion command to complete .
# If the instruction queue has not been completed, wait
while lastIndex > dType.GetQueuedCmdCurrentIndex(api)[0]:
dType.dSleep(100)