CodeTheRobot

Ubuntu Linux for Robotics · Lesson 47 of 96

Parameters

ros2 param list/get/set/dump, YAML files and loading them at start-up.

Estimated time · 45–60 min

Learning goals

What you will understand

  • Explain parameters in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

Parameters configure a node without recompiling. On Ubuntu you can inspect and change them live: ros2 param list, ros2 param get /node name, ros2 param set /node name value, and ros2 param dump /node to save all of them as YAML. The node must declare a parameter before it can be set.

For repeatable setups put parameters in a YAML file under config/, install that folder, and load it with --ros-args --params-file (or from a launch file). Keep one YAML per robot so the same code runs on different machines.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the parameters commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

ros2 param list /arm_node
# List a node's parameters.
ros2 param get /arm_node max_speed
# Read one value.
ros2 param set /arm_node max_speed 0.8
# Change it while the node runs.
ros2 param dump /arm_node > config/arm_dump.yaml
# Save the current values to a file.
ros2 run robot_nodes arm_node --ros-args --params-file config/arm.yaml
# Start the node with values from a YAML file.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · Messages between nodes

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

requestresponseclientservercalls answered: 0MESSAGES BETWEEN NODES

Demo for Parameters. Expected result: Double value is: 0.8

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# TODO: set max_speed of /arm_node to 0.8, then read it back with ros2 param get

Expected output

Double value is: 0.8
Stuck? Show the full solution (try it yourself first)
ros2 param set /arm_node max_speed 0.8
ros2 param get /arm_node max_speed

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Run a node with parameters, change one at run time, dump the parameters to YAML, restart the node from that file, and confirm the value survived.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.