sr_handfinder_example.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 # Example use of handfinder for a 5 fingered hand. The serial number and hand parameters
17 # are read and it is detected whether the hand is left or right and if there are tactiles present.
18 # The correct prefix and parameters are then configured.
19 
20 import sys
21 import rospy
22 from sr_robot_commander.sr_hand_commander import SrHandCommander
23 from sr_utilities.hand_finder import HandFinder
24 
25 rospy.init_node("basic_hand_examples", anonymous=True)
26 
27 hand_finder = HandFinder()
28 
29 hand_parameters = hand_finder.get_hand_parameters()
30 hand_serial = hand_parameters.mapping.keys()[0]
31 
32 hand_commander = SrHandCommander(hand_parameters=hand_parameters,
33  hand_serial=hand_serial)
34 
35 hand_mapping = hand_parameters.mapping[hand_serial]
36 
37 # Hand joints are detected
38 joints = hand_finder.get_hand_joints()[hand_mapping]
39 
40 position_values = [0.35, 0.18, 0.38]
41 
42 # Moving to a target determined by the values in position_values.
43 rospy.loginfo("Hand moving to script specified target")
44 position_1 = dict(zip(joints, position_values))
45 hand_commander.move_to_joint_value_target(position_1)
46 
47 named_target_1 = "pack"
48 rospy.loginfo("Hand moving to named target: " + named_target_1)
49 hand_commander.move_to_named_target(named_target_1)
50 
51 named_target_2 = "open"
52 rospy.loginfo("Hand moving to named target: " + named_target_2)
53 hand_commander.move_to_named_target(named_target_2)
54 
55 # Hand joints state, velocity and effort are read and displayed to screen.
56 hand_joints_state = hand_commander.get_joints_position()
57 hand_joints_velocity = hand_commander.get_joints_velocity()
58 hand_joints_effort = hand_commander.get_joints_effort()
59 
60 rospy.loginfo("Hand joints position \n " + str(hand_joints_state) + "\n")
61 rospy.loginfo("Hand joints velocity \n " + str(hand_joints_velocity) + "\n")
62 rospy.loginfo("Hand joints effort \n " + str(hand_joints_effort) + "\n")
63 
64 # Tactile type and state are read and displayed to screen.
65 tactile_type = hand_commander.get_tactile_type()
66 tactile_state = hand_commander.get_tactile_state()
67 rospy.loginfo("Tactile type \n " + str(tactile_type) + "\n")
68 rospy.loginfo("Tactile state \n " + str(tactile_state) + "\n")


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