What is a Ros2 parameter?
To understand Ros2 parameters, let's start with the problem.
Let's come back to the camera package I used when explaining packages and nodes.
Inside this package we have a camera driver node.
We will focus on that node.
So what does a camera driver node do?
Well, it is expected to connect to a camera through a hardware interface for example USB.
And then get the images from the camera.
Now inside your nodes you will have some variables for settings.
For example, the name of the USB device, the FPS you want to apply, and if you want to run your node
in a simulation mode or not.
Of course you could have many more settings.
So if you want to run your camera and the USB device name is different than the one in the code, well,
you have to change that setting inside your code and build the package again if needed.
If you want to start your camera with 30 fps instead of 60 fps, well, you will have to change the
code again.
And what if you want to run the node twice, once in simulation mode for a certain camera and once in
real mode for another camera?
You would have to duplicate the entire code so you can see that hardcoding those settings into your
code is definitely not a great option.
And here comes Ros two parameters A Ros two parameter is a configuration value for a node, useful for
any kind of setting, So you first need to declare those parameters in your code.
And then when you start the node, you set the values.
So here for example, we start the node and give some values for the parameters.
When we start it with the Ros two run command in the terminal, those values will be set in the code.
So the node can use them.
And we will see how to do that later in this section.
Now if you want you can kill that node and start it again with a different pH value for example.
Or you can start another node with different settings and of course a different name.
If you have two instances of the same node.
And the best part of all that is that you didn't touch anything in the code of the node.
You don't have to compile, you don't have to build anything.
Again, you just need to provide the parameters values at runtime.
So to recap Ros two parameters are used to provide settings for your nodes and you set their values
at runtime.
A parameter is specific to a node.
It will only live while the node is alive, and two different nodes will have two different sets of
parameters.
Values.
A Ros two parameter has a name and a data type.
Among the most common types you can find booleans, integer numbers, double numbers, strings, and
lists of previous data types.
All right, now you are aware of what Ros two parameters are and why we need them.
Let's practice by diving directly into the code.