sr_link_joints_example.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2011 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 """
18 This example demonstrates how two joints can have their positions 'linked' by
19 having a child joint subscribing to the parent joint's controller state topic.
20 The messages are then published to the child joint's controller.
21 
22 The hand should be launched but the trajectory controllers should
23 not be running as they overwrite position commands. To check if they are, a call
24 to rosservice can be made with the following command:
25 >rosservice call /controller_manager/list_controllers
26 To stop the trajectory controllers, open the gui (type rqt) and select position control in
27 plugins > Shadow Robot > Change controllers
28 NOTE: If the joint sliders plugin is open during this change of controllers, it will
29 need to be reloaded.
30 
31 A position can then be published to the parent joint or the joint could be moved by
32 using the joint sliders in the gui, plugins > Shadow Robot > joint slider
33 
34 If you move the joint slider for the parent joint, the child joint will move as well.
35 """
36 
37 import roslib
38 import rospy
39 from std_msgs.msg import Float64
40 from control_msgs.msg import JointControllerState
41 
42 roslib.load_manifest('sr_example')
43 
44 # Joints to be linked
45 parent_name = "rh_ffj3"
46 child_name = "rh_rfj3"
47 
48 # Controller that controls joint position
49 controller_type = "_position_controller"
50 
51 pub = rospy.Publisher(
52  '/sh_' + child_name + controller_type + '/command', Float64, queue_size=1)
53 
54 
55 def callback(data):
56  """
57  The callback function: called each time a message is received on the
58  topic parent joint controller state topic
59 
60  @param data: the message
61  """
62  # publish the message to the child joint controller command topic.
63  # here we insert the joint name into the topic name
64  pub.publish(data.set_point)
65 
66 
67 def listener():
68  """
69  The main function
70  """
71  # init the ros node
72  rospy.init_node('link_joints_example', anonymous=True)
73 
74  # init the subscriber: subscribe to the
75  # parent joint controller topic, using the callback function
76  # callback()
77  rospy.Subscriber('/sh_' + parent_name + controller_type +
78  '/state', JointControllerState, callback)
79  # subscribe until interrupted
80  rospy.spin()
81 
82 
83 if __name__ == '__main__':
84  listener()


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