The robot's max speed is hard-coded, so every new value means an edit, a colcon build and a restart. ROS 2 parameters fix that: named, typed settings each node declares, and anyone can read or change while it runs.
In this video, with one small two-wheeled robot and one parameter (max_speed):
- declaring a parameter with a default, reading it where you use it, and why undeclared names are rejected
- why parameters live in the node: no global parameter server, as there was in ROS 1
- three ways to set one: --ros-args -p on the command line, a YAML params file, and ros2 param set at runtime
- the YAML layout: node name, ros__parameters, then name: value
- a parameter callback that refuses a negative speed
Code in Python (rclpy), with the C++ (rclcpp) calls named. ROS 2 Lyrical Luth (LTS); the same API works in Jazzy. Terminal output on screen is shortened example output.
Try it tonight:
ros2 run turtlesim turtlesim_node
ros2 param list
ros2 param set /turtlesim background_r 150
ros2 param dump /turtlesim
Chapters
00:00 A hard-coded number
01:00 Declare it, read it
02:24 Why declare at all?
03:30 Where do parameters live?
04:52 Three ways to set it
06:23 Saying no: the parameter callback
07:47 Code says what, parameters say how much
08:21 Try it yourself
Part of ROS 2 Explained. #ROS2 #robotics #ROS