Rosanswers logo

How can I access roscpp parameters if the node name has been remapped with roslaunch?

launch file,

<node pkg="my_package" type="my_package_node" name="remapped_name" ns="my_namespace">
    <param name="camera_index" value="$(arg camera_index)" />

in cpp file,

ros::init(argc, argv, "node_default_name");
ros::NodeHandle n;
ros::param::get("node_default_name/camera_index", camera_index); // Fails
ros::param::get("remapped_name/camera_index", camera_index); // Works 

n.getParam("node_default_name/camera_index", camera_index); // Fails
n.getParam("remapped_name/camera_index", camera_index); // Works 

How can I get the parameters in the .cpp file without knowing the node name? Thanks

Originally posted by stebl on ROS Answers with karma: 45 on 2014-03-03

Post score: 2


1 Answer 1


Rosanswers logo

I think you should use the private namespace:

ros::param::get("~camera_index", camera_index);

ros::NodeHandle nh("~");
nh.getParam("camera_index", camera_index);

see http://wiki.ros.org/roscpp/Overview/Parameter%20Server

Originally posted by brice rebsamen with karma: 1001 on 2014-03-03

This answer was ACCEPTED on the original site

Post score: 4

Original comments

Comment by stebl on 2014-03-05:
Yep, worked for me, thanks! ros::NodeHandle nh("~"); nh.getParam("camera_index", camera_index);


Your Answer

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