Ask Your Question

retrieve ros param in launch file

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

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 -0500

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 imageWolf ( 2015-06-03 05:20:49 -0500 )edit

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

Wolf gravatar imageWolf ( 2015-06-03 05:21:49 -0500 )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 imageJasmin ( 2019-01-30 04:13:03 -0500 )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 imageJasmin ( 2019-01-30 04:51:38 -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



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

Seen: 365 times

Last updated: Jun 03 '15