sr_right_print_joints_pos.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 # An example of how to print the current joint positions of the right arm and hand for all joints.
17 # be quickly produced from physically moving the robot into position and then
18 # recording those positions with this script. Angles can be printed in radians or degrees, an argument should be added
19 # when the script is called of either 'radians' or 'degrees', default is radians
20 
21 # For more information, please see:
22 # https://dexterous-hand.readthedocs.io/en/latest/user_guide/2_software_description.html#robot-commander
23 
24 # roslaunch commands used with this script to launch the robot:
25 # real robot with a NUC (or a separate computer with an RT kernel):
26 # roslaunch sr_right_ur10arm_hand.launch external_control_loop:=true sim:=false scene:=true
27 # simulated robot:
28 # roslaunch sr_right_ur10arm_hand.launch sim:=true scene:=true
29 
30 import rospy
31 from sr_robot_commander.sr_robot_commander import SrRobotCommander
32 from math import pi
33 import argparse
34 
35 rospy.init_node("print_joints_position", anonymous=True)
36 
37 parser = argparse.ArgumentParser(description='A script to print hand and arm joint positions. ',
38  add_help=True, usage='%(prog)s [-h] --angle_type ANGLE_TYPE',
39  formatter_class=argparse.RawTextHelpFormatter)
40 parser.add_argument('--angle_type', dest='angle_type',
41  default='radians',
42  help="ANGLE_TYPE should be either degrees or radians")
43 args = parser.parse_args()
44 
45 angle_type = args.angle_type
46 if angle_type not in ['radians', 'degrees']:
47  parser.print_help()
48  exit(1)
49 
50 scale = 1
51 if angle_type == "degrees":
52  scale = 1 * (180/pi)
53 
54 # The constructor for SrRobotCommander
55 # take a name parameter that should match the group name of the robot to be used.
56 robot_commander = SrRobotCommander(name="right_arm_and_hand")
57 
58 # get_joints_position returns a dictionary with joints poisitions
59 all_joints_state = robot_commander.get_joints_position()
60 
61 hand_joints_state = {
62  k: (v * scale) for k, v in all_joints_state.items()
63  if k.startswith("rh_")and not k.startswith("rh_W")}
64 arm_joints_state = {
65  k: (v * scale) for k, v in all_joints_state.items()
66  if k.startswith("ra_") or k.startswith("rh_W")}
67 
68 rospy.loginfo("Joints positions:")
69 rospy.loginfo("Hand joints position \n " + str(hand_joints_state) + "\n")
70 rospy.loginfo("Arm joints position \n " + str(arm_joints_state) + "\n")


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