grip_workout.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 """A helper program to test gripper 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 actionlib
00010 import jaco_msgs.msg
00011 
00012 import goal_generators
00013 
00014 
00015 def gripper_client(finger_positions):
00016     """Send a gripper goal to the action server."""
00017     action_address = '/' + str(sys.argv[1]) + '_arm_driver/fingers/finger_positions'
00018     client = actionlib.SimpleActionClient(action_address,
00019                                           jaco_msgs.msg.SetFingersPositionAction)
00020     client.wait_for_server()
00021 
00022     goal = jaco_msgs.msg.SetFingersPositionGoal()
00023     goal.fingers.finger1 = float(finger_positions[0])
00024     goal.fingers.finger2 = float(finger_positions[1])
00025 
00026     # The MICO arm has only two fingers, but the same action definition is used
00027     if len(finger_positions) < 3:
00028         goal.fingers.finger3 = 0.0
00029     else:
00030         goal.fingers.finger3 = float(finger_positions[2])
00031 
00032     client.send_goal(goal)
00033     if client.wait_for_result(rospy.Duration(5.0)):
00034         return client.get_result()
00035     else:
00036         client.cancel_all_goals()
00037         print('        the gripper action timed-out')
00038         return None
00039 
00040 
00041 if __name__ == '__main__':
00042     if (len(sys.argv) not in [4, 5] or
00043             'help' in str(sys.argv) or
00044             str(sys.argv[1]) not in ['jaco', 'mico']):
00045 
00046         print('Usage:')
00047         print('    gripper_workout.py jaco random num   - randomly generate num poses')
00048         print('    gripper_workout.py jaco f1 f2 f3     - use that specific pose')
00049         print('    gripper_workout.py mico f1 f2        - use that specific pose')
00050         exit()
00051 
00052     try:
00053         rospy.init_node(str(sys.argv[1]) + '_gripper_workout')
00054 
00055         if str(sys.argv[2]) == 'random' and len(sys.argv) == 4:
00056             print('Using {} randomly generated finger positions'.format(int(sys.argv[3])))
00057             if str(sys.argv[1]) == 'jaco':
00058                 positions = goal_generators.random_jaco_finger_positions(int(sys.argv[3]))
00059             else:
00060                 positions = goal_generators.random_mico_finger_positions(int(sys.argv[3]))
00061         elif str(sys.argv[1]) == 'jaco' and len(sys.argv) == 5:
00062             print('Using the specified JACO finger positions:')
00063             raw_positions = [float(n) for n in sys.argv[2:]]
00064             positions = [raw_positions]
00065         elif str(sys.argv[1]) == 'mico' and len(sys.argv) == 4:
00066             print('Using the specified MICO finger positions:')
00067             raw_positions = [float(n) for n in sys.argv[2:]]
00068             positions = [raw_positions]
00069         else:
00070             print('Could not parse arguments, use gripper_workout.py help to see examples')
00071             positions = []  # Get rid of static analysis warning that doesn't see the exit()
00072             exit()
00073 
00074         for position in positions:
00075             print('    position: {}'.format(position))
00076             result = gripper_client(position)
00077 
00078         print('Done!')
00079 
00080     except rospy.ROSInterruptException:
00081         print "program interrupted before completion"


jaco_demo
Author(s): Braden Stenning
autogenerated on Mon Mar 2 2015 16:21:11