20 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
21 from sr_robot_commander.sr_arm_commander
import SrArmCommander
23 rospy.init_node(
"basic_right_arm_example", anonymous=
True)
25 arm_commander = SrArmCommander(set_ground=
False)
27 rospy.sleep(rospy.Duration(2))
30 pose_1 = [0.5, -0.3, 1.2, 0, 1.57, 0]
31 print(
"Planning the move to the first pose:\n" + str(pose_1) +
"\n")
32 arm_commander.plan_to_pose_target(pose_1)
33 print(
"Finished planning, moving the arm now.")
35 arm_commander.execute()
39 pose_2 = [0.5, 0.3, 1.2, 0, 1.57, 0]
40 print(
"Planning the move to the second pose:\n" + str(pose_2) +
"\n")
41 arm_commander.plan_to_pose_target(pose_2)
42 print(
"Finished planning, moving the arm now.")
43 arm_commander.execute()
46 pose_1 = [0.5, -0.3, 1.2, 0, 1.57, 0]
47 print(
"Moving arm to pose:\n" + str(pose_1) +
"\n")
48 arm_commander.move_to_pose_target(pose_1, wait=
True)
52 pose_2 = [0.5, 0.3, 1.2, 0, 1.57, 0]
53 print(
"Moving arm to pose:\n" + str(pose_2) +
"\n")
54 arm_commander.move_to_pose_target(pose_2, wait=
True)
57 position_1 = [0.5, -0.3, 1.2]
58 print(
"Moving arm to position:\n" + str(position_1) +
"\n")
59 arm_commander.move_to_position_target(position_1)
61 rospy.sleep(rospy.Duration(5))
64 position_2 = [0.5, 0.3, 1.2]
65 print(
"Planning the move to the second position:\n" + str(position_2) +
"\n")
66 arm_commander.plan_to_position_target(position_2)
67 print(
"Finished planning, moving the arm now.")
68 arm_commander.execute()
70 rospy.sleep(rospy.Duration(5))
73 print(
"Arm joints position:\n" +
74 str(arm_commander.get_joints_position()) +
"\n")
76 joints_goal_1 = {
'ra_shoulder_pan_joint': 0.43,
'ra_elbow_joint': 2.12,
'ra_wrist_1_joint': -1.71,
77 'ra_wrist_2_joint': 1.48,
'ra_shoulder_lift_joint': -2.58,
'ra_wrist_3_joint': 1.62,
78 'rh_WRJ1': 0.0,
'rh_WRJ2': 0.0}
80 print(
"Moving arm to joints position:\n" + str(joints_goal_1) +
"\n")
82 arm_commander.move_to_joint_value_target(joints_goal_1)
83 rospy.sleep(rospy.Duration(5))
85 joints_goal_2 = {
'ra_shoulder_pan_joint': 0.42,
'ra_elbow_joint': 1.97,
'ra_wrist_1_joint': -0.89,
86 'ra_wrist_2_joint': -0.92,
'ra_shoulder_lift_joint': -1.93,
'ra_wrist_3_joint': 0.71,
87 'rh_WRJ1': 0.0,
'rh_WRJ2': 0.0}
89 print(
"Moving arm to joints position:\n" + str(joints_goal_2) +
"\n")
91 arm_commander.move_to_joint_value_target(joints_goal_2)
92 rospy.sleep(rospy.Duration(5))
94 print(
"Arm joints position:\n" +
95 str(arm_commander.get_joints_position()) +
"\n")
97 joints_goal_3 = {
'ra_shoulder_pan_joint': 1.61,
'ra_elbow_joint': 1.15,
'ra_wrist_1_joint': -0.24,
98 'ra_wrist_2_joint': 0.49,
'ra_shoulder_lift_joint': -1.58,
'ra_wrist_3_joint': 2.11,
99 'rh_WRJ1': 0.0,
'rh_WRJ2': 0.0}
103 print(
"Running joints trajectory")
105 joint_trajectory = JointTrajectory()
106 joint_trajectory.header.stamp = rospy.Time.now()
107 joint_trajectory.joint_names = list(joints_goal_1.keys())
108 joint_trajectory.points = []
109 time_from_start = rospy.Duration(5)
111 for joints_goal
in [joints_goal_1, joints_goal_2, joints_goal_3]:
112 trajectory_point = JointTrajectoryPoint()
113 trajectory_point.time_from_start = time_from_start
114 time_from_start = time_from_start + rospy.Duration(5)
116 trajectory_point.positions = []
117 trajectory_point.velocities = []
118 trajectory_point.accelerations = []
119 trajectory_point.effort = []
120 for key
in joint_trajectory.joint_names:
121 trajectory_point.positions.append(joints_goal[key])
122 trajectory_point.velocities.append(0.0)
123 trajectory_point.accelerations.append(0.0)
124 trajectory_point.effort.append(0.0)
126 joint_trajectory.points.append(trajectory_point)
128 arm_commander.run_joint_trajectory(joint_trajectory)
130 rospy.sleep(rospy.Duration(15))
133 named_target =
"gamma" 134 print(
"Moving arm to named target " + named_target)
135 arm_commander.move_to_named_target(named_target)
137 rospy.sleep(rospy.Duration(3))
140 print(
"Arm joints position:\n" +
141 str(arm_commander.get_joints_position()) +
"\n")
142 print(
"Arm joints velocities:\n" +
143 str(arm_commander.get_joints_velocity()) +
"\n")