Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ROS between message delta time

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.