I am trying to make a launch file which checks an argument value (string) and loads parameters accordingly. I don't seem to find any documentation regarding this, the if/unless attributes section in the roslaunch wiki only works with booleans. Here's what I'm trying to achieve:
<arg name="mode" default="mode_a"/> <!-- mode_a, mode_b, mode_c... -->
<node pkg="node" type="node_type" name="node_name" output="screen">
<rosparam command="load" file="$(find test)/config/mode_a_params.yaml" if="$(arg mode)"=="mode_a" />
<rosparam command="load" file="$(find test)/config/mode_d_params.yaml" unless="$(arg mode)"=="mode_b" />
</node>
But since if/unless work only with booleans, this is not possible. The following code shows my work-around. I made two new flag arguments (boolean), but the issue here is that I need to set the flags every time I change the mode.
<arg name="mode" default="mode_a"/> <!-- mode_a, mode_b, mode_c... -->
<arg name="mode_a_flag" default="true"/> <!-- set to true if mode = mode_a, else false -->
<arg name="mode_c_flag" default="false"/> <!-- set to true if mode = mode_c, else false -->
<node pkg="node" type="node_type" name="node_name" output="screen">
<rosparam command="load" file="$(find test)/config/mode_a_params.yaml" if="$(arg mode_a_flag)" />
<rosparam command="load" file="$(find test)/config/mode_d_params.yaml" unless="$(arg mode_c_flag)" />
</node>
Is there a better way of doing this? I'm looking for a way where I just need to set the mode when launching the file and the flags are set automatically in the launch file.
Originally posted by adityakamath on ROS Answers with karma: 30 on 2021-09-02
Post score: 0