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

Revision history [back]

click to hide/show revision 1
initial version
<node name="receiver" pkg="my_package" type="receiver" output="screen">
  <param name="host" value="$(arg host)" />
  <param name="port" value="$(arg port)" />
  <param name="timeout" value="$(arg timeout)" />
</node>

Here, you're setting host, port and timeout as private parameters of the receiver node.

But here:

ros::NodeHandle nh;
[..]
nh.getParam("host", host);
nh.getParam("port", port);
nh.getParam("timeout", timeout);

You're trying to access those parameters as if they're "public" (ie: exist in some other namespace than the nodes).

That won't work.

// the following doesn't work. However when relative is
// used, i.e. ros::NodeHandle nh("~") it works!

And that makes sense, as ~ has a special meaning as a namespace name (which is what the first argument in that particular ros::NodeHandle ctor is): it refers to the private namespace of the node in which the NodeHandle is created.

So now you're reading private parameters from the private namespace. And that succeeds.

<node name="receiver" pkg="my_package" type="receiver" output="screen">
  <param name="host" value="$(arg host)" />
  <param name="port" value="$(arg port)" />
  <param name="timeout" value="$(arg timeout)" />
</node>

Here, you're setting host, port and timeout as private parameters of the receiver node.

But here:

ros::NodeHandle nh;
[..]
nh.getParam("host", host);
nh.getParam("port", port);
nh.getParam("timeout", timeout);

You're trying to access those parameters as if they're "public" (ie: exist in some other namespace than the nodes).node's namespace).

That won't work.

// the following doesn't work. However when relative is
// used, i.e. ros::NodeHandle nh("~") it works!

And that makes sense, as ~ has a special meaning as a namespace name (which is what the first argument in that particular ros::NodeHandle ctor is): it refers to the private namespace of the node in which the NodeHandle is created.

So now you're reading private parameters from the private namespace. And that succeeds.

<node name="receiver" pkg="my_package" type="receiver" output="screen">
  <param name="host" value="$(arg host)" />
  <param name="port" value="$(arg port)" />
  <param name="timeout" value="$(arg timeout)" />
</node>

Here, you're setting host, port and timeout as private parameters of the receiver node.

But here:

ros::NodeHandle nh;
[..]
nh.getParam("host", host);
nh.getParam("port", port);
nh.getParam("timeout", timeout);

You're trying to access those parameters as if they're "public" (ie: exist in some other namespace than the node's namespace).

That won't work.

// the following doesn't work. However when relative is
// used, i.e. ros::NodeHandle nh("~") it works!

And that makes sense, as ~ has a special meaning as a namespace name (which is what the first argument in that particular ros::NodeHandle ctor is): it refers to the private namespace of the node in which the NodeHandle is created.

So now you're reading private parameters from the private namespace. And that succeeds.

See also wiki/Parameter Server.