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

why does subscriber not automatically subscribe to a topic when publisher suddenly starts publishing?

asked 2014-08-06 13:53:31 -0500

Ashesh Goswami gravatar image

Hi all,

I am having a basic issue with publishing and subscribing to topics. Before I get into the core of the problem, I would like to ask a very simple question with respect to the "beginner_tutorial" package. In this package, there exists the "talker" and the "listener" nodes. When I run the talker node followed by the listener node, the listener subscribes to the topic published by the talker. However, if I run the listener node first it does not subscribe (which is correct as talker is not publishing). But why does it not start subscribing as soon as I run the talker node after a while? Basically, why does the subscriber automatically not understand when the talker starts publishing and latch on to it if I first run the subscriber followed by the publisher node? Thanks a lot.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2014-08-06 14:19:23 -0500

ahendrix gravatar image

When a new publisher becomes active:

  1. It informs the ROS master.
  2. The ROS master sends a callback to all of the nodes that are subscribed to that topic, informing them that there is a new publisher, and giving its address.
  3. The subscribers then use this address to open a new connection directly to the publisher so that they can receive messages.
  4. messages are then passed over this TCP socket from publisher to subscriber

All of the steps in this process take a nonzero amount of time. The end result is usually that the first one or two messages sent by the publisher are not seen by subscribers.

This process can also fail if the master cannot contact the subscriber for some reason (for example, it can't resolve the hostname that the subscriber is running on), or if the subscriber cannot contact the publisher for some reason (again, hostname resolution is often the problem here).

edit flag offensive delete link more

Comments

I see..so does that mean that the publisher needs to be publishing for the subscriber to subscribe to the topic being published by the publisher? In other words, the talker node needs to be running and publishing before I can run the listener node? thanks a lot

Ashesh Goswami gravatar image Ashesh Goswami  ( 2014-08-06 14:42:03 -0500 )edit

No. You can start the publisher and the subscriber in any order.

ahendrix gravatar image ahendrix  ( 2014-08-06 14:59:13 -0500 )edit

but thats the problem I am facing. If I start the talker first it works but if I start the talker(publisher) after the subscriber node, it does not. I am trying this with the default beginner_tutorial package. What do you think might be the issue? thanks

Ashesh Goswami gravatar image Ashesh Goswami  ( 2014-08-06 15:05:24 -0500 )edit
1

"This process can also fail if the master cannot contact the subscriber for some reason (for example, it can't resolve the hostname that the subscriber is running on), or if the subscriber cannot contact the publisher for some reason (again, hostname resolution is often the problem here)."

ahendrix gravatar image ahendrix  ( 2014-08-06 15:56:50 -0500 )edit

my bad I missed that part earlier..thanks!!

Ashesh Goswami gravatar image Ashesh Goswami  ( 2014-08-06 16:16:05 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-06 13:53:31 -0500

Seen: 2,812 times

Last updated: Aug 06 '14