0
$\begingroup$

Rosanswers logo

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.


Originally posted by nlauzier on ROS Answers with karma: 37 on 2012-07-16

Post score: 2


Original comments

Comment by nlauzier on 2012-07-16:
By the way, I am using rospy.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by cagatay with karma: 1850 on 2012-07-16

This answer was ACCEPTED on the original site

Post score: 5


Original comments

Comment by nlauzier on 2012-07-16:
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.

Comment by nlauzier on 2012-07-16:
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.

Comment by dornhege on 2012-07-16:
In that case something is wrong. Verify that both nodes are running and connected. Do they have different names?

Comment by joq on 2012-07-16:
Running the same node twice deletes the first one from the ROS graph, so that behavior is correct and expected.

Comment by nlauzier on 2012-07-16:
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?

Comment by dornhege on 2012-07-16:
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.

Comment by dornhege on 2012-07-16:
If you need multiple nodes, use different names from launch or cmd line or make the names Anonymous.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.