A parameter is a configuration value of a node. You can think of parameters as node settings. A node can store parameters as integers, floats, booleans, strings, and lists. In ROS 2, each node maintains its own parameters.

Commands

ros2 param list

To see the parameters belonging to your nodes, use the command

ros2 param list

You will see the node namespaces, /teleop_turtle and /turtlesim, followed by each node's parameters:

/teleop_turtle:
  qos_overrides./parameter_events.publisher.depth
  qos_overrides./parameter_events.publisher.durability
  qos_overrides./parameter_events.publisher.history
  qos_overrides./parameter_events.publisher.reliability
  scale_angular
  scale_linear
  use_sim_time
/turtlesim:
  background_b
  background_g
  background_r
  qos_overrides./parameter_events.publisher.depth
  qos_overrides./parameter_events.publisher.durability
  qos_overrides./parameter_events.publisher.history
  qos_overrides./parameter_events.publisher.reliability
  use_sim_time

Every node has the parameter use_sim_time

ros2 param get

To display the type and current value of a parameter, use the command:

ros2 param get <node_name> <parameter_name>

If you want to find out the current value of /turtlesim's parameter background_g:

ros2 param get /turtlesim background_g

Which will return the value:

Integer value is: 86

Now you know background_g holds an integer value.

ros2 param set

To change a parameter's value at runtime, use the command:

ros2 param set <node_name> <parameter_name> <value>

If you need to change /turtlesim's background color:

ros2 param set /turtlesim background_r 150

Your terminal should return the message:

Set parameter successful

ros2 param dump

You can view all of a node's current parameter values by using the command:

ros2 param dump <node_name>

The command prints to the standard output (stdout) by default but you can also redirect the parameter values into a file to save them for later. To save your current configuration of /turtlesim's parameters into the file turtlesim.yaml, enter the command:

ros2 param dump /turtlesim > turtlesim.yaml

And the content of the file will be:

/turtlesim:
  ros__parameters:
    background_b: 255
    background_g: 86
    background_r: 150
    qos_overrides:
      /parameter_events:
        publisher:
          depth: 1000
          durability: volatile
          history: keep_last
          reliability: reliable
    use_sim_time: false

ros2 param load

You can load parameters from a file to a currently running node using the command:

ros2 param load <node_name> <parameter_file>

To load the turtlesim.yaml file generated with ros2 param dump into /turtlesim node's parameters, enter the command:

ros2 param load /turtlesim turtlesim.yaml

Tip

If you want to start the same node using your saved parameter values, use:

ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>