Robotics StackExchange | Archived questions

How to use getNodeHandle ?

I have a node which uses private node handle to advertise topics. I wanted to subscribe to a topic from another node. So I wanted to create another node handle instance. I tried to use getNodeHandle() but got the below error. Am I missing some include files? I have included nodelet/nodelet.h

error: ‘getNodeHandle’ was not declared in this scope ros::NodeHandle& nh = getNodeHandle();

Asked by vinmean on 2018-11-08 04:12:16 UTC

Comments

How did you declare it in your class? Try to post the more of the code if possible.

Asked by bpinaya on 2018-11-08 04:19:02 UTC

To use getNodeHandle you would have to actually use a nodelet (thus derive your class from the class nodelet, define an onInit() method etc...) which doesn't seem to be what you want.

Asked by Delb on 2018-11-08 05:10:00 UTC

Answers

I would recommend to read the NodeHandles wiki and the Names in ros.

If your first node define a nodehandle with a private namespace then if you want to have the same namespace in your second node you would have to define the nodehandle with the fully qualified name of the first one :

//In node A
ros::NodeHandle n("~"); //Consider the private namespace to be node_a
//In node B
ros::NodeHandle n("node_a");

You could also use a remapping in a launch file if you have one.

Asked by Delb on 2018-11-08 05:42:07 UTC

Comments