Storing parameters in YAML files
As your ROS 2 application grows, so will the number of parameters. Adding 10 or more parameters from the command line is not really an option anymore.
Fortunately, you can use YAML files to store your parameters, and you can load these files at runtime. If you don’t know YAML, it’s basically a markup language, similar to XML and JSON, but supposedly more readable by humans.
In this section, you will learn how to add your parameters to a YAML file and how to load this file at runtime.
Loading parameters from a YAML file
Let’s start by saving parameters into a file so we can use them when we start a node.
First, create a YAML file with the .yaml
extension. The filename doesn’t matter that much, but it’s better to give it a meaningful name. As our application deals with numbers, we can name it number_params.yaml
.
For now, let’s just create a new file in our home directory (in the next chapter...