joint_0_publisher.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 import rospy
18 from sensor_msgs.msg import JointState
19 
20 
22  def __init__(self):
23  rospy.init_node('joint_0_publisher', anonymous=True)
24  rospy.wait_for_message("joint_states", JointState)
25  self.sub = rospy.Subscriber("joint_states", JointState, self.callback)
26  self.pub = rospy.Publisher("joint_0s/joint_states", JointState, queue_size=1)
27  self.joint_state_msg = JointState()
28 
29  rospy.spin()
30 
31  def callback(self, data):
32  self.joint_state_msg.header.stamp = rospy.Time.now()
33 
34  self.joint_state_msg.name = []
35  self.joint_state_msg.position = []
36  self.joint_state_msg.velocity = []
37  self.joint_state_msg.effort = []
38 
39  fj0 = [0.0, 0.0, 0.0]
40  for name, position, velocity, effort in zip(data.name,
41  data.position,
42  data.velocity,
43  data.effort):
44  if "FJ1" in name and len(name) == 4:
45  fj0 = [position, velocity, effort]
46 
47  if "FJ2" in name and len(name) == 4:
48  fj0 = [fj0[0] + position, fj0[1] + velocity, fj0[2] + effort]
49  self.joint_state_msg.name.append(name[0]+"FJ0")
50  self.joint_state_msg.position.append(fj0[0])
51  self.joint_state_msg.velocity.append(fj0[1])
52  self.joint_state_msg.effort.append(fj0[2])
53 
54  self.pub.publish(self.joint_state_msg)
55 
56 if __name__ == '__main__':
57  j0_pub = Joint0Publisher()


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:19