ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The variable that you create for each sensor is only valid inside its callback.

Your callbacks will be called asynchronously, whenever there is new data on a topic. This means that you can't assume that callbacks will be called in order.

Instead of trying to write all four reading to your database in the callback for one sensor (where you only have data from one sensor), I suggest a different approach. You have a few choices:

  • Gather the data into a single message with all of your sensor readings on the publisher, so that you only need to subscribe to one message
  • Store the data from each sensor separately in the database, so that you don't need to collect all four sensor readings
  • Use an Approximate Time Synchronizer from the message_filters package to synchronize your sensor readings so that you get a single callback with all four sensor readings. The message_filters python docs may be useful.
  • Build your own synchronization mechanism