# Figuring out the power of a YAML file.

I have no prior experience in writing a YAML file. I want to know something related to it's capability.

1. Suppose in move_base.launch file, I have written something which launch mux.yaml ( http://wiki.ros.org/yocs_cmd_vel_mux ). Which look like below:

START

subscribers:
- name:        "Teleoperation"
topic:       "input/teleop"
timeout:     1.0
priority:    7
topic:       "input/move_base"
timeout:     2.0
priority:    4


END

Scenario:1

Suppose,* I don't want explicit number in the priority field i.e 7/4* instead I need to load this value from a text file. So, I want priority to be a variable.

Scenario 2

Let's hope that above scenario is possible. Now suddenly the text file changes; which in turn changes the yaml file as well. Will ROS is able to catch the dynamic behavior of the yaml file and reflect the same?

Can you just tell me how to achieve above situations and any good reference for writing YAML files?

edit retag close merge delete

Sort by » oldest newest most voted

Background: YAML is a generic file format, and can be used to specify many, many things. In this particular context it's used to specify the configuration of the yocs_cmd_vel_mux nodelet, but be aware that you will see the YAML format used elsewhere for completely different things.

I will confine my answer specifically to using YAML to configure the yocs_cmd_vel_mux nodelet.

1) As far as I'm aware, you can't reference outside data from a YAML file. That said, a YAML file is a text file, so it's easy to modify.

2) The yocs_cmd_vel_mux node will not automatically pick up changes to the yaml file. It does have an interface through dynamic_reconfigure that can be used to load a new configuration file.

Further things to consider:

The yocs_cmd_vel_mux nodelet is a nodelet; this means that it needs to be run within a nodelet manager. It's usually run as part of the core Kobuki/Turtlebot2 launch, but if you're trying to use it on another robot, you'll need to learn a little about nodelets and how to run a nodelet manager in order to use it.

If you're trying to change the priorities of the input topics dynamically at run time in order to force a particular input, you're probably designing your system wrong. The purpose of a multiplexer like this is to prioritize and choose the input topic automatically; if you set the priorities correctly on startup, the mux should automatically choose whichever active topic has the highest priority.

If you're looking for a more generic mux that doesn't automatically do topic prioritization and switching, have a look at the topic_tools mux node.

more

@ahendrix, thanks for your comment. I am wondering why nodlet (http://wiki.ros.org/nodelet) is required for implementing mux.yaml? I have seen here (https://github.com/vicoslab/vicos_ros/blob/master/turtlebot_vicos/launch/includes/_mobile_base.launch); which use nodelet for mux.yaml. Since I am using P3AT robot with lms200 laser range finder; is it possible to achieve desired behavior of mux.yaml. As we all know that ROS autonomous module has limited chance of failure, then what is the point of setting timeout? How we know that mux.yaml has worked properly. Right now, after completing the goal set in RVIZ, I can opt for teleop without using mux.yaml. But problem arises when we try to go for teleop without completing the goal set in RVIZ

( 2014-01-31 06:28:39 -0500 )edit

YAML is a data description format and is not runnable; it merely defines the configuration for something else.

( 2014-01-31 08:54:43 -0500 )edit

Concerning YAML and variables (your Scenario 1), you can use anchors (&) and references (*). This makes modifying YAML files easier when the same data is used multiple times in the same YAML file (anchors/references do not work across multiple files). In your case, this could look like:

defines:
- priority: &priority1 7
- priority: &priority2 4 subscribers:
- name:        "Teleoperation"
topic:       "input/teleop"
timeout:     1.0
priority:    *priority1
topic:       "input/move_base"
timeout:     2.0
priority:    *priority2


You can check the result online. However, if you want to achieve a more complex behavior, there is no equivalent to xacro in YAML, but you could generate YAML files with a Python script, it's quite simple and you could use a modified version of this:

#!/usr/bin/env python2
import yaml

def generate_subscriber(s_name, s_topic, s_timeout, s_priority):
return dict(name = s_name,
topic = s_topic,
timeout = s_timeout,
priority = s_priority)

data = dict(
subscribers = tuple([
generate_subscriber("Teleoperation", "input/teleop", 1.0, 7),
])
)

with open('data.yaml', 'w') as outfile:
outfile.write(yaml.safe_dump(data, default_flow_style=False))

more

@bchr Thank you for the whole information. In the first answer @ahendrix mention that YAML file can't access the outside data. The yaml file you have written gives the priority in the yaml file itself. Based on your info I think its better to write python script which access external text file (for priorities) and creates a yaml file.

( 2014-01-29 23:53:49 -0500 )edit

@Brian Smith: this is what I would do, since conversions between YAML and Python are really straightforward.

( 2014-01-30 00:00:53 -0500 )edit