parent
0fbc0c02e0
commit
a954326103
@ -1,19 +1,100 @@
|
|||||||
import time
|
import time
|
||||||
from glob import glob
|
import threading
|
||||||
|
import DobotDllType as dType
|
||||||
|
|
||||||
from pydobot import Dobot
|
class Candybot:
|
||||||
|
def __init__(self):
|
||||||
|
CON_STR = {
|
||||||
|
dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError",
|
||||||
|
dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
|
||||||
|
dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"}
|
||||||
|
|
||||||
available_ports = glob('/dev/cu*usb*') # mask for OSX Dobot port
|
#Load Dll
|
||||||
if len(available_ports) == 0:
|
self.api = dType.load()
|
||||||
print('no port found for Dobot Magician')
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
device = Dobot(port=available_ports[0])
|
#Connect Dobot
|
||||||
|
state = dType.ConnectDobot(self.api, "", 115200)[0]
|
||||||
|
print("Connect status:",CON_STR[state])
|
||||||
|
|
||||||
time.sleep(0.5)
|
if (state == dType.DobotConnect.DobotConnect_NoError):
|
||||||
device.speed(100)
|
|
||||||
device.go(250.0, 0.0, 25.0)
|
#Clean Command Queued
|
||||||
device.speed(10)
|
dType.SetQueuedCmdClear(self.api)
|
||||||
device.go(250.0, 0.0, 0.0)
|
|
||||||
time.sleep(2)
|
#Async Motion Params Setting
|
||||||
device.close()
|
dType.SetHOMEParams(self.api, 250, 0, 50, 0, isQueued = 1)
|
||||||
|
dType.SetJOGJointParams(self.api, 50, 50, 50, 50, 50, 50, 50, 50, isQueued = 1)
|
||||||
|
dType.SetJOGCommonParams(self.api, 100, 100, isQueued = 1)
|
||||||
|
|
||||||
|
#linear rail
|
||||||
|
dType.SetDeviceWithL(self.api, 1)
|
||||||
|
dType.SetJOGLParams(self.api, 50, 50, isQueued=0)
|
||||||
|
|
||||||
|
#Async Home
|
||||||
|
dType.SetHOMECmd(self.api, temp = 0, isQueued = 1)
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
#Disconnect Dobot
|
||||||
|
dType.DisconnectDobot(self.api)
|
||||||
|
|
||||||
|
def base(self, direction):
|
||||||
|
if direction == 1:
|
||||||
|
dType.SetJOGCmd(self.api,1,1)
|
||||||
|
|
||||||
|
elif direction == -1:
|
||||||
|
dType.SetJOGCmd(self.api,1,2)
|
||||||
|
|
||||||
|
else :
|
||||||
|
return
|
||||||
|
threading.Timer(0.1,self.stop).start()
|
||||||
|
|
||||||
|
def rearArm(self, direction):
|
||||||
|
if direction == 1:
|
||||||
|
dType.SetJOGCmd(self.api,1,3)
|
||||||
|
|
||||||
|
elif direction == -1:
|
||||||
|
dType.SetJOGCmd(self.api,1,4)
|
||||||
|
|
||||||
|
else :
|
||||||
|
return
|
||||||
|
threading.Timer(0.1,self.stop).start()
|
||||||
|
|
||||||
|
def forearm(self, direction):
|
||||||
|
if direction == 1:
|
||||||
|
dType.SetJOGCmd(self.api,1,5)
|
||||||
|
|
||||||
|
elif direction == -1:
|
||||||
|
dType.SetJOGCmd(self.api,1,6)
|
||||||
|
|
||||||
|
else :
|
||||||
|
return
|
||||||
|
threading.Timer(0.1,self.stop).start()
|
||||||
|
|
||||||
|
def gripperRotation(self, direction):
|
||||||
|
if direction == 1:
|
||||||
|
dType.SetJOGCmd(self.api,1,7)
|
||||||
|
|
||||||
|
elif direction == -1:
|
||||||
|
dType.SetJOGCmd(self.api,1,8)
|
||||||
|
|
||||||
|
else :
|
||||||
|
return
|
||||||
|
threading.Timer(0.1,self.stop).start()
|
||||||
|
|
||||||
|
def linear(self, direction):
|
||||||
|
if direction == 1:
|
||||||
|
dType.SetJOGCmd(self.api,1,9)
|
||||||
|
|
||||||
|
elif direction == -1:
|
||||||
|
dType.SetJOGCmd(self.api,1,10)
|
||||||
|
|
||||||
|
else :
|
||||||
|
return
|
||||||
|
threading.Timer(0.1,self.stop).start()
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
dType.SetJOGCmd(self.api, 1, 0)
|
||||||
|
|
||||||
|
def panic(self):
|
||||||
|
dType.SetQueuedCmdForceStopExec(self.api)
|
Loading…
Reference in new issue