Additional tools for handling parameters
You start to get used to it: for each ROS 2 core concept, we get a dedicated ros2
command-line tool. For parameters, we have ros2 param
.
You can see all the commands with ros2 param -h
. Let’s focus on the most important ones so that we can get parameters’ values from the terminal and set some values after the node has been started. At the end of this section, we will also explore the different parameter services available for all nodes.
Getting parameters’ values from the terminal
After you’ve started one or several nodes, you can list all available parameters with ros2
param list
.
Stop all nodes and start two nodes, num_pub1
and num_pub2
, either by using the YAML file or by providing the parameters’ values manually.
In Terminal 1, run the following:
$ ros2 run my_py_pkg number_publisher --ros-args -r __node:=num_pub1 -p number:=3 -p publish_period:=0.5
In Terminal 2, run the following:
...