I'm trying to write a python node, which has one class and two member functions as callback functions. so a TimeSynchronizer and Subscriber in a node. I saw in this link and tested that python subscribers are event-driven model and are in separate threads. How to get a python node in ROS subscribe to multiple topics?
My question here is , are they thread safe when they are working on the same class member? e.g. self.a below. Do I need to write a lock? Where can I find more information about this? Thank you in advanced!!!!
def __init__(self): self.a = [1,2,3,4,5] rospy.init_node('mr_listener', anonymous=True) scan_subscriber = message_filters.Subscriber('/scan',LaserScan) pose_subscriber = message_filters.Subscriber('/slam_out_pose', PoseStamped) ts = message_filters.ApproximateTimeSynchronizer([scan_subscriber,projected_scan_subscriber,pose_subscriber], 10, 0.1, allow_headerless=True) ts.registerCallback(self.callback1) rospy.Subscriber("chatter", String, self.callback2) rospy.spin() def callback1(self,scan,pose): somthing def callback2(self,chatt): somingthing rospy.sleep(1.)