[ros-users] problems receiving messages

Wim Meeussen meeussen at willowgarage.com
Tue May 3 16:57:38 UTC 2011


I am having some problems receiving messages.
> The idea is to implement an EKF using data from odometry, gps, laser scan
> and row detection.
> These messages are recorded in bags, with frequencies of 45, 95, 75 and 15
> Hz, respectively.
> The first strange thing noticed is that, using subscribers queue size = 1
> and spinOnce() with loop_rate.sleep() of 1 KHz, I am missing about 50% of
> the messages recorded in the bags. It is strange, because the total
> frequency of the messages in the bags is 230 Hz, and the code is running at
> 1 KHz.

When you care about receiving all the messages sent to a topic, you should
always use a buffer size > 1.   If you only care about the last message
received, a buffer size of 1 is great.  In your testcase, even when you set
the desired rate to 1kHz, there is no guarantee that your buffer won't fill
up and drop messages. Your average rate could reach 1 kHz, but the actual
times when your buffer is serviced can vary greatly.

> After it, I started to receive all the messages. But looking to the screen,
> it is possible to see that the different type messages are arriving out of
> time order. ROS processes the entire queue of one message type before
> starting to process the others. This could be the reason for receiving
> messages in wrong order. But even looking to the first message of each block
> type, the time stamps are still out of order.

 I tried different things, like spin() with multi threads and the
> approximate time message filter, and I am still receiving the messages out
> of order. My last try was to store all the messages in a single bag, and run
> the code in http://www.ros.org/wiki/rosbag/Cookbook to order the messages
> in the bag to match the timestamps. The results got much better, but I am
> still receiving some messages out of time order.
> Is ROS supposed to work like this? Do you have any suggestion to solve
> these problems?

Yes, this is the way ROS works. When you receive messages from different
sources, there is no guarantee in which order you will receive/process them.
I do believe though that messages from a single source should arrive in
order.  Is that not the case?

The robot_pose_ekf package solves a problem very similar to the one you're
trying to solve.  In the robot pose ekf we use an internal buffer to store
incoming messages from different sources.  The buffer temporary stores
messages while you're waiting until you received a message from all your
sources up to a certain timestamp. The robot pose ekf uses a tf Transformer
as its buffer. First of all the Transformer nicely deals with keeping a
fixed time history, but more importantly the Transformer also takes care of
interpolation between data with different timestamps.  When running an EKF,
you probably want data from all your sources at one and the same timestamp,
but all sources have their own timestamps and are not synchronized. So
you'll need some kind of interpolation. To use the Transformer, you'll have
to convert all your data to 6D Poses though.

Hope this helps,


Wim Meeussen
Willow Garage Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20110503/c0cf6c38/attachment-0002.html>

More information about the ros-users mailing list