Ask Your Question

ros launch get param in launch file to append to param from config file

asked 2020-09-15 03:01:58 -0500

noob_ros gravatar image

Using a common configuration file (not to be modified) - package_config.yaml:

param0: param0_value
param1: param1_value

Is it possible to append and override certain params only through the launch file? For example:

    <arg name="ns" value="namespace0"/>
    <node name="node_name" pkg="package" type="package_node" clear_params="true">
      <rosparam command="load" file="$(find package)/cfg/package_config.yaml"/>
      <param name="param0" value="$(arg ns)$(param param0)"/>

I know that param overriding from the launch file is allowed (calling <param name="param0" value="override_value"/> after loading params from yaml file <rosparam command="load" file="$(find package)/cfg/package_config.yaml"/>). But (for some reason that is beyond me) there is no way to access params (e.g. $(param param0)) in the param server from a launch file. Is there any way to append to existing params from a launch file?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-03-11 06:56:26 -0500

lsrosa gravatar image

The .xml launch files do not support reading from the ROS parameter server.

You can go around this limitation by creating a simple python script which reads from the parameter server, concatenates the value, and then stores the concatenated value back to the parameter server. Then you can call this script from your .launch files passing the .xml arguments to the python function.

my_launch.launch file example: <launch>
<arg name="value"/>


</launch> example:

import rospy, sys
if __name__ == '__main__':
    value = rospy.myargv(argv=sys.argv)[-1]
    var = '/thing_to_append'

    if not rospy.has_param(var):
        rospy.set_param(var, [value])
        rospy.set_param(var, rospy.get_param(var) + [value])

except rospy.ROSInterruptException:

Then you can just roslaunch my_launch.launch value=:<something>. You can add another arg to select the variable in the ROS parameter server you want to append to.

edit flag offensive delete link more


This has been discussed before: parameters are written before nodes are started. And this is for good reason: it keeps everything consistent (ie: all parameters defined in .launch files are present on the parameters server, so all nodes see the same values).

The approach you suggest cannot guarantee that all nodes see the same parameters, as your script will likely have been started after a couple other nodes have already been running, and before a few others.

There is no way to do what the OP asks.

Edit: re-reading the OP's request, there might actually be a way -- although it won't be 'overriding' anything.

rosparam supports the subst_value attribute, which makes roslaunch accept substitution args in the .yaml. If the values he wants to override can be passed as roslaunchargs, he could 'read' those using substitution args.

gvdhoorn gravatar image gvdhoorn  ( 2022-03-11 07:01:16 -0500 )edit

You are right, the approach I proposed does not append the value prior to the starting of the nodes. But it works if you are launching a second file. So it might be useful.

I did not find an way to use subst_value that allow me to read from the parameter server. Do you have an example? That would be really helpful.


lsrosa gravatar image lsrosa  ( 2022-03-11 08:13:45 -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: 2020-09-15 03:01:58 -0500

Seen: 420 times

Last updated: Mar 11