dynamixel_joint_state_publisher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4  dynamixel_joint_state_publisher.py - Version 1.0 2010-12-28
5 
6  Publish the dynamixel_controller joint states on the /joint_states topic
7 
8  Created for the Pi Robot Project: http://www.pirobot.org
9  Copyright (c) 2010 Patrick Goebel. All rights reserved.
10 
11  This program is free software; you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details at:
20 
21  http://www.gnu.org/licenses/gpl.html
22 """
23 import rospy
24 
25 from sensor_msgs.msg import JointState as JointStatePR2
26 from dynamixel_msgs.msg import JointState as JointStateDynamixel
27 from dynamixel_controllers.srv import SetSpeed
28 from dynamic_reconfigure.server import Server
29 from jsk_tilt_laser.cfg import DynamixelTiltControllerConfig
30 
32  def __init__(self, name, position, velocity, effort):
33  self.name = name
34  self.position = position
35  self.velocity = velocity
36  self.effort = effort
37 
39  def __init__(self):
40  rospy.init_node('dynamixel_joint_state_publisher', anonymous=True)
41  rospy.wait_for_service('tilt_controller/set_speed')
42  self.srv = Server(DynamixelTiltControllerConfig, self.reconfigure_callback)
43  dynamixel_namespace = rospy.get_namespace()
44  rate = rospy.get_param('~rate', 10)
45  r = rospy.Rate(rate)
46 
47  self.joints = list()
48 
49  # Get all parameter names
50  parameters = rospy.get_param_names()
51 
52  for parameter in parameters:
53  # Look for the parameters that name the joints.
54  if parameter.find(dynamixel_namespace) != -1 and parameter.find("joint_name") != -1:
55  self.joints.append(rospy.get_param(parameter))
56 
57  self.servos = list()
58  self.controllers = list()
59  self.joint_states = dict({})
60 
61  for joint in self.joints:
62  # Remove "_joint" from the end of the joint name to get the controller names.
63  servo = joint.split("_joint")[0]
64  self.joint_states[joint] = JointStateMessage(joint, 0.0, 0.0, 0.0)
65  # ARD
66  self.controllers.append(dynamixel_namespace + servo + "_controller")
67  # self.controllers.append(joint)
68  rospy.loginfo("Dynamixel Joint State Publisher " + joint)
69 
70  # Start controller state subscribers
71  [rospy.Subscriber(c + '/state', JointStateDynamixel, self.controller_state_handler) for c in self.controllers]
72 
73  # Start publisher
74  self.joint_states_pub = rospy.Publisher('/joint_states', JointStatePR2)
75 
76  rospy.loginfo("Starting Dynamixel Joint State Publisher at " + str(rate) + "Hz")
77 
78  while not rospy.is_shutdown():
80  # With 23 servos, we go as fast as possible
81  r.sleep()
82  def reconfigure_callback(self, config, level):
83  try:
84  set_speed = rospy.ServiceProxy('tilt_controller/set_speed', SetSpeed)
85  set_speed(config.tilt_speed)
86  except rospy.ServiceException, e:
87  print "Service call failed: %s"%e
88  return config
89  def controller_state_handler(self, msg):
90  js = JointStateMessage(msg.name, msg.current_pos, msg.velocity, msg.load)
91  self.joint_states[msg.name] = js
92 
94  # Construct message & publish joint states
95  msg = JointStatePR2()
96  msg.name = []
97  msg.position = []
98  msg.velocity = []
99  msg.effort = []
100 
101  for joint in self.joint_states.values():
102  msg.name.append(joint.name)
103  fudge_value = rospy.get_param('~fudge_factor/' + joint.name + '/value', 0.0)
104  j_pos = joint.position - fudge_value
105  # rospy.loginfo("fudge " + str(joint.name) + ': ' + str(j_pos) + ' = ' + str(joint.position) + ' - ' + str(fudge_value))
106  msg.position.append(j_pos)
107  msg.velocity.append(joint.velocity)
108  msg.effort.append(joint.effort)
109 
110  msg.header.stamp = rospy.Time.now()
111  self.joint_states_pub.publish(msg)
112 
113 if __name__ == '__main__':
114  try:
116  rospy.spin()
117  except rospy.ROSInterruptException: pass
118 
def __init__(self, name, position, velocity, effort)


jsk_tilt_laser
Author(s): YoheiKakiuchi
autogenerated on Tue Feb 6 2018 03:45:14