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

How to set parameter for std::map structure in launch file

asked 2015-11-03 12:55:55 -0500

mikegao88 gravatar image

Hello! As described in the title, my question is how I could input the parameter for a std::map structure in a roslaunch file, which is needed by a node. I use ros-indigo. Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-11-03 15:54:42 -0500

Dimitri Schachmann gravatar image

updated 2015-11-03 15:57:32 -0500

I guess the question is rather how to get some configuration from a launch file into the nodes, that you go on to store that information in an std::map just an extra.

You most probably want to use the parameter server which is available to you per default when you run ROS.

You can store name-value pairs on the server in a launch file with the <param> tag then you can access it in your node as described in the documentation.. In Brief:

ros::param::param<std::string>("default_param", default_param, "default_value");

Note that the parameter names are global, but you can set private parameters per node by putting the tag inside the <node> tag:

   <node ...>
       <param name="foo" .../>
   </node>

Then you need to use "~foo" to access it.

PS: It is possible to store an entire map with a single name on the parameter server, but I know of no way to use that feature with launch files. You will need to specify a parameter for each map element.

PPS: Also note the convenient <rosparam> tag that allows:

<rosparam>
 my_parameter_1: 768
 my_parameter_2: 480
</rosparam>
edit flag offensive delete link more
0

answered 2015-11-04 05:12:43 -0500

mikegao88 gravatar image

updated 2015-11-04 06:28:13 -0500

gvdhoorn gravatar image

I figured it out, one can do it by using rosparam command in a ros launch file in this way:

<node pkg="xxx" name="yyy" type="ggg" output="screen">
  <!-- without "~" in front of the parameter name -->
  <rosparam param="name_map_structure">
     x: 1
     y: 2
     z: 3
  </rosparam>
</node>

Assume here that the private parameter name_map_structure is an instance of std::map<std::string, int>.

edit flag offensive delete link more

Comments

Isn't this exactly what @Dimitri Schachmann suggested?

gvdhoorn gravatar image gvdhoorn  ( 2015-11-04 06:28:48 -0500 )edit

Hi, this is his original answer. Later I figured it out by myself and posted the answer here. "PS: It is possible to store an entire map with a single name on the parameter server, but I know of no way to use that feature with launch files. You will need to specify a parameter for each map element."

mikegao88 gravatar image mikegao88  ( 2015-11-10 07:51:48 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-03 12:55:55 -0500

Seen: 2,145 times

Last updated: Nov 04 '15