Configuration and Launch
Your camera driver works perfectly — with a hardcoded resolution of 640×480, frame rate of 30fps, and exposure set to auto. But what if someone wants 1920×1080 at 60fps? Or a different camera model with different parameters?
Hardcoding configuration is brittle. Configuration files and launch systems make robot software adaptable and reusable.
Why Configuration Files?
Configuration files separate what your code does from how it's configured. This means:
- No recompilation — change camera resolution without rebuilding
- Environment-specific configs — different settings for sim vs. real robot
- Reusability — same code, different robots
- Version control — config changes are tracked like code changes
Your code loads this at runtime:
Always validate configuration! Use schema validation libraries (like jsonschema for Python, serde for Rust) to catch typos and invalid values early. A config file with frame_rate: "sixty" (string instead of int) should fail immediately, not crash your robot later.
YAML vs. TOML vs. JSON
Different robotics ecosystems prefer different formats:
| Format | Syntax | Pros | Cons | Used In |
|---|---|---|---|---|
| YAML | Indentation-based | Human-friendly, concise | Whitespace-sensitive, ambiguous syntax | Many robotics frameworks |
| TOML | INI-like | Clear, explicit | More verbose | Rust ecosystem |
| JSON | JavaScript-like | Strict, universal | No comments, verbose | Web APIs, URDF alternatives |
YAML example:
robot:
name: "mybot"
wheels: 4
TOML example:
[robot]
name = "mybot"
wheels = 4
JSON example:
{
"robot": {
"name": "mybot",
"wheels": 4
}
}
For robotics, YAML is the most common format. TOML is gaining traction in Rust-based systems (it's Cargo's native format).
Launch Systems
Real robots run dozens of nodes at once: camera drivers, sensor processors, planners, controllers, visualizers. Starting each manually is tedious and error-prone.
Launch systems orchestrate multiple nodes with a single command.
This single file:
- Starts three nodes
- Loads the camera config file
- Remaps topics so detector subscribes to camera
- Passes parameters to each node
Run it with a single command:
launch my_package camera_system.launch.xml
Use launch files for reproducibility. Instead of "start these five nodes in this order with these flags," you have a single versioned file. New team members can run your entire system with one command.
Environment-Specific Configurations
You often need different configs for different environments:
Your launch file selects the right one:
Run with:
launch my_package camera.launch.py env:=sim # Use sim.yaml
launch my_package camera.launch.py env:=real # Use real.yaml
What's Next?
You've packaged your code and made it configurable. But how do you know it actually works? How do you prevent bugs from creeping in as you add features? In the next lesson, we'll explore testing robot software — from unit tests to full system simulations.