sr_publisher_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 # -*- coding: utf-8 -*-
18 
19 """
20 An example that demonstrates how to publish command messages to joints in the hand.
21 The hand should be launched but the trajectory controllers should
22 not be running as they overwrite position commands. To check if they are, a call to
23 rosservice can be made with the following command:
24 >rosservice call /controller_manager/list_controllers
25 To stop the trajectory controllers, open the gui (type rqt) and select position control in
26 plugins > Shadow Robot > Change controllers
27 
28 """
29 
30 
31 import roslib
32 import rospy
33 import time
34 import math
35 from std_msgs.msg import Float64
36 
37 roslib.load_manifest('sr_example')
38 
39 
40 # Controller that controls joint position
41 controller_type = "_position_controller"
42 
43 
44 def talker():
45  """
46  The Publisher publishes two commands to move joint rh_FFJ0 and rh_RFJ0
47 
48  """
49  joint1 = 'rh_ffj0'
50  joint2 = 'rh_rfj0'
51 
52  # Initialise the ROS node
53  rospy.init_node('publisher_example')
54 
55  pub1 = rospy.Publisher(
56  'sh_' + joint1 + controller_type + '/command', Float64, latch=True, queue_size=1)
57  pub2 = rospy.Publisher(
58  'sh_' + joint2 + controller_type + '/command', Float64, latch=True, queue_size=1)
59 
60  # define a new target value for the joint position in degrees.
61  # The position controllers expect their commands in radians
62  new_target_1 = math.radians(20)
63  new_target_2 = math.radians(20)
64 
65  time.sleep(1)
66  print ("publishing:")
67  print (joint1 + " to " + str(math.degrees(new_target_1)) + " degrees\n" +
68  joint2 + " to " + str(math.degrees(new_target_2)) + " degrees")
69 
70  # This will move the joint rh_ffj0 to the defined target (20 degrees)
71  pub1.publish(new_target_1)
72 
73  # This will move the joint rh_rfj0 to the defined target (20 degrees)
74  pub2.publish(new_target_2)
75 
76 
77 if __name__ == '__main__':
78  try:
79  talker()
80  except rospy.ROSInterruptException:
81  pass


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