ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Even though ros::Time is initialized to 0 seconds 0 nanoseconds (like it is by default in your code), you cannot add a message to a bag file with this timestamp. It has to be at least 0 seconds and 1 nanosecond. Generally, you should make sure that the timestamp you are about to pass in is not 0:
ros::Time timeStamp;
//...
if (timeStamp.toNSec == 0) timeStamp = ros::TIME_MIN;
bag.write("topic", timeStamp, message);
I just checked, ros::TIME_MIN will set the bag time to exactly 0 seconds and 1 nanosecond.