sr_right_hand_arm_joint_pos.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright 2020 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 how to move the right hand and arm through a sequence of joint goals.
17 # At the start and end of the sequence, both the hand and arm will spend 20s in teach mode,
18 # This allows the user to manually move the hand and arm. New goals can be easily generated
19 # using the script 'sr_right_print_joints_pos.py
20 # PLEASE NOTE: move_to_joint_value_target_unsafe is used in this script, so collision checks
21 # between the hand and arm are not made!
22 
23 # For more information, please see:
24 # https://dexterous-hand.readthedocs.io/en/latest/user_guide/2_software_description.html#robot-commander
25 
26 # roslaunch commands used with this script to launch the robot:
27 # real robot with a NUC (or a separate computer with an RT kernel):
28 # roslaunch sr_robot_launch sr_right_ur10arm_hand.launch
29 # external_control_loop:=true sim:=false scene:=true
30 # simulated robot:
31 # roslaunch sr_robot_launch sr_right_ur10arm_hand.launch sim:=true scene:=true
32 
33 # It is recommended to run this script in simulation first.
34 
35 import rospy
36 import sys
37 from sr_robot_commander.sr_arm_commander import SrArmCommander
38 from sr_robot_commander.sr_hand_commander import SrHandCommander
39 from sr_robot_commander.sr_robot_commander import SrRobotCommander
40 
41 rospy.init_node("right_hand_arm_joint_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="right_hand")
47 arm_commander = SrArmCommander(name="right_arm")
48 # How to command the arm and hand together
49 robot_commander = SrRobotCommander(name="right_arm_and_hand")
50 arm_commander.set_max_velocity_scaling_factor(0.1)
51 
52 # Specify goals for hand and arm if not a saved state
53 arm_home_joints_goal = {'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.00,
54  'ra_shoulder_lift_joint': -1.25, 'ra_wrist_1_joint': -0.733,
55  'ra_wrist_2_joint': 1.5708, 'ra_wrist_3_joint': 0.00}
56 
57 arm_hand_home_joints_goal = {'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.00,
58  'ra_shoulder_lift_joint': -1.25, 'ra_wrist_1_joint': -0.733,
59  'ra_wrist_2_joint': 1.5708, 'ra_wrist_3_joint': 0.00,
60  'rh_THJ1': 0.52, 'rh_THJ2': 0.61, 'rh_THJ3': 0.0, 'rh_THJ4': 1.20,
61  'rh_THJ5': 0.17, 'rh_FFJ1': 1.5707, 'rh_FFJ2': 1.5707, 'rh_FFJ3': 1.5707,
62  'rh_FFJ4': 0.0, 'rh_MFJ1': 1.5707, 'rh_MFJ2': 1.5707, 'rh_MFJ3': 1.5707,
63  'rh_MFJ4': 0.0, 'rh_RFJ1': 1.5707, 'rh_RFJ2': 1.5707, 'rh_RFJ3': 1.5707,
64  'rh_RFJ4': 0.0, 'rh_LFJ1': 1.5707, 'rh_LFJ2': 1.5707, 'rh_LFJ3': 1.5707,
65  'rh_LFJ4': 0.0, 'rh_LFJ5': 0.0, 'rh_WRJ1': 0.0, 'rh_WRJ2': 0.0}
66 
67 hand_arm_joints_goal_1 = {'rh_FFJ1': 1.57, 'rh_FFJ2': 1.57, 'rh_FFJ3': 1.574, 'rh_FFJ4': -0.00,
68  'rh_THJ4': -0.00, 'rh_THJ5': 6.49, 'rh_THJ1': -1.49, 'rh_THJ2': 4.72,
69  'rh_THJ3': 3.19, 'rh_LFJ2': 1.57, 'rh_LFJ3': 1.57, 'rh_LFJ1': 1.57,
70  'rh_LFJ4': 0.00, 'rh_LFJ5': -3.13, 'rh_RFJ4': -0.00, 'rh_RFJ1': 1.57,
71  'rh_RFJ2': 1.57, 'rh_RFJ3': 1.57, 'rh_MFJ1': 1.57, 'rh_MFJ3': 1.57,
72  'rh_MFJ2': 1.57, 'rh_MFJ4': -0.00, 'rh_WRJ2': -1.29, 'rh_WRJ1': 0.00,
73  'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.00,
74  'ra_shoulder_lift_joint': -1.57, 'ra_wrist_3_joint': 0.00}
75 
76 hand_arm_joints_goal_2 = {'rh_FFJ1': -0.00, 'rh_FFJ2': 1.31, 'rh_FFJ3': 1.36, 'rh_FFJ4': -0.00,
77  'rh_MFJ1': 0.42, 'rh_MFJ2': 1.57, 'rh_MFJ3': 1.21, 'rh_MFJ4': 0.0,
78  'rh_RFJ1': -0.00, 'rh_RFJ2': 1.5707, 'rh_RFJ3': 1.41, 'rh_RFJ4': -0.00,
79  'rh_LFJ1': 1.57, 'rh_LFJ2': 0.84, 'rh_LFJ3': 0.36, 'rh_LFJ4': 0.22,
80  'rh_LFJ5': 0.19, 'rh_THJ1': 0.0, 'rh_THJ2': 0.0, 'rh_THJ3': 0.0,
81  'rh_THJ4': 0.0, 'rh_THJ5': 0.0, 'rh_WRJ1': 0.6, 'rh_WRJ2': 0.0,
82  'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.10,
83  'ra_shoulder_lift_joint': -1.4, 'ra_wrist_1_joint': -0.733,
84  'ra_wrist_2_joint': 1.5708, 'ra_wrist_3_joint': 0.00}
85 
86 # Evaluate the plan quality from starting position of robot.
87 # https://github.com/shadow-robot/sr_interface/blob/melodic-devel/sr_robot_commander/src/sr_robot_commander/sr_robot_commander.py#L263-L310
88 # This is to confirm that the arm is in a safe place to move to the home joints goal,
89 # if the outcome is poor please refer to the readthedocs of where the start arm home position is.
90 arm_to_home_plan = arm_commander.plan_to_joint_value_target(arm_home_joints_goal)
91 arm_to_home_plan_quality = arm_commander.evaluate_given_plan(arm_to_home_plan)
92 eval_arm_home_plan_quality = arm_commander.evaluate_plan_quality(arm_to_home_plan_quality)
93 
94 if eval_arm_home_plan_quality != 'good':
95  rospy.logfatal("Plan quality to the home position is poor! " +
96  "For safety please refer to the hand and arm documentation " +
97  "for where to start the arm " +
98  "to ensure no unexpected movements during plan and execute.")
99  sys.exit("Exiting script to allow for the arm to be manually moved to better start position ...")
100 
101 # Execute arm to home plan
102 rospy.loginfo("Planning and moving arm to home joint states\n" + str(arm_home_joints_goal) + "\n")
103 arm_commander.execute_plan(arm_to_home_plan)
104 rospy.sleep(2.0)
105 
106 # Move through each goal
107 # joint states are sent to the commanders, with a time for execution and a flag as to whether
108 # or not the commander should wait for the command to complete before moving to the next command.
109 # https://github.com/shadow-robot/sr_interface/blob/melodic-devel/sr_robot_commander/src/sr_robot_commander/sr_robot_commander.py#L723
110 
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)
115 
116 # Move arm and hand together
117 raw_input("Press Enter to continue...")
118 rospy.loginfo("Moving hand to joint states\n" + str(hand_arm_joints_goal_1) + "\n")
119 robot_commander.move_to_joint_value_target_unsafe(hand_arm_joints_goal_1, 6.0, True)
120 rospy.sleep(2.0)
121 
122 # Move arm and hand together
123 raw_input("Press Enter to continue...")
124 rospy.loginfo("Moving hand and arm to joint states\n" + str(hand_arm_joints_goal_2) + "\n")
125 robot_commander.move_to_joint_value_target_unsafe(hand_arm_joints_goal_2, 6.0, True)
126 rospy.sleep(2.0)
127 
128 # Finish arm at home and hand at pack
129 raw_input("Press Enter to continue...")
130 rospy.loginfo("Moving arm and hand to joint states\n" + str(arm_hand_home_joints_goal) + "\n")
131 robot_commander.move_to_joint_value_target_unsafe(arm_hand_home_joints_goal, 6.0, True)
132 rospy.sleep(2.0)


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