Robotics StackExchange | Archived questions

retrieve ros param in launch file

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?

Asked by Wolf on 2015-06-03 01:48:00 UTC

Comments

Answers

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:

<launch>
  <arg name="foo" default="42"/>
  <param name="foo" value="$(arg foo)"/>
</launch>

Asked by ahendrix on 2015-06-03 02:46:43 UTC

Comments

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.

Asked by Wolf on 2015-06-03 05:20:49 UTC

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

Asked by Wolf on 2015-06-03 05:21:49 UTC

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?

Asked by Jasmin on 2019-01-30 05:13:03 UTC

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.

Asked by Jasmin on 2019-01-30 05:51:38 UTC