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

Subscribing to a non-existing topic

asked 2012-07-16 03:01:48 -0600

nlauzier gravatar image

updated 2012-07-16 04:53:03 -0600

Hi,

Is it possible for a node to subscribe to a topic which doesn't exist yet? This would be useful if the node publishing on this topic has to be started after the listener.

To put this into context, I have three nodes (A, B, C) and two topics (T1 and T2). Node A publishes on T1. Node B subscribes to T1 and publishes on T2. Finally, Node C only subscribes on T2.

As I have experienced, I must run node A before node B as B will not be able to subscribe on T1 because it doesn't exist until some node publishes on it. The same happens for B and C and therefore I must run the nodes in the proper order (A then B then C). This is not a problem in my case, but if there was a third topic (T3) on which C would publish and A would listen, that would create a problem.

There must be a cleaner way to solve this problem but I haven't found one in ROS documentation yet. Any idea?

Thanks!


Update: reinitializing roscore solved the problem. I'm not sure what was the cause of the problem, though.

edit retag flag offensive close merge delete

Comments

By the way, I am using rospy.

nlauzier gravatar image nlauzier  ( 2012-07-16 04:34:26 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2012-07-16 03:05:22 -0600

cagatay gravatar image

yes you can subscribe to an unpublished topic but you may not retrieve any data in your callback till topic is published

edit flag offensive delete link more

Comments

You are right, if I run "rostopic list -v", I can see that the topic exists and that it has one subscriber. However, when I run the node publishing on that topic, the callback function of the listener is never called.

nlauzier gravatar image nlauzier  ( 2012-07-16 03:15:10 -0600 )edit

And if I run the same listener node twice (one before and one after the publisher is run), only the one run after the publisher will get its callback function called.

nlauzier gravatar image nlauzier  ( 2012-07-16 03:16:54 -0600 )edit

In that case something is wrong. Verify that both nodes are running and connected. Do they have different names?

dornhege gravatar image dornhege  ( 2012-07-16 04:07:21 -0600 )edit

Running the same node twice deletes the first one from the ROS graph, so that behavior is correct and expected.

joq gravatar image joq  ( 2012-07-16 04:35:38 -0600 )edit

ok, now I'm not sure why but restarting roscore solved my problem. Is it possible that modifying my code or node/topic names needs a reinitialisation of roscore?

nlauzier gravatar image nlauzier  ( 2012-07-16 04:51:44 -0600 )edit

It's possible that you left a connection open, then restarted roscore (which doesn't know about the old node still running) and then reconnected? Also refer to @joq's comment.

dornhege gravatar image dornhege  ( 2012-07-16 05:23:52 -0600 )edit

If you need multiple nodes, use different names from launch or cmd line or make the names Anonymous.

dornhege gravatar image dornhege  ( 2012-07-16 05:24:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-07-16 03:01:48 -0600

Seen: 3,708 times

Last updated: Jul 16 '12