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

roscpp relative parameter

asked 2011-09-01 23:13:32 -0500

andreas gravatar image


I somehow can't manage to get or search relative parameter names. What I do is, I launch a launch file which sets parameters.

  <node pkg="test" type="test_node" name="test_node"> 
    <param name="testparameter" value="a" />
    <param name="show_windows" value="true" />
    <rosparam file="$(find test)/config/params.yaml" command="load"/>

This all works, I can get and set parameters using rosparam via the shell. They are published over e.g. /test_node/orientations, /test_node/kernels/kernel_1/wavelength, /test_node/kernels/kernel_2/wavelength and so on. Now within the test node I want to read those parameter. But when I try

nh_.getParam("orientations", orientations_list);

The parameter won't be found, I have to explicitly name the whole global name "/test_node/orientations". I have the same issue with

nh_.searchParam("orientations", orientations_param_name);

Am I doing something wrong? Is there a way to get the current namespace the node is in as a workaround?

(I'm using Ubuntu 10.04.1, 64 bit with the standard ros diamondback package from the package manager)

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2011-09-02 00:10:39 -0500

dornhege gravatar image

To read parameters from the node's namespace create a private NodeHandle as:

NodeHandle nhPriv("~");

Use this nodehandle to access the parameters and it will work. This is actually not a workaround but the preferred way to do it.

edit flag offensive delete link more

answered 2011-09-02 04:01:42 -0500

joq gravatar image

It seems there is some confusion here about the difference between "relative" names and "private" names. You defined private parameters, which must be resolved using the "~" node handle, as Dornhege described. See this wiki page for more details. Relative names can be resolved via the node's address space, but not private ones.

edit flag offensive delete link more

answered 2011-09-02 03:25:36 -0500

andreas gravatar image

Thanks, now it worked. I'm still a bit confused because in the tutorial

it says

ros::NodeHandle nh;
std::string global_name, relative_name, default_param;
if (nh.getParam("/global_name", global_name))

if (nh.getParam("relative_name", relative_name))

But nh.getParam("relative_name", relative_name) shouldn't work when the NodeHandle isn't private, right?

edit flag offensive delete link more



Yes I am confused too. When and Why would i use relative_name then ? And why does it even exist ? This tutorial says we can use relative name if we use the corresponding node handle

ROSfc gravatar image ROSfc  ( 2016-09-01 10:01:30 -0500 )edit

Question Tools


Asked: 2011-09-01 23:13:32 -0500

Seen: 3,181 times

Last updated: Sep 02 '11