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

ROS NodeHandles : nh_ vs nh_priv_

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

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

Comments

3

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 site:answers.ros.org 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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

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

pvl gravatar image

updated 2021-06-28 06:35:28 -0500

  1. A nodehandle is a RAII (resource acquisition is initialization) type according to ros.org - 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. ros.org - 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

Stats

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

Seen: 356 times

Last updated: Jun 28 '21