Go to the documentation of this file.00001
00002 """A helper program to test cartesian goals for the JACO and MICO arms."""
00003
00004 import roslib; roslib.load_manifest('jaco_demo')
00005 import rospy
00006
00007 import sys
00008
00009 import math
00010
00011 import actionlib
00012 import jaco_msgs.msg
00013
00014 import goal_generators
00015
00016
00017 def joint_angle_client(angle_set):
00018 """Send a joint angle goal to the action server."""
00019 action_address = '/' + str(sys.argv[1]) + '_arm_driver/joint_angles/arm_joint_angles'
00020 client = actionlib.SimpleActionClient(action_address,
00021 jaco_msgs.msg.ArmJointAnglesAction)
00022 client.wait_for_server()
00023
00024 goal = jaco_msgs.msg.ArmJointAnglesGoal()
00025
00026 goal.angles.joint1 = angle_set[0]
00027 goal.angles.joint2 = angle_set[1]
00028 goal.angles.joint3 = angle_set[2]
00029 goal.angles.joint4 = angle_set[3]
00030 goal.angles.joint5 = angle_set[4]
00031 goal.angles.joint6 = angle_set[5]
00032
00033 print('goal: {}'.format(goal))
00034
00035 client.send_goal(goal)
00036 if client.wait_for_result(rospy.Duration(20.0)):
00037 return client.get_result()
00038 else:
00039 print(' the joint angle action timed-out')
00040 client.cancel_all_goals()
00041 return None
00042
00043
00044 if __name__ == '__main__':
00045 if len(sys.argv) not in [3, 4, 8] or 'help' in str(sys.argv):
00046 print('Usage:')
00047 print(' joint_angle_workout.py node_name random num - randomly generate num joint angle sets')
00048 print(' joint_angle_workout.py node_name file_path - use poses from file')
00049 print(' joint_angle_workout.py node_name j1 j2 j3 j4 j5 j6 - use these specific angle')
00050 exit()
00051
00052 try:
00053 rospy.init_node(str(sys.argv[1]) + '_joint_angle_workout')
00054
00055 if str(sys.argv[2]) == 'random' and len(sys.argv) == 4:
00056 print('Using {} randomly generated joint angle sets'.format(int(sys.argv[3])))
00057 angles = goal_generators.random_joint_angles_generator(int(sys.argv[3]))
00058 elif len(sys.argv) == 3:
00059 print('Using joint angles from file: {}'.format(sys.argv[2]))
00060 angles = goal_generators.joint_angles_from_file(str(sys.argv[2]))
00061 else:
00062 print('Using the specified joint angles:')
00063 raw_angles = [float(n) for n in sys.argv[2:]]
00064 angles = [raw_angles]
00065
00066 for angle_set in angles:
00067 print(' angles: {}'.format(angle_set))
00068 result = joint_angle_client(angle_set)
00069
00070 print('Done!')
00071
00072 except rospy.ROSInterruptException:
00073 print "program interrupted before completion"