joint_state_publisher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4  joint_state_publisher - Version 2.0 2017-3-18
5  dynamixel_joint_state_publisher.py - Version 1.0 2010-12-28
6 
7  Publish the dynamixel_controller joint states on the /joint_states topic
8 
9  Created for the Pi Robot Project: http://www.pirobot.org
10  Copyright (c) 2010 Patrick Goebel. All rights reserved.
11  Copyright (c) 2017 Svenzva Robotics
12 
13  This program is free software; you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details at:
22 
23  http://www.gnu.org/licenses/gpl.html
24 """
25 
26 import roslib
27 import rospy
28 
29 from sensor_msgs.msg import JointState as JointStatePR2
30 from svenzva_msgs.msg import MotorStateList
31 
33  def __init__(self, name, position, velocity, effort):
34  self.name = name
35  self.position = position
36  self.velocity = velocity
37  self.effort = effort
38 
40  def __init__(self):
41  rospy.init_node('joint_state_publisher', anonymous=True)
42 
43  rate = rospy.get_param('~rate', 20)
44  r = rospy.Rate(rate)
45  namespace = rospy.get_param('~arm_namespace', '')
46  self.joints = rospy.get_param('joint_names', '')
47 
48  self.motor_states = []
49 
50  # Start controller state subscribers
51  rospy.Subscriber(namespace + '/motor_states', MotorStateList, self.motor_state_cb)
52 
53  # Start publisher
54  self.joint_states_pub = rospy.Publisher('/joint_states', JointStatePR2, queue_size=1)
55 
56  rospy.loginfo("Starting Joint State Publisher at " + str(rate) + "Hz")
57 
58  #2*theta*r / pi = linear_distance due to 1:1 gear ratio for rack/pinion system
59  self.finger_divisor = .0246 / 3.14159 * 2
60 
61  while not rospy.is_shutdown():
63  r.sleep()
64 
65  def motor_state_cb(self, msg):
66  self.motor_states = msg.motor_states
67 
69  # Construct message & publish joint states
70  msg = JointStatePR2()
71  msg.name = []
72  msg.position = []
73  msg.velocity = []
74  msg.effort = []
75 
76  for i, joint in enumerate(self.motor_states):
77  #linear fit into torque in Nm
78  effort_nm = joint.load * 0.00336 * 1.083775
79  if i == 6:
80  #finger 1
81  msg.name.append(self.joints[i])
82  msg.position.append(-1 * joint.position * self.finger_divisor)
83  msg.velocity.append(-1 * joint.speed)
84  msg.effort.append(-1 * effort_nm)
85 
86 
87  #finger 2
88  msg.name.append(self.joints[i+1])
89  msg.position.append(1 * joint.position * self.finger_divisor)
90  msg.velocity.append(1 * joint.speed)
91  msg.effort.append(1 * effort_nm)
92  else:
93  msg.name.append(self.joints[i])
94  msg.position.append(joint.position)
95  msg.velocity.append(joint.speed)
96  msg.effort.append(effort_nm)
97 
98  msg.header.stamp = rospy.Time.now()
99 
100  self.joint_states_pub.publish(msg)
101 
102 if __name__ == '__main__':
103  try:
105  rospy.spin()
106  except rospy.ROSInterruptException: pass
107 
def __init__(self, name, position, velocity, effort)


svenzva_drivers
Author(s): Max Svetlik
autogenerated on Wed Oct 28 2020 03:31:27