virtual_ShadowPST_publisher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # This node combines 5 virtual touch sensors into a ShadowPST message compatible with etherCAT hand
3 
4 import rospy
5 from std_msgs.msg import Float64
6 from sr_robot_msgs.msg import ShadowPST
7 import thread
8 
9 
10 class MergeMessages(object):
11  def __init__(self):
12  rospy.init_node('ShadowPST_publisher', anonymous=True)
13  self.ff_sub = rospy.Subscriber('/sr_tactile/touch/ff', Float64, self.ff_cb)
14  self.mf_sub = rospy.Subscriber('/sr_tactile/touch/mf', Float64, self.mf_cb)
15  self.rf_sub = rospy.Subscriber('/sr_tactile/touch/rf', Float64, self.rf_cb)
16  self.lf_sub = rospy.Subscriber('/sr_tactile/touch/lf', Float64, self.lf_cb)
17  self.th_sub = rospy.Subscriber('/sr_tactile/touch/th', Float64, self.th_cb)
18  self.rate = rospy.Rate(25.0)
19  self.pub = rospy.Publisher("/tactile", ShadowPST)
20  self.pst = [0.0, 0.0, 0.0, 0.0, 0.0]
21  self.mutex = thread.allocate_lock()
22 
23  def ff_cb(self, msg):
24  self.mutex.acquire()
25  self.pst[0] = msg.data
26  self.mutex.release()
27 
28  def mf_cb(self, msg):
29  self.mutex.acquire()
30  self.pst[1] = msg.data
31  self.mutex.release()
32 
33  def rf_cb(self, msg):
34  self.mutex.acquire()
35  self.pst[2] = msg.data
36  self.mutex.release()
37 
38  def lf_cb(self, msg):
39  self.mutex.acquire()
40  self.pst[3] = msg.data
41  self.mutex.release()
42 
43  def th_cb(self, msg):
44  self.mutex.acquire()
45  self.pst[4] = msg.data
46  self.mutex.release()
47 
49  pst_state_msg = ShadowPST()
50  pst_state_msg.temperature = [0, 0, 0, 0, 0, 0]
51  pressure = []
52  self.mutex.acquire()
53  for i in range(0, 5):
54  pressure.append(self.pst[i]*100)
55  pst_state_msg.pressure = pressure
56  # print pst_state_msg.pressure
57  self.mutex.release()
58 
59  pst_state_msg.header.stamp = rospy.Time.now()
60  self.pub.publish(pst_state_msg)
61 
62 if __name__ == '__main__':
63  merger = MergeMessages()
64  while not rospy.is_shutdown():
65  merger.shadowpst_publisher()
66  merger.rate.sleep()


sr_tactile_sensors
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:46