Ask Your Question

getParam question

asked 2017-10-19 16:13:26 -0500

rnunziata gravatar image

I seem to be unable to gain access to params passed to node....I want to read them from a callback.

 <node name="xxxx" pkg="xxxx" type="RGBD" clear_params="true" output="screen">
    <remap from="/camera/rgb/image_raw"              to="$(arg bag_image_topic)"/>  
    <remap from="/camera/depth_registered/image_raw" to="$(arg bag_depth_topic)"/> 
    <param name="base_frame"    value="$(arg pose_base_frame)"/>
    <param name="camera_frame"  value="$(arg bag_camera_frame)"/>                       

in the code I have in my call back which is inside a c++ ros node.

std::string camera_frame = "notgiven";
std::string base_frame   = "notgiven";
ros::param::get("base_frame",  camera_frame);
ros::param::get("camera_frame", base_frame);

The variables are always set to "notgiven" .... How do I get access ?

edit retag flag offensive close merge delete


ros::param::get("xxxx/base_frame", camera_frame); ros::param::get("xxxx/camera_frame", base_frame);

BhanuKiran.Chaluvadi gravatar image BhanuKiran.Chaluvadi  ( 2017-10-19 16:51:19 -0500 )edit

That would work, but it isn't all that robust. If the node name changes, the parameter names will change also and the code would have to be changed or the parameter names would have to be remapped.

jarvisschultz gravatar image jarvisschultz  ( 2017-10-19 17:02:29 -0500 )edit

Accessing as a private parameter will automatically resolve to the right node name.

jarvisschultz gravatar image jarvisschultz  ( 2017-10-19 17:03:08 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-19 17:00:22 -0500

updated 2017-10-19 17:00:52 -0500

Since you are placing the parameters inside of the node tag in your launch file, they are set to be "private parameters". All this really means is that the node's name is appended to the front of the globally resolved parameter name. So in this case (I can't see you whole launch file, so I'm guessing a bit), the global name for one of the params would be /xxxx/base_frame). When retrieving that parameter from the parameter server, you'd want to either use ros::param::get("~base_frame", camera_frame); (notice the tilde) or a private ros::NodeHandle.

Read more on the roscpp Accessing Private Parameters page or the Names page

edit flag offensive delete link more


that worked....thank you

rnunziata gravatar image rnunziata  ( 2017-10-19 19:27:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-10-19 16:13:26 -0500

Seen: 2,902 times

Last updated: Oct 19 '17