You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.7 KiB

6 years ago
import time
6 years ago
import threading
import DobotDllType as dType
6 years ago
6 years ago
'''
Six actuators:
linear rail
base rotation
rear arm
forarm
gripperrotation
gripper
First five takes argument 1 or -1 (direction)
Example:
#initialisation
c = Candybot()
c.linear(1) # move linear in positive direction
c.gripp() # gripp candy
c.letgo() # let go of candy
c.stopcmp() # stoop compressor
c.panic() # stops everything
'''
6 years ago
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"}
6 years ago
6 years ago
#Load Dll
self.api = dType.load()
6 years ago
6 years ago
#Connect Dobot
state = dType.ConnectDobot(self.api, "", 115200)[0]
print("Connect status:",CON_STR[state])
6 years ago
6 years ago
if (state == dType.DobotConnect.DobotConnect_NoError):
#Clean Command Queued
dType.SetQueuedCmdClear(self.api)
#Async Motion Params Setting
dType.SetHOMEParams(self.api, 250, 0, 50, 0, isQueued = 1)
6 years ago
dType.SetJOGJointParams(self.api, 200, 200, 200, 200, 200, 200, 200, 200, isQueued = 1)
6 years ago
dType.SetJOGCommonParams(self.api, 100, 100, isQueued = 1)
#linear rail
dType.SetDeviceWithL(self.api, 1)
6 years ago
dType.SetJOGLParams(self.api, 200, 200, isQueued=0)
6 years ago
#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()
6 years ago
#dType.SetWAITCmd(self.api, 1, isQueued=0)
#dType.SetJOGCmd(self.api, 1, 0)
6 years ago
def rearArm(self, direction):
if direction == 1:
dType.SetJOGCmd(self.api,1,3)
elif direction == -1:
dType.SetJOGCmd(self.api,1,4)
else :
return
6 years ago
#dType.SetWAITCmd(self.api, 1, isQueued=0)
#dType.SetJOGCmd(self.api, 1, 0)
threading.Timer(0.1,self.stop).start()
6 years ago
def forearm(self, direction):
if direction == 1:
dType.SetJOGCmd(self.api,1,5)
elif direction == -1:
dType.SetJOGCmd(self.api,1,6)
else :
return
6 years ago
#dType.SetWAITCmd(self.api, 1, isQueued=0)
#dType.SetJOGCmd(self.api, 1, 0)
threading.Timer(0.1,self.stop).start()
6 years ago
def gripperRotation(self, direction):
if direction == 1:
dType.SetJOGCmd(self.api,1,7)
elif direction == -1:
dType.SetJOGCmd(self.api,1,8)
else :
return
6 years ago
#dType.SetWAITCmd(self.api, 1, isQueued=0)
#dType.SetJOGCmd(self.api, 1, 0)
threading.Timer(0.1,self.stop).start()
6 years ago
def linear(self, direction):
if direction == 1:
dType.SetJOGCmd(self.api,1,9)
elif direction == -1:
dType.SetJOGCmd(self.api,1,10)
else :
return
6 years ago
#dType.SetWAITCmd(self.api, 1, isQueued=0)
#dType.SetJOGCmd(self.api, 1, 0)
threading.Timer(0.1,self.stop).start()
6 years ago
6 years ago
def gripp(self):
dType.SetEndEffectorGripper(self.api, 1, 1, isQueued=0)
def letgo(self):
dType.SetEndEffectorGripper(self.api, 1, 0, isQueued=0)
6 years ago
def stop(self):
dType.SetJOGCmd(self.api, 1, 0)
6 years ago
def stopcmp(self):
dType.SetEndEffectorGripper(self.api, 0, 0, isQueued=0)
6 years ago
def panic(self):
dType.SetQueuedCmdForceStopExec(self.api)