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

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

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

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:

<launch>
    <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)"/>
    </node>
</launch>

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
0

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

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"/>

<node                                                                                            
    pkg="my_pkg"                                                                    
    name="add_to_param_server"                                            
    type="add_to_param_server.py"                                                                      
    args="$(value)"                                                         
    output="screen"                                                                              
/>

</launch>

add_to_param_server.py example:

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

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

except rospy.ROSInterruptException:
    pass

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

Comments

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 -0600 )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.

Best,

lsrosa gravatar image lsrosa  ( 2022-03-11 08:13:45 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2020-09-15 03:01:58 -0600

Seen: 1,823 times

Last updated: Mar 11 '22