sr_right_hand_partial_traj_grasp.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
00005 
00006 from sr_robot_commander.sr_hand_commander import SrHandCommander
00007 
00008 rospy.init_node("set_traj_goals", anonymous=True)
00009 rospy.sleep(1)  # Do not start with zero
00010 
00011 
00012 def construct_trajectory_point(posture, duration):
00013     trajectory_point = JointTrajectoryPoint()
00014     trajectory_point.time_from_start = rospy.Duration.from_sec(float(duration))
00015     for key in joint_trajectory.joint_names:
00016         trajectory_point.positions.append(posture[key])
00017     return trajectory_point
00018 
00019 
00020 hand_commander = SrHandCommander()
00021 
00022 open_hand = {'rh_FFJ1': 0.0, 'rh_FFJ2': 0.0, 'rh_FFJ3': 0.0, 'rh_FFJ4': 0.0,
00023              'rh_MFJ1': 0.0, 'rh_MFJ2': 0.0, 'rh_MFJ3': 0.0, 'rh_MFJ4': 0.0,
00024              'rh_RFJ1': 0.0, 'rh_RFJ2': 0.0, 'rh_RFJ3': 0.0, 'rh_RFJ4': 0.0,
00025              'rh_LFJ1': 0.0, 'rh_LFJ2': 0.0, 'rh_LFJ3': 0.0, 'rh_LFJ4': 0.0,
00026              'rh_LFJ5': 0.0, 'rh_THJ1': 0.0, 'rh_THJ2': 0.0, 'rh_THJ3': 0.0,
00027              'rh_THJ4': 0.0, 'rh_THJ5': 0.0, 'rh_WRJ1': 0.0, 'rh_WRJ2': 0.0}
00028 
00029 keys = ['rh_FFJ1', 'rh_FFJ2', 'rh_FFJ3', 'rh_FFJ4', 'rh_LFJ1', 'rh_LFJ2',
00030         'rh_LFJ3', 'rh_LFJ4', 'rh_LFJ5', 'rh_MFJ1', 'rh_MFJ2', 'rh_MFJ3',
00031         'rh_MFJ4', 'rh_RFJ1', 'rh_RFJ2', 'rh_RFJ3', 'rh_RFJ4', 'rh_THJ1',
00032         'rh_THJ2', 'rh_THJ3', 'rh_THJ4', 'rh_THJ5', 'rh_WRJ1', 'rh_WRJ2']
00033 position = [1.0707232604620422, 0.26175844295000505, 0.883936396387667,
00034             -0.3434683241082386, 0.8476100321368696, 0.603282427869523,
00035             0.21068692113415377, -0.2259571234036457, 0.15140092663442495,
00036             1.0574641003686231, 0.15788941690905922, 1.0361759477073011,
00037             0.05490553542027321, 1.040703232148128, 0.3401612929181024,
00038             0.6804364962780189, -0.23700380992456882, 0.3491125761045675,
00039             0.6901807769501129, 0.17965518799781588, 1.2043661627831659,
00040             -0.10694821918223951, -0.07495731995088306, -0.21656822158752753]
00041 grasp_pose = dict(zip(keys, position))
00042 
00043 grasp_partial_1 = {'rh_FFJ3': 0.50}
00044 
00045 start_time = rospy.Time.now()
00046 
00047 # Move hand using move_to_joint_value_target_unsafe
00048 hand_commander.move_to_joint_value_target_unsafe(open_hand, 1.0, True)
00049 
00050 rospy.sleep(2)
00051 hand_commander.move_to_joint_value_target_unsafe(grasp_pose, 1.0, False)
00052 
00053 # Move hand using run_joint_trajectory_unsafe
00054 trajectory_start_time = 2.0
00055 joint_trajectory = JointTrajectory()
00056 joint_trajectory.header.stamp = start_time + rospy.Duration.from_sec(
00057     float(trajectory_start_time))
00058 joint_trajectory.joint_names = list(grasp_partial_1.keys())
00059 joint_trajectory.points = []
00060 trajectory_point = construct_trajectory_point(grasp_partial_1, 1.0)
00061 joint_trajectory.points.append(trajectory_point)
00062 hand_commander.run_joint_trajectory_unsafe(joint_trajectory, True)


sr_example
Author(s): Ugo Cupcic
autogenerated on Fri Aug 21 2015 12:25:43