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

How to use getNodeHandle ?

asked 2018-11-08 03:12:16 -0600

vinmean gravatar image

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();

edit retag flag offensive close merge delete


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

bpinaya gravatar image bpinaya  ( 2018-11-08 03:19:02 -0600 )edit

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.

Delb gravatar image Delb  ( 2018-11-08 04:10:00 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-11-08 04:42:07 -0600

Delb gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-11-08 03:12:16 -0600

Seen: 963 times

Last updated: Nov 08 '18