Summary
In this chapter, you worked on parameters. Parameters allow you to provide settings for your nodes at runtime. Thus, with the same code, you could start several different nodes with different configurations. This increases the code reusability a lot.
To handle parameters in your nodes, follow these guidelines:
- Declare the parameter so that it exists within the node. The best practice is to set a default value. This value will also set the type for the parameter.
- Get the parameter’s value and store it in your node—for example, in a private attribute.
- Use this value in your code.
Then, when you start a node with ros2 run
, you can specify any parameter’s value you want.
You can also organize your parameters inside a YAML file, which makes it much more convenient when you start to have more than a handful of parameters. You will load the YAML file when you start a node.
Finally, you can also decide to allow parameters to be modified...