rewrite wait_for_move, split robot file, check test_all.py

This commit is contained in:
Olivier R-D
2015-06-12 10:34:42 +02:00
parent 06644d96c8
commit 5e4c8a0696
8 changed files with 498 additions and 495 deletions

View File

@ -1,11 +1,15 @@
import urx
from IPython import embed
import logging
if __name__ == "__main__":
try:
robot = urx.Robot("192.168.1.6")
logging.basicConfig(level=logging.INFO)
#robot = urx.Robot("192.168.1.6")
robot = urx.Robot("192.168.1.100")
#robot = urx.Robot("localhost")
r = robot
print("Robot object is available as robot or r")
embed()
finally:
robot.shutdown()
robot.close()

View File

@ -69,7 +69,8 @@ class Service(object):
if abs(val) < 0.2:
val = 0
tmp = "self.cmd.axis" + str(i) + " = " + str(val)
#print(tmp)
if val != 0:
print(tmp)
exec(tmp)
#get button state
@ -92,20 +93,20 @@ class Service(object):
speeds = [0, 0, 0, 0, 0, 0]
#get linear speed from joystick
speeds[0] = self.cmd.axis0 * self.linear_velocity
speeds[0] = -1 * self.cmd.axis0 * self.linear_velocity
speeds[1] = self.cmd.axis1 * self.linear_velocity
if self.cmd.btn4 and not self.cmd.btn6:
speeds[2] = self.linear_velocity
if self.cmd.btn6 and not self.cmd.btn4:
if self.cmd.btn4 and not self.cmd.axis2:
speeds[2] = -self.linear_velocity
if self.cmd.axis2 and not self.cmd.btn4:
speeds[2] = self.cmd.axis2 * self.linear_velocity
#get rotational speed from joystick
speeds[4] = -1 * self.cmd.axis2 * self.rotational_velocity
speeds[3] = self.cmd.axis3 * self.rotational_velocity
if self.cmd.btn1 and not self.cmd.btn2:
speeds[4] = -1 * self.cmd.axis3 * self.rotational_velocity
speeds[3] = -1 * self.cmd.axis4 * self.rotational_velocity
if self.cmd.btn5 and not self.cmd.axis5:
speeds[5] = self.rotational_velocity
if self.cmd.btn2 and not self.cmd.btn1:
speeds[5] = -self.rotational_velocity
if self.cmd.axis5 and not self.cmd.btn5:
speeds[5] = self.cmd.axis5 * -self.rotational_velocity
#for some reasons everything is inversed
speeds = [-i for i in speeds]
@ -117,7 +118,6 @@ class Service(object):
else:
self.robot.speedl(speeds, acc=self.acceleration, min_time=2)
time.sleep(0.12)#URX secondday port accepts command at 10Hz, no need to go faster
def close(self):
if self.joystick:
@ -125,13 +125,10 @@ class Service(object):
if __name__ == "__main__":
#create robot object
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))
robot.csys.orient.rotate_zb(-pi/4)
robot = urx.Robot("192.168.1.100")
r = robot
#start joystick service with given max speed and acceleration
service = Service(robot, linear_velocity=0.1, rotational_velocity=0.1, acceleration=0.1)
service.init_joystick()

View File

@ -4,8 +4,8 @@ import urx
import logging
if __name__ == "__main__":
#rob = urx.Robot("192.168.1.6")
rob = urx.Robot("localhost")
rob = urx.Robot("192.168.1.100")
#rob = urx.Robot("localhost")
rob.set_tcp((0,0,0,0,0,0))
rob.set_payload(0.5, (0,0,0))
try:

View File

@ -5,8 +5,8 @@ import logging
if __name__ == "__main__":
logging.basicConfig(level=logging.WARN)
#rob = urx.Robot("192.168.1.6")
rob = urx.Robot("localhost")
rob = urx.Robot("192.168.1.100")
#rob = urx.Robot("localhost")
rob.set_tcp((0,0,0,0,0,0))
rob.set_payload(0.5, (0,0,0))
try:

View File

@ -14,17 +14,18 @@ if sys.version_info[0] < 3: # support python v2
def wait():
if do_wait:
print("Click enter to continue")
input()
if __name__ == "__main__":
logging.basicConfig(level=logging.WARN)
logging.basicConfig(level=logging.INFO)
do_wait = True
if len(sys.argv) > 1:
do_wait = False
#rob = urx.Robot("192.168.1.6")
rob = urx.Robot("localhost")
rob = urx.Robot("192.168.1.100")
#rob = urx.Robot("localhost")
rob.set_tcp((0, 0, 0, 0, 0, 0))
rob.set_payload(0.5, (0, 0, 0))
try:
@ -49,8 +50,8 @@ if __name__ == "__main__":
wait()
pose[2] += l
rob.movel(pose, acc=a, vel=v, wait=False)
print("Waiting for end move")
rob.wait_for_move(0, pose)
print("Waiting 2s for end move")
time.sleep(2)
print("Moving through several points with a radius")
wait()
@ -77,22 +78,14 @@ if __name__ == "__main__":
print("stop robot")
rob.stopj()
print("Test movep, it will fail on older controllers")
wait()
init = rob.get_pose()
pose = init.copy()
for _ in range(3):
pose.pos[0] += l
rob.movep(pose, acc=a, vel=v, radius=r)
rob.movep(init, acc=a, vel=v, radius=r) # back to start
print("Test movec")
wait()
via = init.copy()
pose = rob.get_pose()
via = pose.copy()
via.pos[0] += l
to = via.copy()
to.pos[1] += l
rob.movec(via, to, acc=a, vel=v, radius=r)
rob.movec(via, to, acc=a, vel=v)
print("Sending robot back to original position")
rob.movej(initj, acc=0.8, vel=0.2)