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

When is private nodehandle useful

asked 2014-09-08 13:27:18 -0600

Andromeda gravatar image

updated 2021-04-21 17:31:35 -0600

130s gravatar image

Looking into many codes and programs I see not rarely some nodes which are called toghether with a private name. For istance:

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

finding out this tutorial I read that:

  // Use a private node handle so that multiple instances of the node can
  // be run simultaneously while using different parameters.
  // Parameters defined in the .cfg file do not need to be initialized here
  // as the dynamic_reconfigure::Server does this for you.

ya ok, but I would ask now: Why?!?

In which case should I need to run simultaneously many istances of the same node? Is the risiko, that some nodes publishing on the some topics create a lot of confusion running the main prog, too big?

Since im trying to write more complicated drivers for my robot and I look into the coe of other users, I see that private nodes are normal.

Regards

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-09-11 00:59:25 -0600

Andromeda gravatar image

Many many Thanks! It helped me to understand much better how it works. The explanation of Sebastian was very clear about that. Here a link where I found some precious informations.

Regards

edit flag offensive delete link more
6

answered 2014-09-08 18:50:04 -0600

One example is when you have multiple nodes that have the same parameter (e.g. "frequency"). How do you set each node's parameter to be different?

In a launch file, when you do

<node pkg="some_package" type="some_executable" name="some_name" >
    <param name="param_name" value="some_value" />
</node>

the parameter gets resolved to /some-name/param_name.

In order to access the param_name without worrying about the node name you need to use

ros::NodeHandle nh_private("~");
std::string param;
nh_private.getParam("param_name", param);

otherwise you won't be able to get the parameter.

Hope it helps.

edit flag offensive delete link more
2

answered 2014-09-09 01:53:21 -0600

Sebastian Kasperski gravatar image

Also, you don't create many instances of the node, only different node handles. You can create node handles as you wish and your node will continue to exist until the last node handle gets out of scope.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-08 13:27:18 -0600

Seen: 1,332 times

Last updated: Apr 21 '21