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

roscpp parameters with roslaunch remapping

asked 2014-03-03 13:14:23 -0600

stebl gravatar image

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)" />
</node>

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2014-03-03 15:17:21 -0600

brice rebsamen gravatar image

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/P...

edit flag offensive delete link more

Comments

Yep, worked for me, thanks! ros::NodeHandle nh("~"); nh.getParam("camera_index", camera_index);

stebl gravatar image stebl  ( 2014-03-05 11:44:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-03-03 13:14:23 -0600

Seen: 2,742 times

Last updated: Mar 03 '14