21 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
23 from sr_robot_commander.sr_hand_commander
import SrHandCommander
24 from sr_utilities.hand_finder
import HandFinder
26 rospy.init_node(
"partial_traj_example", anonymous=
True)
31 trajectory_point = JointTrajectoryPoint()
32 trajectory_point.time_from_start = rospy.Duration.from_sec(float(duration))
33 for key
in joint_trajectory.joint_names:
34 trajectory_point.positions.append(posture[key])
35 return trajectory_point
37 hand_finder = HandFinder()
39 hand_parameters = hand_finder.get_hand_parameters()
40 hand_serial = hand_parameters.mapping.keys()[0]
42 hand_commander = SrHandCommander(hand_parameters=hand_parameters,
43 hand_serial=hand_serial)
45 hand_mapping = hand_parameters.mapping[hand_serial]
48 joints = hand_finder.get_hand_joints()[hand_mapping]
50 open_hand = {
'rh_FFJ1': 0.0,
'rh_FFJ2': 0.0,
'rh_FFJ3': 0.0,
'rh_FFJ4': 0.0,
51 'rh_MFJ1': 0.0,
'rh_MFJ2': 0.0,
'rh_MFJ3': 0.0,
'rh_MFJ4': 0.0,
52 'rh_RFJ1': 0.0,
'rh_RFJ2': 0.0,
'rh_RFJ3': 0.0,
'rh_RFJ4': 0.0,
53 'rh_LFJ1': 0.0,
'rh_LFJ2': 0.0,
'rh_LFJ3': 0.0,
'rh_LFJ4': 0.0,
54 'rh_LFJ5': 0.0,
'rh_THJ1': 0.0,
'rh_THJ2': 0.0,
'rh_THJ3': 0.0,
55 'rh_THJ4': 0.0,
'rh_THJ5': 0.0}
57 keys = [
'rh_FFJ1',
'rh_FFJ2',
'rh_FFJ3',
'rh_FFJ4',
'rh_LFJ1',
'rh_LFJ2',
58 'rh_LFJ3',
'rh_LFJ4',
'rh_LFJ5',
'rh_MFJ1',
'rh_MFJ2',
'rh_MFJ3',
59 'rh_MFJ4',
'rh_RFJ1',
'rh_RFJ2',
'rh_RFJ3',
'rh_RFJ4',
'rh_THJ1',
60 'rh_THJ2',
'rh_THJ3',
'rh_THJ4',
'rh_THJ5']
62 position = [1.07, 0.26, 0.88, -0.34, 0.85, 0.60,
63 0.21, -0.23, 0.15, 1.06, 0.16, 1.04,
64 0.05, 1.04, 0.34, 0.68, -0.24, 0.35,
65 0.69, 0.18, 1.20, -0.11]
67 grasp_pose = dict(zip(keys, position))
70 open_hand_current = dict([(i, open_hand[i])
for i
in joints
if i
in open_hand])
71 grasp_pose_current = dict([(i, grasp_pose[i])
for i
in joints
if i
in grasp_pose])
74 grasp_partial_1 = {
'rh_FFJ3': 0.50}
76 start_time = rospy.Time.now()
79 hand_commander.move_to_joint_value_target_unsafe(open_hand_current, 1.0,
True)
84 hand_commander.move_to_joint_value_target_unsafe(grasp_pose_current, 1.0,
False)
86 trajectory_start_time = 2.0
87 joint_trajectory = JointTrajectory()
90 joint_trajectory.header.stamp = start_time + rospy.Duration.from_sec(float(trajectory_start_time))
91 joint_trajectory.joint_names = list(grasp_partial_1.keys())
92 joint_trajectory.points = []
94 joint_trajectory.points.append(trajectory_point)
96 hand_commander.run_joint_trajectory_unsafe(joint_trajectory,
True)
def construct_trajectory_point(posture, duration)