[Documentation] [TitleIndex] [WordIndex

The ros::NodeHandle class serves two purposes. First, it provides RAII-style startup and shutdown of the internal node inside a roscpp program. Second, it provides an extra layer of namespace resolution that can make writing subcomponents easier.

Automatic Startup and Shutdown

As explained in the Initialization and Shutdown roscpp overview, ros::NodeHandle manages an internal reference count to make starting and shutting down a node as simple as:

   1 ros::NodeHandle nh;

On creation, if the internal node has not been started already, ros::NodeHandle will start the node. Once all ros::NodeHandle instances have been destroyed, the node will be automatically shutdown.


See also: ROS names documentation

NodeHandles let you specify a namespace to their constructor:

   1 ros::NodeHandle nh("my_namespace");

This makes any relative name used with that NodeHandle relative to <node_namespace>/my_namespace instead of just <node_namespace>.

You can also specify a parent NodeHandle and a namespace to append:

   1 ros::NodeHandle nh1("ns1");
   2 ros::NodeHandle nh2(nh1, "ns2");

This puts nh2 into the <node_namespace>/ns1/ns2 namespace.

Global Names

Private Names

2023-10-28 12:59