Ask Your Question

ROS subscriber/publisher communication

asked 2015-01-27 17:44:58 -0500

Anton Belev gravatar image

These slides introducing ROS subscribers/publishers on slide 7 are saying that one topic can have multiple subscribers/publishers. If you scroll down a bit in the official tutorials here you can see the actual protocol for establishing connection between single subscriber and publisher. My question is, in case you have multiple publishers to a single topic, how does the communication changes in order to handle these publishers? Does one publisher blocks until the subscriber is ready to process more messages? Are the process messages handled using a queue? How is the second connection established? What if there are many-to-many relationship between the subscribers/publishers? Are the subscriber just removing msg-s from a queue and publishers pushing msgs on the queue? Can this queue overflow (if there is a queue at all)?

More in depth documentation of the subscriber/publisher architecture is acceptable as an answer. Also if you know the answer of some of the questions it will be helpful as well.

Thank you, much appreciated!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-28 06:45:19 -0500

Erwan R. gravatar image


As far as I know, there is no publication on a topic if no node has subscribed to it. When there is at least one, message are published depending on the rate of publishing node.

If there are two nodes publishing on the same topic, messages will come one after the other in a non-predictable order. The subscriber will get these messages as they come. It may be conflicting (if you have a movement control node and the teleop node publishing speeds to the low-level controller, your robot may move strangely).

About queues :

ros::Subscriber subscribe(const std::string& topic, uint32_t queue_size, <callback>, const ros::TransportHints& transport_hints = ros::TransportHints());

the queue_size argument tells the node how many messages it should keep before erasing the oldest one. A value of 1 will keep the last message received. I guess that all subscribers having a queue_size on 1 means that you have at most "Nb of Callbacks" messages to process when spinningOnce.

So for you two last questions : subscribing nodes handle their own callbackQueue that is being processed when spinning. It can overflow if publishers are faster that subscribers and callback processing.

I let someone more used to the precise mechanisms of ROS give more details.

edit flag offensive delete link more


Thank you! That's helpful.

Anton Belev gravatar image Anton Belev  ( 2015-01-28 14:26:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-01-27 17:44:58 -0500

Seen: 1,007 times

Last updated: Jan 28 '15