Order / time stamps of messages in ros2bag
I'm running ros2 foxy on ubuntu x64.
I've tried to find more information in other questions. While finding some hints in that direction in
but no answer that fully covered this question.
To illustrate my question, I've created this node in rclcpp:
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include "example.hpp"
EX::EX() : Node("EX")
{
pub_temp = this->create_publisher<sensor_msgs::msg::Temperature> ("myTemp", 1);
}
int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
auto node = std::make_shared<EX>();
rclcpp::Rate loop_rate(20);
sensor_msgs::msg::Temperature myTemp;
rclcpp::Clock clk;
while (rclcpp::ok())
{
rclcpp::Time now = clk.now();
myTemp.temperature = now.seconds();
myTemp.header.stamp = now;
node->pub_temp->publish(myTemp);
loop_rate.sleep();
rclcpp::spin_some(node);
}
rclcpp::shutdown();
return 0;
}
The only aim is to publish current time in a message, while reusing already defined sensor_msg.
Having this node running, I record a rosbag by means of
ros2 bag record -a -o test
Then, I convert the rosbag into a csv by means of https://github.com/fishros/ros2bag_co..., which seems to be just a python interface to ros2bag.
In resulting csv, I see both, temperature (used as container for float time in seconds) and header.stamp are equal and monotonic increasing. But the rosbag timestamps are not monotonic increasing (removed other columns to improve readability)
time,temperature
2023/04/14 23:25:01.713269932,1681507501.712159
2023/04/14 23:25:01.763184384,1681507501.7621498
2023/04/14 23:25:01.813263977,1681507501.8121464
2023/04/14 23:25:01.863493836,1681507501.8623857
2023/04/14 23:25:01.913219134,1681507501.9123156
2023/04/14 23:25:01.963290093,1681507501.9621348
2023/04/14 23:25:02.12836290,1681507502.0120738 <-- wrong order
2023/04/14 23:25:02.63265628,1681507502.0622058 <-- wrong order
2023/04/14 23:25:02.109310622,1681507502.1082995
2023/04/14 23:25:02.163232019,1681507502.162216
2023/04/14 23:25:02.212783868,1681507502.2116454
2023/04/14 23:25:02.263243347,1681507502.262219
2023/04/14 23:25:02.309256681,1681507502.3084276
2023/04/14 23:25:02.363401993,1681507502.3622973
2023/04/14 23:25:02.413387354,1681507502.4122632
2023/04/14 23:25:02.463181642,1681507502.4621735
2023/04/14 23:25:02.513352901,1681507502.5121999
2023/04/14 23:25:02.563386845,1681507502.562251
2023/04/14 23:25:02.613217409,1681507502.6121466
2023/04/14 23:25:02.663480320,1681507502.6622477
2023/04/14 23:25:02.713262122,1681507502.7121816
2023/04/14 23:25:02.763399794,1681507502.7621949
2023/04/14 23:25:02.813229584,1681507502.8121612
2023/04/14 23:25:02.863225064,1681507502.8621368
2023/04/14 23:25:02.913630391,1681507502.912515
2023/04/14 23:25:02.963167168,1681507502.9621494
2023/04/14 23:25:03.13150167,1681507503.0121276 <-- wrong order
2023/04/14 23:25:03.63157445,1681507503.062264 <-- wrong order
2023/04/14 23:25:03.113222072,1681507503 ...