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

retrieve ros param in launch file

asked 2015-06-03 01:48:00 -0600

Wolf gravatar image

I would like to set a parameter in a launch file but only if the respective parameter is not yet set. (The parameter value I would like to set in the launch file is kind of default but maybe the user has already set it to something smarter before the launch so i do not want to override the user value.) Is that possible? Or is it possible to retrieve a ros param inside a launch file in order of checking if it exists?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-06-03 02:46:43 -0600

ahendrix gravatar image

The roslaunch xml syntax doesn't have any concept of reading from or executing conditionally based on existing ROS parameters.

Is there any reason you can't use a default value in your node, when reading this parameter from the parameter server?

If you want to have a launch file that sets a user-supplied value for a parameter or uses a sane default, you could use arguments with default values:

  <arg name="foo" default="42"/>
  <param name="foo" value="$(arg foo)"/>
edit flag offensive delete link more


I want to distinguish between a "whatever default", which is set in the node (where I do not now the application), if param not present, and an application specific default which overrides "whatever default" and is set in launch file (where application is known) and allow the user to override both.

Wolf gravatar image Wolf  ( 2015-06-03 05:20:49 -0600 )edit

Any Ideas on that? But, the command arg suggestion seems to be a workaround! Thank you for the reply!

Wolf gravatar image Wolf  ( 2015-06-03 05:21:49 -0600 )edit

I some how need the same thing but I thought of something else, we could prepare a simple bash script where we run rosparam get /my_param to get the parameter value and set the input argument to it if it is already set or else it will just use the default value. Is this coherent with ROS?

Jasmin gravatar image Jasmin  ( 2019-01-30 04:13:03 -0600 )edit

Or we could just run roslaunch foo.launch foo:=$(rosparam get /foo) , this will work if we have a running roscore and the parameter /foo already set.

Jasmin gravatar image Jasmin  ( 2019-01-30 04:51:38 -0600 )edit

Question Tools



Asked: 2015-06-03 01:48:00 -0600

Seen: 2,098 times

Last updated: Jun 03 '15