ROS 2 Lyrical lab 06 ยท 75 min
Launch and parameters
Start a repeatable robot system and load reviewed limits from YAML.
Practice this lab in your browser: Validate a parameter on setUnderstand before building
How this part of ROS 2 works
Launch files describe how a complete system starts. Parameters move reviewed configuration out of source code while keeping each node responsible for validation.
A loaded value is not automatically safe: the node must declare its expected type and reject values outside its operating range.
Before you start
- At least two working nodes
- A package with launch and config directories
Files you will touch
src/robot_bringup/launch/system.launch.pysrc/robot_bringup/config/limits.yaml
Step 1
Set up
status_node:
ros__parameters:
max_speed: 0.25
publish_rate: 10.0Step 2
Create the file
from pathlib import Path
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
config = str(Path(get_package_share_directory('robot_bringup')) / 'config' / 'limits.yaml')
return LaunchDescription([
Node(package='robot_basics', executable='status_node',
parameters=[config], output='screen')
])What each part does
- 1.The YAML nests values under the node name and ros__parameters.
- 2.The launch description starts the executable and supplies the reviewed configuration file.
Step 3
Build, run and inspect
ros2 launch robot_bringup system.launch.py
ros2 param get /status_node max_speed
ros2 param set /status_node max_speed 0.2Proof that it works
- The launch file starts every declared node
- max_speed loads as 0.25
- Runtime changes are accepted only inside the node's declared safe range
Recovery notes
- Install launch and config directories from CMakeLists.txt.
- Declare every parameter before reading it and validate safety-critical changes in an on-set callback.