ordered_target_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('target_joint_state_merger', anonymous=True)
10  self.subs_1 = rospy.Subscriber("/srh/target/joint_states", JointState, self.callback1)
11  self.subs_2 = rospy.Subscriber("/sr_arm/target/joint_states", JointState, self.callback2)
12 
13  self.pub = rospy.Publisher("/targets/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 
46  self.mutex.release()
47 
48  def callback2(self, data):
49  self.mutex.acquire()
50 
51  self.msg_2_received = True
52 
53  self.joint_state_msg.header.stamp = rospy.Time.now()
54 
55  tmp = self.joint_state_msg.name
56  tmp += data.name
57  self.joint_state_msg.name = tmp
58 
59  tmp = self.joint_state_msg.position
60  tmp += data.position
61  self.joint_state_msg.position = tmp
62 
63  tmp = self.joint_state_msg.velocity
64  tmp += data.velocity
65  self.joint_state_msg.velocity = tmp
66 
67  tmp = self.joint_state_msg.effort
68  tmp += data.effort
69  self.joint_state_msg.effort = tmp
70 
71  if self.msg_1_received:
72  self.pub.publish(self.joint_state_msg)
73  self.msg_1_received = False
74  self.msg_2_received = False
75  self.joint_state_msg = JointState()
76 
77  self.mutex.release()
78 
79 
80 if __name__ == '__main__':
81  merger = MergeMessages()


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