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

ROS NodeHandles : nh_ vs nh_priv_

asked 2021-06-28 05:07:37 -0600

electrophod gravatar image

1) What exactly is a Nodehandle? Why are they only in C++ and not in Python?

2) In many C++ header files of a ROS package (for example this one), I have seen people declaring 2 NodeHandles namely, nh_ and nh_priv_.

Why are there 2 NodeHandles in the same code and what does the underscore _ at the end of both the identifiers mean?

Would like to know about these in more detail, resources would be amazing to get.

Help is appreciated, TIA

edit retag flag offensive close merge delete



Probably not what you came here to hear, but could you list the Q&As you've already found on this site which discuss this topic? Personally I always use Google to search and append to my query.

There's a very good chance both of your questions have been discussed before, and we should try to a) avoid duplicates and b) avoid repeating discussions.

By listing existing Q&As in your own question, you can help us help you.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-28 05:38:42 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-06-28 06:34:15 -0600

pvl gravatar image

updated 2021-06-28 06:35:28 -0600

  1. A nodehandle is a RAII (resource acquisition is initialization) type according to - NodeHandles. RAII is a C++ term meaning that resources are cleanup up afterwards when the object goes out of scope. In rospy the nodehandle-like class is the rospy module itself. Both solutions seems more idiomatic to their languages, but that is a guess on my part.
  2. Private node handles are a way to access names private to the ROS node, which would create ambiguous names in some situations otherwise. They are a nodehandle to a different namespace. - AccessingPrivateNamesWithNodeHandle. I have not used them myself.
  3. underscores at the end of a member variable are a C++ convention. As with all C++ things, this is not universal and will differ in different organisations.
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2021-06-28 05:07:37 -0600

Seen: 319 times

Last updated: Jun 28 '21