master
adligeerik 6 years ago
parent 7d3723eab3
commit 1db35c90c8

@ -2,8 +2,6 @@ import time
import threading import threading
import DobotDllType as dType import DobotDllType as dType
""" """
Six actuators: Six actuators:
linear rail linear rail
@ -173,53 +171,133 @@ class Candybot:
speeds[lookup[name]] = speed speeds[lookup[name]] = speed
dType.SetJOGJointParams(self.api, speeds[0], 200, speeds[1], 200, speeds[2], 200, speeds[3], 200, isQueued = 1) dType.SetJOGJointParams(self.api, speeds[0], 200, speeds[1], 200, speeds[2], 200, speeds[3], 200, isQueued = 1)
def setJOGcmd(self, cmd):
dType.SetJOGCmd(self.api,1,cmd)
candy = Candybot()
c = Candybot() startTime = time.time()
nowTime = 0
def slide_left(): currentMotor = 0
c.linear(-1) motorcfg = [0] * 10
motorcfg[1] = {"name" : 'base' , "positive":1, "negative":2, 'speedslot':2}
motorcfg[2] = {"name" : 'reararm' ,"positive":3, "negative":4, 'speedslot':4}
motorcfg[3] = {"name" : 'base' ,"positive":5, "negative":6, 'speedslot':6}
def slide_right(): friction = 0.99
c.linear(1) movement_time = 5
max_movement_time = 10
min_speed = 1
max_speed = 50
def rotate_left(): speed = 0
c.base(-1) stopTime = 0
isRunning = False
def rotate_right():
c.base(1)
def forward(): def adjustSpeed(motor, adjustment):
c.forearm(1) global nowTime, stopTime, currentMotor, speed, motorcfg, movement_time, max_speed, max_movement_time
def back(): if currentMotor==motor:
c.forearm(-1) speed += adjustment * (abs(speed)/max_speed)
stopTime += movement_time/2 * max_movement_time/(stopTime - nowTime)
else:
currentMotor = motor
speed = adjustment
stopTime = nowTime + movement_time
if(speed>0):
candy.setJOGcmd(motorcfg[currentMotor]['positive'])
#print("JOG command {}".format(motorcfg[currentMotor]['positive']))
else:
candy.setJOGcmd(motorcfg[currentMotor]['negative'])
# print("JOG command {}".format(motorcfg[currentMotor]['negative']))
def up():
c.rearArm(1)
def down(): def stopMotorFunctions():
c.rearArm(-1) global currentMotor, speed
currentMotor = 0
speed = 0
candy.stop()
def grab(): def updateLoop():
c.gripp() global nowTime, stopTime, currentMotor, speed, friction, min_speed, motorcfg
c.stopcmp() nowTime = (time.time() - startTime)
threading.Timer(0.2, updateLoop).start()
def drop(): if currentMotor != 0:
c.letgo() if nowTime > stopTime:
c.stopcmp() stopMotorFunctions()
return
else:
speed *= friction
if abs(speed) < min_speed:
stopMotorFunctions()
return
candy.setparams(motorcfg[currentMotor]['name'], abs(speed)))
#print("JOG parameter {} to {}".format( motorcfg[currentMotor]['speedslot'], abs(speed)) )
def stop():
c.panic()
def getCurrentCmd(): def rt():
return c.getCurrentCmd() adjustSpeed(1, 5)
def updateLinearSpeed(): def lt():
pass adjustSpeed(1, -5)
def up():
adjustSpeed(2, 5)
def dn():
adjustSpeed(2, -5)
updateLoop()
#
#c = Candybot()
#
#
#def slide_left():
# c.linear(-1)
#
#def slide_right():
# c.linear(1)
#
#def rotate_left():
# c.base(-1)
#
#def rotate_right():
# c.base(1)
#
#def forward():
# c.forearm(1)
#
#def back():
# c.forearm(-1)
#
#def up():
# c.rearArm(1)
#
#def down():
# c.rearArm(-1)
#
#def grab():
# c.gripp()
# c.stopcmp()
#
#def drop():
# c.letgo()
# c.stopcmp()
#
#def stop():
# c.panic()
#
#def getCurrentCmd():
# return c.getCurrentCmd()
#
#def updateLinearSpeed():
# pass
#

Loading…
Cancel
Save