sr_print_joints_position.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 for all joints.
17 # Useful when used in conjunction with 'teach mode', as new motion sequences can
18 # be quickly produced from physically moving the robot into position and then
19 # recording those positions with this script. Angles can be printed in radians or degrees, an argument should be added
20 # when the script is called of either 'radians' or 'degrees', default is radians
21 
22 import rospy
23 from sr_robot_commander.sr_hand_commander import SrHandCommander
24 from sr_utilities.hand_finder import HandFinder
25 from math import pi
26 import argparse
27 
28 
29 rospy.init_node("print_joints_position", anonymous=True)
30 
31 parser = argparse.ArgumentParser(description='A script to print hand and arm joint positions. ',
32  add_help=True, usage='%(prog)s [-h] --angle_type ANGLE_TYPE',
33  formatter_class=argparse.RawTextHelpFormatter)
34 
35 parser.add_argument(dest='--angle_type', help="ANGLE_TYPE should be either degrees or radians")
36 args = parser.parse_args()
37 
38 angle_type = args.angle_type
39 
40 # Use the hand finder to get the hand prefix, to allow this script to be used with either left or right hands
41 hand_finder = HandFinder()
42 hand_parameters = hand_finder.get_hand_parameters()
43 prefix = hand_parameters.mapping.values()[0]
44 hand_serial = hand_parameters.mapping.keys()[0]
45 scale = 1
46 
47 if angle_type == "degrees":
48  scale = 1 * (180/pi)
49 
50 hand_commander = SrHandCommander(hand_parameters=hand_parameters, hand_serial=hand_serial)
51 
52 print("Joints positions")
53 
54 all_joints_state = hand_commander.get_joints_position()
55 
56 
57 hand_joints_state = {
58  k: (v * scale) for k, v in all_joints_state.items()
59  if k.startswith(prefix + "_")and not k.startswith(prefix + "_W")}
60 arm_joints_state = {
61  k: (v * scale) for k, v in all_joints_state.items()
62  if k.startswith(prefix[0] + "a_") or k.startswith(prefix + "_W")}
63 
64 
65 print("Hand joints position \n " + str(hand_joints_state) + "\n")
66 
67 print("Arm joints position \n " + str(arm_joints_state) + "\n")


sr_example
Author(s): Ugo Cupcic
autogenerated on Wed Oct 14 2020 04:05:12