test_simple_arm_manager.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 import roslib; roslib.load_manifest("hrl_pr2_lib")
00003 
00004 import rospy
00005 from hrl_pr2_lib.pr2_arms import PR2Arms
00006 from hrl_lib.transforms import rotX, rotY, rotZ
00007 import numpy as np
00008 
00009 import random
00010 
00011 import copy
00012 
00013 node_name = "test_pr2_arms" 
00014 
00015 def log(str):
00016     rospy.loginfo(node_name + ": " + str)
00017 
00018 if __name__ == "__main__":
00019     rospy.init_node(node_name, anonymous = True)
00020     log("Node initialized")
00021 
00022     arms = PR2Arms()
00023 
00024 #   while not rospy.is_shutdown():
00025 #       print arms.FK(0, arms.get_joint_angles(0))
00026 #       rospy.sleep(0.1)
00027 
00028 #   while not rospy.is_shutdown():
00029 #       print arms.get_joint_angles(0)
00030 #       rospy.sleep(0.1)
00031 
00032 
00033 #   while not rospy.is_shutdown():
00034 #       pos = (0.52, -0.3, -0.1)
00035 #       rot = rotY(np.pi / 2.)
00036 #       arms.move_arm(0, pos, rot, 4.)
00037 #       arms.wait_for_arm_completion(0)
00038 #       rospy.sleep(0.5)
00039 #       angs = arms.get_joint_angles(0)
00040 #       angs[1] -= 0.15
00041 #       if angs[1] < -.54:
00042 #           angs[1] = -.54
00043 #       angs[2] -= 0.15
00044 #       if angs[2] < -3.9:
00045 #           angs[2] = -3.9
00046 #       angs[5] += 0.15
00047 #       if angs[5] > 0.:
00048 #           angs[5] = 0.
00049 #       arms.set_joint_angles(0, angs, 4.)
00050 #       arms.wait_for_arm_completion(0)
00051 #       rospy.sleep(0.5)
00052 
00053     while not rospy.is_shutdown():
00054         angs = arms.get_joint_angles(0)
00055         pos, rot = arms.FK(0, angs)
00056         print "FK", pos, rot 
00057         ik_angs = arms.IK(0, pos, rot, angs)
00058         print "pos", pos
00059         print "IK", ik_angs
00060         print "Angles", angs
00061         if ik_angs is not None:
00062             diffs_sqrd = [(ik_angs[i] - angs[i]) ** 2 for i in range(len(angs))]
00063             print "Squared differences between IK and original angles:", diffs_sqrd
00064             print "Sum squared differences between IK and original angles:", sum(diffs_sqrd)
00065         rospy.sleep(0.1)
00066 
00067 #   print arms.create_JTG(0, [[0.2] * 7], [1.])
00068 #   arms.move_arm(0, (0.7, 0.0, 0.035), rotY(np.pi / 2.), 4.)
00069 
00070 #   while not rospy.is_shutdown():
00071 #       pos, rot = arms.FK(0, arms.get_joint_angles(0))
00072 #       pos[2,0] -= 0.05
00073 #       for i in range(3):
00074 #           rot[i,0] = 0.0
00075 #       rot[3,0] = 1.0
00076 #       print arms.IK(0, pos, rot, arms.get_joint_angles(0))
00077 
00078 #   pos, rot = arms.FK(0, arms.get_joint_angles(0))
00079 #   pos[2,0] += 0.15
00080 #   for i in range(3):
00081 #       rot[i,0] = 0.0
00082 #   rot[3,0] = 1.0
00083 #   arms.move_arm(0, pos, rot, 1.0)
00084     
00085 #   while not rospy.is_shutdown():
00086 #       pos, rot = arms.FK(0, arms.get_joint_angles(0))
00087 #       rand = random.randint(0, 1)
00088 #       if rand == 0:
00089 #           delta = -0.1
00090 #       else:
00091 #           delta = 0.1
00092 #       rand = random.randint(0, 2)
00093 #       pos[rand,0] += delta 
00094 #       for i in range(3):
00095 #           rot[i,0] = 0.0
00096 #       rot[3,0] = 1.0
00097 #       if arms.can_move_arm(0, pos, rot, 1.0):
00098 #           arms.move_arm(0, pos, rot, 1.0)
00099 #       rospy.sleep(1.1)
00100 
00101 #   pos, rot = arms.FK(0, arms.get_joint_angles(0))
00102 #   altpos = copy.copy(pos)
00103 #   pos[1] += 0.2
00104 #   altpos[2] -= 0.2
00105 #   arms.move_arm(0, pos, rot, 1.0)
00106 #   rospy.sleep(0.2)
00107 #   arms.move_arm(0, altpos, rot, 1.0)
00108 
00109 #   while not rospy.is_shutdown():
00110 #       arms.smooth_linear_arm_trajectory(0, 0.3, dir=(0.,0.,1.), dur=None)
00111 #       rospy.sleep(7.15)
00112 #       arms.smooth_linear_arm_trajectory(0, 0.3, dir=(0.,0.,-1.), dur=None)
00113 #       rospy.sleep(7.15)
00114 
00115 #   deltas = np.linspace(0.004, 0.009, 10)
00116 #   j = 0
00117 #   while not rospy.is_shutdown():
00118 #       arms.smooth_linear_arm_trajectory(0, 0.3, dir=(0.,0.,1.), dur=None, delta=deltas[j])
00119 #       print "delta =", deltas[j]
00120 #       rospy.sleep(7.15)
00121 #       arms.smooth_linear_arm_trajectory(0, 0.3, dir=(0.,0.,-1.), dur=None, delta=deltas[j])
00122 #       print "delta =", deltas[j]
00123 #       rospy.sleep(7.15)
00124 #       j += 1
00125 
00126 #   jerks = np.linspace(0.008, 0.03, 10)
00127 #   j = 0
00128 #   while not rospy.is_shutdown():
00129 #       arms.smooth_linear_arm_trajectory(0, 0.3, dir=(0.,0.,-1.), dur=None, max_jerk=jerks[j])
00130 #       print "jerk =", jerks[j]
00131 #       rospy.sleep(7.15)
00132 #       arms.smooth_linear_arm_trajectory(0, 0.3, dir=(0.,0.,1.), dur=None, max_jerk=jerks[j])
00133 #       print "jerk =", jerks[j]
00134 #       rospy.sleep(7.15)
00135 #       j += 1


hrl_pr2_lib
Author(s): haidai
autogenerated on Wed Nov 27 2013 11:40:34