πThe Robot Town Ledger

Table of contents
- π§Ύ Introduction: YAML Is Your Town's Ledger π
- π§© Anatomy of a ROS 2 YAML File
- π Example: ChefBotβs YAML Configuration
- π Launch Files with Parameters
- π± Multi-Bot Launch with YAMLs
- π€ Dynamic Tip: YAML + Command Line = Override
- π§ͺ Testing and Debugging
- π Recap: What Youβve Learned
- π§± Folder Structure Snapshot
- π‘ Bonus Ideas for Exploration
- YAML Cheatsheet for Robot Town ππ

π§Ύ Introduction: YAML Is Your Town's Ledger π
Imagine every bot in Robot Town has a personal diary in City Hall. Itβs neat, human-readable, and stores all settings like favorite food, alarm times, and security levels.
Thatβs what YAML files are in ROS 2 β clear, structured, and powerful.
And just like the Mayor gives out a Morning Bulletin to activate all bots, launch files let us load those settings at startup.
In this article, weβll:
Understand the YAML structure in ROS2
Create reusable config files
Pass them into launch files
Bonus: Launch multiple bots, each with their own config!
π§© Anatomy of a ROS 2 YAML File
A YAML file stores parameters per node.
Letβs say we have a bot named guard_bot
with a sensitivity level.
guard_bot:
ros__parameters:
alert_level: 5
watch_mode: "motion"
π§ Breakdown:
guard_bot
: This is the node's name.ros__parameters
: A magic key that tells ROS these are parameters.The inner keys like
alert_level
andwatch_mode
are the actual parameters used in your node code.
π Example: ChefBotβs YAML Configuration
In chef_bot/chef_bot/chef_config.yaml
:
chef_bot:
ros__parameters:
flavor: sweet
spice_level: 3
Then in your chef_
node.py
, you'd fetch these parameters like so:
self.flavor = self.get_parameter("flavor").get_parameter_value().string_value
self.spice = self.get_parameter("spice_level").get_parameter_value().integer_value
Run with:
ros2 run chef_bot chef_node --ros-args --params-file src/chef_bot/chef_bot/chef_config.yaml
π Launch Files with Parameters
Letβs build a launch file that powers on ChefBot with settings loaded from YAML.
π File: chef_bot/launch/chef_
launch.py
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='chef_bot',
executable='chef_node',
name='chef_bot',
parameters=['../chef_bot/chef_config.yaml']
)
])
Run with:
ros2 launch chef_bot chef_launch.py
π Make sure the relative path to chef_config.yaml
is correct or use os.path.join
for safer access.
π± Multi-Bot Launch with YAMLs
Letβs launch ChefBot and GuardBot, each with their own YAML:
1. YAML for GuardBot β guard_bot/guard_config.yaml
guard_bot:
ros__parameters:
alert_level: 7
watch_mode: "thermal"
2. Launch File β launch/all_bots_
launch.py
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='chef_bot',
executable='chef_node',
name='chef_bot',
parameters=['../chef_bot/chef_config.yaml']
),
Node(
package='guard_bot',
executable='guard_node',
name='guard_bot',
parameters=['../guard_bot/guard_config.yaml']
)
])
π Run all bots:
ros2 launch your_package all_bots_launch.py
Now both bots boot up, read their personality profiles from YAML, and run accordingly.
π€ Dynamic Tip: YAML + Command Line = Override
You can override a YAML setting live:
ros2 run chef_bot chef_node --ros-args \
--params-file src/chef_bot/chef_bot/chef_config.yaml \
-p flavor:=bitter
ROS2 will read the YAML but use bitter
for flavor
.
π§ͺ Testing and Debugging
β To check what parameters a node is using:
ros2 param list
ros2 param get /chef_bot flavor
β YAML Format Checker:
Use VS Code or online YAML linters to avoid indentation errors.
π Recap: What Youβve Learned
β YAML stores bot preferences in a clean, editable format.
β Launch files can pass YAML to bots for easy config.
β You can override YAML on the command line.
β Every bot in Robot Town can have a personal profile, loaded at start!
π§± Folder Structure Snapshot
robot_town_ws/
βββ src/
βββ chef_bot/
β βββ chef_bot/
β β βββ chef_node.py
β β βββ chef_config.yaml
β βββ launch/
β βββ chef_launch.py
βββ guard_bot/
β βββ guard_bot/
β β βββ guard_node.py
β β βββ guard_config.yaml
β βββ launch/
β βββ guard_launch.py
βββ launch/
βββ all_bots_launch.py
π‘ Bonus Ideas for Exploration
Create a Mood YAML for MayorBot with tone and message frequency
Use YAML to store DanceBotβs routine steps
Pass coordinates in YAML to NavigationBot
YAML Cheatsheet for Robot Town ππ
Basic Syntax
# Comments start with a hash
key: value # Key-value pair
Data Types
string: "Hello Robot Town" # Strings (quotes optional unless special chars)
integer: 42 # Integers
float: 3.14 # Floats
boolean_true: true # Booleans: true / false
boolean_false: false
null_value: null # Null / None
Collections
t# List (sequence)
bots:
- MayorBot
- TrafficBot
- GuardBot
# Inline list
colors: [red, green, blue]
# Dictionary (mapping)
robot:
name: GuardBot
role: Patrol
active: true
# Nested dictionary
launch:
nodes:
mayor:
name: mayor_bot
executable: mayor
door:
name: door_bot
executable: door
Indentation
Use spaces only (no tabs)
Consistent indentation (2 or 4 spaces)
Indentation shows hierarchy and nesting
Multiline Strings
description: |
This is a
multiline string
preserving line breaks.
note: >
This is a
multiline string
folded into one line.
Common YAML in ROS2 Launch Files
launch:
- node:
package: robot_package
executable: robot_node
name: robot1
output: screen
parameters:
- param1: value1
- param2: value2
remappings:
- from: /old_topic
to: /new_topic
π Whatβs Next: Practice Day β First ROS2 Simulation Day
Time for the big Robot Town festival! Next, your bots will practice their routines in a fun ROS2 simulation.
Watch DanceBot groove through moves, and learn to coordinate a group act using pub/sub messaging β the perfect team performance! π€ππΆ
Subscribe to my newsletter
Read articles from gayatri kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by