ordered_position_joint_states_merger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 from sensor_msgs.msg import JointState
4 import thread
5 
6 
8  def __init__(self):
9  rospy.init_node('position_joint_state_merger', anonymous=True)
10  self.subs_1 = rospy.Subscriber("/srh/position/joint_states", JointState, self.callback1)
11  self.subs_2 = rospy.Subscriber("/sr_arm/position/joint_states", JointState, self.callback2)
12 
13  self.pub = rospy.Publisher("/positions/joint_states", JointState)
14 
15  self.msg_1_received = False
16  self.msg_2_received = False
17 
18  self.joint_state_msg = JointState()
19 
20  self.mutex = thread.allocate_lock()
21 
22  rospy.spin()
23 
24  def callback1(self, data):
25  self.mutex.acquire()
26  if self.msg_1_received:
27  self.mutex.release()
28  return
29 
30  self.msg_1_received = True
31 
32  self.joint_state_msg.header.stamp = rospy.Time.now()
33 
34  tmp = data.name
35  self.joint_state_msg.name = tmp
36 
37  tmp = data.position
38  self.joint_state_msg.position = tmp
39 
40  tmp = data.velocity
41  self.joint_state_msg.velocity = tmp
42 
43  tmp = data.effort
44  self.joint_state_msg.effort = tmp
45  self.mutex.release()
46 
47  def callback2(self, data):
48  self.mutex.acquire()
49 
50  self.msg_2_received = True
51 
52  self.joint_state_msg.header.stamp = rospy.Time.now()
53 
54  tmp = self.joint_state_msg.name
55  tmp += data.name
56  self.joint_state_msg.name = tmp
57 
58  tmp = self.joint_state_msg.position
59  tmp += data.position
60  self.joint_state_msg.position = tmp
61 
62  tmp = self.joint_state_msg.velocity
63  tmp += data.velocity
64  self.joint_state_msg.velocity = tmp
65 
66  tmp = self.joint_state_msg.effort
67  tmp += data.effort
68  self.joint_state_msg.effort = tmp
69 
70  if self.msg_1_received:
71  self.pub.publish(self.joint_state_msg)
72  self.msg_1_received = False
73  self.msg_2_received = False
74  self.joint_state_msg = JointState()
75 
76  self.mutex.release()
77 
78 
79 if __name__ == '__main__':
80  merger = MergeMessages()


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:49