adapt sample code to current test joystick

This commit is contained in:
Olivier R-D 2015-04-15 14:56:41 +02:00
parent 30cc708912
commit f769446d2c

View File

@ -1,5 +1,6 @@
"""
example program to control a universal robot with a joystick
All joysticks are differens, so you will need to modify the script to work with your joystick
"""
import time
@ -62,9 +63,13 @@ class Service(object):
#get joystick state
for i in range(0, self.joystick.get_numaxes()):
if abs(self.joystick.get_axis(i)) > 0.2:
tmp = "self.cmd.axis" + str(i) + " = " + str(self.joystick.get_axis(i))
print(tmp)
val = self.joystick.get_axis(i)
if i in (2, 5) and val != 0:
val += 1
if abs(val) < 0.2:
val = 0
tmp = "self.cmd.axis" + str(i) + " = " + str(val)
#print(tmp)
exec(tmp)
#get button state
@ -121,13 +126,11 @@ class Service(object):
if __name__ == "__main__":
#create robot object
#robot = urx.Robot('192.168.0.90')
robot = urx.Robot('localhost')
robot = urx.Robot('192.168.0.90')
#robot = urx.Robot('localhost')
#set a base transformation for robot (optional)
robot.set_tcp((0, 0, 0, 0, 0, 0))
trx = m3d.Transform()
trx.orient.rotate_zb(-pi/4)
robot.set_csys("mycsys", trx)
robot.csys.orient.rotate_zb(-pi/4)
#start joystick service with given max speed and acceleration
service = Service(robot, linear_velocity=0.1, rotational_velocity=0.1, acceleration=0.1)