ROS between message delta time

asked 2019-11-13 20:57:11 -0500

mrrius gravatar image

Hello,

So, I have a really simple pub-sub process. The goal is simple too, to find the time between message sent by publisher.

In publisher, the data sent is in Odometry and the header stamp is set to rospy.Time.now()

In subscriber, I assigned this message to a variable named cur_pos and calculate this:

this->dt = (cur_pos->header.stamp.nsec - this->last_time_stamp) / 1000000000.0;
this->last_time_stamp = cur_pos->header.stamp.nsec;

In constructor, I assigned 0 as default value.

this->last_time_stamp = 0

This means that the first dt is the delta time between program is started and first message received. I print this data stream into a log file.

dt log file

The problem is, I got a really weird data. There are 3 things that I noticed.

First: There can be a past message where:

cur_pos->header.stamp.nsec < this->last_time_stamp

This means that probably ROS sent message unorderedat some pint or some failure to send and resend message.

Second: The dt calculation cannot be negative. Probably because using usigned int data type.

Third: Where long enough running this, the count seems restarted. Probably due to reaching maximum integer.

So my question is, are there any explanation to point no 1? Why there is a past package received? How to handle this?

Thank you.

edit retag flag offensive close merge delete

Comments

Have you set a rate in your test ? I would guess that you publish too fast so you exceed the queue_size, that would mean that your comparison between last_time_stamp and cur_pos->header.stamp isn't between the last published and last received messages but older messages from the queue. That could induce the data you get.

You could check if messages are actually dropped by setting the param enable_statistics to true and then echo the topic /statistics.

Delb gravatar image Delb  ( 2019-11-14 04:10:45 -0500 )edit