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

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 -0500

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
1

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

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

1

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 image chanhyeoni  ( 2017-10-30 23:06:23 -0500 )edit

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

jayess gravatar image jayess  ( 2017-10-30 23:20:31 -0500 )edit
3

This really doesn't address the problem the OP is having.

Mehdi. gravatar image Mehdi.  ( 2021-02-11 10:10:29 -0500 )edit

Question Tools

3 followers

Stats

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

Seen: 4,366 times

Last updated: Oct 30 '17