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

Figuring out the power of a YAML file.

asked 2014-01-29 06:15:08 -0500

RB gravatar image

updated 2014-01-29 17:59:20 -0500

ahendrix gravatar image

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 ( ). Which look like below:


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



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?

Thanks in advances for your valuable suggestions...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-01-29 18:18:48 -0500

ahendrix gravatar image

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.

edit flag offensive delete link more


@ahendrix, thanks for your comment. I am wondering why nodlet ( is required for implementing mux.yaml? I have seen here (; 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

RB gravatar image RB  ( 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.

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

answered 2014-01-29 22:41:36 -0500

bchr gravatar image

updated 2014-01-30 00:20:29 -0500

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:

   - priority: &priority1 7
   - priority: &priority2 4

subscribers: - name: "Teleoperation" topic: "input/teleop" timeout: 1.0 priority: *priority1 - name: "Autonomouse Navigation" 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),
        generate_subscriber("Autonomous Navigation", "input/move_base", 2.0, 4)

with open('data.yaml', 'w') as outfile:
    outfile.write(yaml.safe_dump(data, default_flow_style=False))
edit flag offensive delete link 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.

RB gravatar image RB  ( 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.

bchr gravatar image bchr  ( 2014-01-30 00:00:53 -0500 )edit

Question Tools



Asked: 2014-01-29 06:15:08 -0500

Seen: 1,857 times

Last updated: Jan 30 '14