0
$\begingroup$

Rosanswers logo

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


Originally posted by Andromeda on ROS Answers with karma: 893 on 2014-09-08

Post score: 1

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Gary Servin with karma: 962 on 2014-09-08

This answer was NOT ACCEPTED on the original site

Post score: 6

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by Sebastian Kasperski with karma: 1658 on 2014-09-09

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by Andromeda with karma: 893 on 2014-09-11

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.