Nodes asynchronously accessing messages/data
I have a sensor which outputs data at a slow rate, I want to create another node which uses a nonblocking loop to access this data and either continues an action or changes actions based upon what it scans but I don't want the node to block and wait for the next sensor reading.
How do I do this in python and ROS? The rospy.waitformessage() function looks like it will block until the next message is published instead of accessing the most recent sensor scan - is this correct?
Should I make a subscriber node whose main spawns a separate thread? But then how do you transmit data between your callback function and that thread? I have seen people make a global variable which is used to transmit information between a subscriber and publisher which exist in a single node - is this the best way to do it?