Go to the documentation of this file.00001
00002
00003
00004
00005 import roslib
00006 roslib.load_manifest('pr2_laban_gazebo_demo')
00007 import rospy
00008 from pr2_laban_gazebo_demo.srv import ExecuteCartesianIKTrajectory
00009 from geometry_msgs.msg import Pose
00010 import time
00011 import sys
00012 import pdb
00013 import tf
00014 import std_msgs.msg
00015
00016
00017
00018 def call_execute_cartesian_ik_trajectory(frame, positions, orientations):
00019 rospy.wait_for_service("execute_cartesian_ik_trajectory")
00020
00021
00022 header = std_msgs.msg.Header()
00023 header.frame_id = frame
00024 header.stamp = rospy.get_rostime()
00025
00026
00027 poses = []
00028 for (position, orientation) in zip(positions, orientations):
00029 pose = Pose()
00030 pose.position.x = position[0]
00031 pose.position.y = position[1]
00032 pose.position.z = position[2]
00033 pose.orientation.x = orientation[0]
00034 pose.orientation.y = orientation[1]
00035 pose.orientation.z = orientation[2]
00036 pose.orientation.w = orientation[3]
00037 poses.append(pose)
00038
00039
00040 print "calling execute_cartesian_ik_trajectory"
00041 try:
00042 s = rospy.ServiceProxy("execute_cartesian_ik_trajectory", \
00043 ExecuteCartesianIKTrajectory)
00044 resp = s(header, poses)
00045 except rospy.ServiceException, e:
00046 print "error when calling execute_cartesian_ik_trajectory: %s"%e
00047 return 0
00048 return resp.success
00049
00050
00051 def pplist(list):
00052 return ' '.join(['%2.3f'%x for x in list])
00053
00054
00055 if __name__ == "__main__":
00056 rospy.init_node("test_cartesian_ik_trajectory_executer")
00057 tf_listener = tf.TransformListener()
00058 time.sleep(.5)
00059
00060 joint_names = ["r_shoulder_pan_joint",
00061 "r_shoulder_lift_joint",
00062 "r_upper_arm_roll_joint",
00063 "r_elbow_flex_joint",
00064 "r_forearm_roll_joint",
00065 "r_wrist_flex_joint",
00066 "r_wrist_roll_joint"]
00067
00068 positions = [[.76, -.19, .83], [0.59, -0.36, 0.93]]
00069 orientations = [[.02, -.09, 0.0, 1.0], [0.65, -0.21, .38, .62]]
00070
00071 success = call_execute_cartesian_ik_trajectory("base_link", \
00072 positions, orientations)
00073
00074
00075 (trans, rot) = tf_listener.lookupTransform('base_link', 'r_wrist_roll_link', rospy.Time(0))
00076 print "end Cartesian pose: trans", pplist(trans), "rot", pplist(rot)
00077
00078 if success:
00079 print "trajectory succeeded!"
00080 else:
00081 print "trajectory failed."
00082