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

Revision history [back]

click to hide/show revision 1
initial version

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. 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
- 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, AFAIK there is no equivalent to xacro in YAML. Also, anchors/references do not work across multiple files.

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. In your case, this could look like:

defines:
   - priority: &priority1 \&priority1 7
   - priority: &priority2 \&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, AFAIK there is no equivalent to xacro in YAML. Also, anchors/references do not work across multiple files.

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. In your case, this could look like:

defines:
   - priority: \&priority1 &priority1 7
   - priority: \&priority2 &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

(& is escaped for some reason)

You can check the result online. However, if you want to achieve a more complex behavior, AFAIK there is no equivalent to xacro in YAML. Also, anchors/references do not work across multiple files.

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. In your case, this could look like:

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

4

subscribers: - name: "Teleoperation" topic: "input/teleop" timeout: 1.0 priority: *priority1 - name: "Autonomouse Navigation" topic: "input/move_base" timeout: 2.0 priority: *priority2

(& is escaped to & for some reason)

You can check the result online. However, if you want to achieve a more complex behavior, AFAIK there is no equivalent to xacro in YAML. Also, anchors/references do not work across multiple files.

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. 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 - name: "Autonomouse Navigation" topic: "input/move_base" timeout: 2.0 priority: *priority2

(& is escaped to & for some reason)

You can check the result online. However, if you want to achieve a more complex behavior, AFAIK there is no equivalent to xacro in YAML. Also, anchors/references do not work across multiple files.

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. 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 - 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, AFAIK there is no equivalent to xacro in YAML. YAML, but you could generate YAML files with a Python script, it's quite simple. Also, anchors/references do not work across multiple files.

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. 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 - 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, AFAIK there is no equivalent to xacro in YAML, but you could generate YAML files with a Python script, it's quite simple. Also, anchors/references do not work across multiple files.

simple and you could use a modified version of this:

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.yml', 'w') as outfile:
    outfile.write(yaml.safe_dump(data, default_flow_style=False))

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

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.yml', open('data.yaml', 'w') as outfile:
    outfile.write(yaml.safe_dump(data, default_flow_style=False))

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