sr_left_arm_examples.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright 2019 Shadow Robot Company Ltd.
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the Free
6 # Software Foundation version 2 of the License.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 # more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15 
16 # This example demonstrates some of the functions of the arm commander using poses.
17 # The arm is moved through a sequence of goals generated via different pose functions in the commander.
18 # A pose can be a PoseStamped message,
19 # or a list of 6 floats: [x, y, z, rot_x, rot_y, rot_z],
20 # or a list of 7 floats [x, y, z, qx, qy, qz, qw]
21 # PLEASE NOTE: move_to_joint_value_target_unsafe is used in this script, so collision checks
22 # between the hand and arm are not made!
23 
24 # For more information, please see:
25 # https://dexterous-hand.readthedocs.io/en/latest/user_guide/2_software_description.html#robot-commander
26 
27 # roslaunch commands used with this script to launch the robot:
28 # real robot with a NUC (or a separate computer with an RT kernel):
29 # roslaunch sr_left_ur10arm_hand.launch external_control_loop:=true sim:=false scene:=true start_home:=true
30 # simulated robot:
31 # roslaunch sr_left_ur10arm_hand.launch sim:=true scene:=true start_home:=true
32 
33 # It is recommended to run this script in simulation first.
34 
35 import rospy
36 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
37 from sr_robot_commander.sr_robot_commander import SrRobotCommander
38 from sr_robot_commander.sr_hand_commander import SrHandCommander
39 from sr_robot_commander.sr_arm_commander import SrArmCommander
40 
41 rospy.init_node("left_hand_arm_ef_pos", anonymous=True)
42 
43 # The constructors for the SrArmCommander, SrHandCommander and SrRobotCommander
44 # take a name parameter that should match the group name of the robot to be used.
45 # How to command the hand or arm separately
46 hand_commander = SrHandCommander(name="left_hand")
47 arm_commander = SrArmCommander(name="left_arm")
48 # How to command the arm and hand together
49 robot_commander = SrRobotCommander(name="left_arm_and_hand")
50 arm_commander.set_max_velocity_scaling_factor(0.1)
51 rospy.sleep(2.0)
52 
53 arm_home_joints_goal = {'la_shoulder_pan_joint': 1.47, 'la_elbow_joint': -1.695,
54  'la_shoulder_lift_joint': -1.22, 'la_wrist_1_joint': -01.75,
55  'la_wrist_2_joint': 1.57, 'la_wrist_3_joint': -1.830}
56 
57 example_pose_1 = [0.6, 0.3, 1.5, -0.7, 0.04, -0.67]
58 
59 example_pose_2 = [0.6, 0.3, 1.46, -0.7, 0.04, 0.69, 0.08]
60 
61 example_pose_3 = [0.69, 0.64, 1.4, -0.71, 0.04, 0.69, 0.08]
62 
63 # Start arm at home
64 rospy.loginfo("Moving arm to joint states\n" + str(arm_home_joints_goal) + "\n")
65 robot_commander.move_to_joint_value_target_unsafe(arm_home_joints_goal, 6.0, True)
66 
67 # Move hand to open
68 # Moving to a stored named target, stored targets can be viewed in MoveIt in the planning tab
69 rospy.loginfo("Moving hand to joint state: open")
70 hand_commander.move_to_named_target("open")
71 rospy.sleep(3.0)
72 
73 # Move hand to pack
74 # Moving to a stored named target, stored targets can be viewed in MoveIt in the planning tab
75 rospy.loginfo("Moving hand to joint state: pack")
76 hand_commander.move_to_named_target("pack")
77 
78 # The arm commander generates a plan to a new pose before the pose is executed.
79 raw_input("Press Enter to continue...")
80 rospy.loginfo("Planning the move to the first pose:\n" + str(example_pose_1) + "\n")
81 arm_commander.plan_to_pose_target(example_pose_1)
82 rospy.loginfo("Finished planning, moving the arm now.")
83 # Can only execute if a plan has been generated.
84 arm_commander.execute()
85 rospy.sleep(2.0)
86 
87 raw_input("Press Enter to continue...")
88 rospy.loginfo("Planning the move to the second pose:\n" + str(example_pose_2) + "\n")
89 arm_commander.plan_to_pose_target(example_pose_2)
90 rospy.loginfo("Finished planning, moving the arm now.")
91 arm_commander.execute()
92 
93 # Here a pose is provided and the arm commander moves the arm to it
94 raw_input("Press Enter to continue...")
95 rospy.loginfo("Moving arm to pose:\n" + str(example_pose_1) + "\n")
96 arm_commander.move_to_pose_target(example_pose_1, wait=True)
97 rospy.sleep(2.0)
98 
99 # Here a pose is provided and the arm commander moves the arm to it
100 raw_input("Press Enter to continue...")
101 rospy.loginfo("Moving arm to pose:\n" + str(example_pose_3) + "\n")
102 arm_commander.move_to_pose_target(example_pose_3, wait=True)
103 rospy.sleep(2.0)
104 
105 # Finish arm at home
106 raw_input("Press Enter to continue...")
107 rospy.loginfo("Moving arm to joint states\n" + str(arm_home_joints_goal) + "\n")
108 robot_commander.move_to_joint_value_target_unsafe(arm_home_joints_goal, 6.0, True)
109 
110 # Move hand to open
111 # Moving to a stored named target, stored targets can be viewed in MoveIt in the planning tab
112 rospy.loginfo("Moving hand to joint state: open")
113 hand_commander.move_to_named_target("open")
114 rospy.sleep(2.0)


sr_example
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:10