Private NodeHandlers and topics?

asked 2018-12-04 06:23:32 -0500

Hypomania gravatar image


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?

edit retag flag offensive close merge delete



I'm not sure I understand completely, but wouldn't creating a "private nodehandle" do this automatically?

gvdhoorn gravatar imagegvdhoorn ( 2018-12-04 09:17:17 -0500 )edit

@gvdhoorn, sorry, my node_b is from a different package. How can I subscribe to /node_a/navigation from node_b without entering Subscriber navigation = n.subscribe("node_a/navigation", 1000, navigationCallback);?To be more precise, is there a way of doing it without entering the absolute path?

Hypomania gravatar imageHypomania ( 2018-12-05 06:07:08 -0500 )edit

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 gravatar imagegvdhoorn ( 2018-12-05 06:25:29 -0500 )edit

@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)?

Hypomania gravatar imageHypomania ( 2018-12-05 07:12:16 -0500 )edit

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 gravatar imagegvdhoorn ( 2018-12-05 07:13:41 -0500 )edit

@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?

Hypomania gravatar imageHypomania ( 2018-12-05 07:15:07 -0500 )edit

@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!

Hypomania gravatar imageHypomania ( 2018-12-05 07:16:09 -0500 )edit

Or could I enter the absolute path of the topic in the Subscribers constructor?

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.

gvdhoorn gravatar imagegvdhoorn ( 2018-12-05 08:33:03 -0500 )edit