Private NodeHandlers and topics?
Hi,
I am reading "ROS Best Practices" and it suggest to use private node handlers for output publishers. I am not sure how to implement that in code (C++).
For example, I have a publisher that belongs to a node "node_a" and advertise data on a topic called "navigation". This will create a topic called /node_a/navigation
.
That's all fine until now, however, let's assume I have a subscriber node called "node_b". At the moment I am "hardcoding" node_a's name into the Subscriber object: ros::Subscriber navigation = n.subscribe("node_a/navigation", 1000, navigationCallback);
.
Is there a different way of doing this? I know it can be done with remapping however is there a different way? Am I missing something?
I'm not sure I understand completely, but wouldn't creating a "private nodehandle" do this automatically?
@gvdhoorn, sorry, my node_b is from a different package. How can I subscribe to
/node_a/navigation
from node_b without enteringSubscriber navigation = n.subscribe("node_a/navigation", 1000, navigationCallback);?
To be more precise, is there a way of doing it without entering the absolute path?I still don't fully understand what you are trying to do or why, but your last question could be answered by "topic remapping".
@gvdhoorn, let me rephrase my question: I have two packages, one of them publishes a topic via a private NodeHandler. How does the other node subscribe to it without remapping (it uses a normal NodeHandler)?
Remapping is not done inside a node, it's a configuration-phase activity that is done either on the command line or in your launch file.
My answer would still be: remapping.
@gvdhoorn, thank you for that, is that the only way of doing it? Or could I enter the absolute path of the topic in the Subscribers constructor? Or is there anything else?
@gvdhoorn by the way if you answer the question with an answer I will give you "best answer" and and upvote, you are really helpful!
well, yes. But I would not do that: it would strongly couple your two nodes, which is not something you'd want to do.
It's perfectly OK to use short topic names, and leave (re)wiring to your users: they can remap.