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

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

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

MahShah gravatar image

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

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

Comments

1

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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

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

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

Comments

Thank you!

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

Question Tools

3 followers

Stats

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

Seen: 2,079 times

Last updated: Nov 21 '18