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.
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.
Asked by mrrius on 2019-11-13 21:57:11 UTC
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 betweenlast_time_stamp
andcur_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
totrue
and then echo the topic/statistics
.Asked by Delb on 2019-11-14 05:10:45 UTC