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

Two messages with the same sequence number

asked 2017-05-05 18:37:17 -0500

nbro gravatar image

I have a bag file with a lot of messages on different topics. I've just found out that I have two messages with the same sequence number, but they were published to different topics. I thought that every message sent over ROS had a unique sequence number in the system, but, apparently, this isn't true.

What exactly is the sequence number used for? In which circumstances can we have two (or more) messages with the same sequence number?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-05-06 04:02:46 -0500

gvdhoorn gravatar image

updated 2017-05-06 04:09:59 -0500

What exactly is the sequence number used for?

It's somewhat of a 'relic' from the earlier versions of ROS. The idea was that it could be useful to be able to correlate messages to each other, or deal with out-of-order delivery over transports that do not guarantee in-order delivery.

That never really got used (afaik), and on multiple occasions proposals to remove seq from Header have been put forth -- ROS 2 RFC: Remove seq from Header.msg on the ros-sig-ng-ros list being one of the more recent ones. That posting by @William also explains some of the shortcomings of seq, and might also answer some of your other questions about it.

In which circumstances can we have two (or more) messages with the same sequence number?

There is no guarantee whatsoever that seq is unique, in any way. From the posting linked earlier:

[..] in ROS 1, the seq field is sometimes set by the middleware, but inconsistently not set in other cases. For example, it is set when publishing, but not when sending a Service Request. Also, some client libraries don’t set the seq field on publish [..]

and:

[..] seq is specific to a single publishing source, or topic depending on the middleware's behavior [..]

Uniqueness guarantees would also be really hard to implement robustly. Imagine a highly distributed system with 100+ hosts with tens of nodes of each. seq is a simple uint32, so setting up some oracle that can reliably generate unique nrs would be almost impossible due to the limited width of the integer and because of the necessity to somehow keep track of nrs already used across all involved graph participants.

So there can be many situations in which multiple msgs have identical sequence nrs. Most commonly it can occur if publishers (or the underlying client library) don't initialise seq at all (it stays 0). In other cases seq could be set by the caller, who could happen to have started counting at the same nr (say 0) as some other publishing entity in your node graph. This would also lead to the possibility of receiving different msgs with identical seq values.

In conclusion: no, seq is not required nor guaranteed to be unique - not even within a single process - and you should not rely on it being unique. It's only still there because of its history and for reasons of backwards compatibility. It probably won't be maintained as part of a Header (or equivalent structure) in ROS2 and if we could, it would've been removed from ROS1 a long time ago already.


Edit: found some related discussion: Is the sequence number in Header message deprecated on ROS Discourse. The linked ros2/common_interfaces#1 on Github is also interesting, especially this comment.

edit flag offensive delete link more

Comments

Why isn't this fact about the deprecation of seq explicitly and very clearly written in the documentation: http://docs.ros.org/kinetic/api/std_m... ?

nbro gravatar image nbro  ( 2017-05-06 06:43:57 -0500 )edit

Honestly? I guess things change, are repurposed / updated over time and it only takes one person not doing their job in such a federated development model. This is going to sound a bit like a cliche, but a PR against ros/std_msgs would be certainly be appreciated.

gvdhoorn gravatar image gvdhoorn  ( 2017-05-06 08:30:55 -0500 )edit

Also: I'm not sure the field itself is deprecated. It's more the fact that users should not assume that it's unique or consistently used everywhere. But I guess that's about the same.

I'm not a core developer, so all of this is assumptions and extrapolation on my part.

gvdhoorn gravatar image gvdhoorn  ( 2017-05-06 08:37:57 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-05 18:37:17 -0500

Seen: 1,283 times

Last updated: May 06 '17