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

when and why do we use two or more ros::NodeHandle for one Node?

asked 2018-11-20 23:24:23 -0600

MahShah gravatar image

updated 2018-11-20 23:49:17 -0600

could you please explain when and why two or more ros::NodeHandle object are used in a program? could you please give some experimental example for these cases?

edit retag flag offensive close merge delete



You tagged this with ros2, but afaik ROS 2 doesn't (yet) have a NodeHandle?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-20 23:40:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-21 03:25:40 -0600

mgruhler gravatar image

Assuming you are using ROS1: The NodeHandles define how names are resolved in the ROS system. See the wiki for details.

One typical use case is the following:

Create a regular and a private NodeHandle:

ros::NodeHandle nh();
ros::NodeHandle pnh("~");

Topics, services, etc. typically use the regular NodeHandle nh. This ensures that topics etc. are always relative to the nodes namespace.

A private NodeHandle makes the nodes name part of the namespace. This is good for parameters, as they are typically tightly coupled to the node itself and thus having them private avoids collisions.

edit flag offensive delete link more


Thank you!

Rajendra gravatar image Rajendra  ( 2020-01-16 07:58:36 -0600 )edit

Question Tools



Asked: 2018-11-20 23:24:23 -0600

Seen: 1,910 times

Last updated: Nov 21 '18