ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Just to add to the reply posted by @dornhege:
It is fairly common to drop the first few messages played from a bag file.
When you start your program early, this only ensures that topic subscriptions are advertised before playing the bag-file topics. The way ROS handles message-publishing is by creating explicit connections between the publisher and subscriber once "matching" topic names/types have been identified. This connection happens when the publisher and subscriber have both advertised the same topic. Once the connection is made, then the subscriber starts processing any messages received after the connection is completed. Any messages published before that connection is finalized are simply dropped.
When playing a bag file with the default settings, there is a very small (near-zero) delay between advertising a topic and playing the messages from that topic. This can cause the first few messages to be dropped before the subscriber connection is fully completed.
Thankfully, there is an easy solution to this problem. Play the bag file with a delay
option to introduce a pause between advertising the topic and publishing the messages. This delay allows time for subscriber clients to connect before publishing any messages, so none are dropped:
rosbag play -d 0.5 myData.bag