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

Order / time stamps of messages in ros2bag

asked 2023-04-14 16:52:18 -0500

holunder gravatar image

updated 2023-04-14 23:33:24 -0500

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 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-04-15 07:44:36 -0500

Mike Scheutzow gravatar image

updated 2023-04-15 07:49:29 -0500

2023/04/14 23:25:03.13150167,1681507503.0121276 <-- wrong order 2023/04/14 23:25:03.63157445,1681507503.062264 <-- wrong order

That "time" field for a rosbag is the arrival time-of-day at the rosbag node subscriber. These lines I quoted were delayed by the network (possibly lost and retransmitted): the first by 119 milliseconds and the 2nd by 570 milliseconds. This would be obvious if you'd sorted by the first column.

Yes, my advice is use some "source timestamp" for sensor messages if it is possible. Most networks are going to have jitter & retransmissions, so using "arrival timestamp" can really mess with the data quality.

edit flag offensive delete link more

Comments

Thanks a lot for your explanation. I'll consider adding an additional element in each (custom) message and set the time just before publishing.

Do you have any further information why I see these re-transmission? It's just a local ros system (in wsl2) without any wired network communication. Is it worth to invest more time in playing around with qos settings?

holunder gravatar image holunder  ( 2023-04-15 09:37:32 -0500 )edit

I don't do development on MS Windows, but I would think it is impossible to get those results over localhost. To me, the most likely explanation is that those packets actually traveled out of your computer, then were sent back to it.

Is it worth to invest more time in playing around with qos settings?

If you want to build a good system, it's vital to understand the characteristics of the connections your ros nodes are using.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-04-15 10:29:06 -0500 )edit

Concerning Windows: I've ran the same test on an embedded device running Ubuntu 20.04 and found exactly the same behaviour. No further network connection apart from myself using ssh to work on the device.

holunder gravatar image holunder  ( 2023-04-16 23:53:17 -0500 )edit

Concerning this:

If you want to build a good system, it's vital to understand the characteristics of the connections your ros nodes are using.

Do you have any good starting point to look into this? I found no holistic description to start with.

holunder gravatar image holunder  ( 2023-04-17 03:27:26 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2023-04-14 16:52:18 -0500

Seen: 721 times

Last updated: Apr 15 '23