Ask Your Question
0

Is there a way to read from a text or yaml file and pass its data to <arg> tag?

asked 2017-10-30 16:28:24 -0600

chanhyeoni gravatar image

Just like rosparam that take yaml file as a parameter, I want to know if there is a way to read text or yaml file that contains parameters and pass the parameters to any attributes of the <arg> tag (e.g. value, default).

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-10-30 16:57:39 -0600

jayess gravatar image

As far as I'm aware, you can't use launch files to read individual parameters in yaml files and/or change them. You can, however, use an arg tag to specify a file path and pass the file name to the launch file. For example, let's call the following launch file launch1.launch:

<launch>
    <arg name="file_name" default="$(find my_package)/my_yaml.yaml"/>   
    <rosparam command="load" file="$(arg file_name)"/>
</launch>

Then you can include this launch file from other launch files and use the file_name arg to dynamically change what yaml file you're using. For example, let's call the following launch file launch2.launch:

<launch>
    <arg name="file_name" default="$(find my_package)/another_yaml.yaml"/>

    <include file="$(find my_package)/launch1.launch">
        <arg name="file_name" value="$(arg file_name)"/>
    </include>
</launch>

This would result in launch1.launch being used with the yaml file passed to it (another_yaml.yaml) instead of its default of my_yaml.yaml.

An alternative approach is to load the yam with out the parameters that you want to change during launch and set those as arguments. Here's launch3.launch:

<launch>
    <arg name="file_name" default="$(find my_package)/my_yaml.yaml"/>
    <arg name="param1" default="0"/>
    <arg name="param2" default="1"/>

    <rosparam command="load" file="$(arg file_name)" />
    <param name="param1" value="$(arg param1)"/>
    <param name="param2" value="$(arg param2)"/>
</launch>

A good way to get how this all works is to read other projects' launch files and to just experiment (oh, and read the launch file wiki entry too).

edit flag offensive delete link more

Comments

Thanks for your help. I actually need to find some way to make individual parameters be read from the yaml file and pass each as an argument to machine tags in the launch file. I appreciate your help!

chanhyeoni gravatar imagechanhyeoni ( 2017-10-30 23:06:23 -0600 )edit

What's the reason behind doing it that way? The way I'm describing is straightforward and pretty standard.

jayess gravatar imagejayess ( 2017-10-30 23:20:31 -0600 )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

1 follower

Stats

Asked: 2017-10-30 16:28:24 -0600

Seen: 1,666 times

Last updated: Oct 30 '17