19 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
20 from sr_robot_commander.sr_hand_commander
import SrHandCommander
21 from sr_utilities.hand_finder
import HandFinder
22 from numpy
import sin, cos, pi, arange
24 rospy.init_node(
"joint_sine_example", anonymous=
True)
27 hand_finder = HandFinder()
28 hand_parameters = hand_finder.get_hand_parameters()
29 prefix = hand_parameters.mapping.values()
30 hand_serial = hand_parameters.mapping.keys()[0]
32 hand_commander = SrHandCommander(hand_parameters=hand_parameters, hand_serial=hand_serial)
42 joint_names = [prefix[0] +
'_FFJ3', prefix[0] +
'_RFJ3']
48 rospy.sleep(rospy.Duration(2))
50 hand_joints_goal = {joint_names[0]: 0.0, joint_names[1]: 0.0}
52 rospy.loginfo(
"Running joints trajectory")
55 joint_trajectory = JointTrajectory()
56 joint_trajectory.header.stamp = rospy.Time.now()
57 joint_trajectory.joint_names = list(hand_joints_goal.keys())
58 joint_trajectory.points = []
61 for t
in arange(0.002, ts, 0.02):
62 trajectory_point = JointTrajectoryPoint()
63 trajectory_point.time_from_start = rospy.Duration.from_sec(float(t))
64 trajectory_point.positions = []
65 trajectory_point.velocities = []
66 trajectory_point.accelerations = []
67 trajectory_point.effort = []
69 for key
in joint_trajectory.joint_names:
70 if key
in joint_names[0]:
71 joint_position = sin(w * t) * (max_pos_J3 - min_pos_J3) / 2 + (max_pos_J3 - min_pos_J3) / 2 + min_pos_J3
72 trajectory_point.positions.append(joint_position)
73 elif key
in joint_names[1]:
74 joint_position = cos(w * t) * (max_pos_J3 - min_pos_J3) / 2 + (max_pos_J3 - min_pos_J3) / 2 + min_pos_J3
75 trajectory_point.positions.append(joint_position)
77 trajectory_point.positions.append(hand_joints_goal[key])
79 trajectory_point.velocities.append(0.0)
80 trajectory_point.accelerations.append(0.0)
81 trajectory_point.effort.append(0.0)
83 joint_trajectory.points.append(trajectory_point)
86 hand_commander.run_joint_trajectory_unsafe(joint_trajectory)
88 rospy.sleep(rospy.Duration(15))