In this laboratory lesson, we will see how to start the simple parameter node and how to use the two
command line interface to interact with the parameters of a node allowing us basically to read them
from the terminal or even to change their values during the execution.
To do.
So let's start by opening a new terminal and go into the workspace and let's source the file setup dot
bash that is in the source folder, that is in the install folder so that the packages that we created
in this workspace are recognized and we can execute them from this terminal.
So let's start by running our simple parameter node with the command.
Ross to run and then I'm going to launch the C plus plus implementation of the simple parameter node.
So I'm going to launch the one from the Arduino, but CP examples.
But if you want to launch the Python one, you need to launch it from the Arduino dot pi examples.
And from this one we can see that there is the simple parameter executable available.
So let's execute this simple parameter node and let's press enter.
And now our node is up and running and so we can actually see and we can check that actually the parameters
of the node are available.
So the node has two parameters and let's check that those are available with the command.
Ros two param a list.
Just as the Ros2 Topic list command provides a list of all the currently available topics in Ros2.
The Ros2 Param List command provides a list of all the parameters that are available for each node.
In this case, we can see that there is only one node active, so the simple parameter node.
And we can also see that apart from some parameters that were instantiated by default so that ros2 is
passing by default to each node that are the quality of service parameters.
We can also see that there are two more parameters and those are the two ones that we have declared.
So the simple int parameter and the simple string parameter.
We can see the values that are associated with these parameters with the command Ros2 param get followed
by the name of the node from which we want to read the parameters.
And so let's read those of the simple parameter node and followed by the name of the parameter that
we want to read.
For example, let's take the simple int parameter and let's press enter.
And as we can see its value is 28.
So it is an integer and its value is 28.
And this is exactly the default value that we assigned to the parameter.
Since when we started the node, we haven't passed any parameter to the node.
Now, if we stop the execution of the node and this time we restart it, but passing a different value
to the simple int parameter.
And so we can do this with the Ros arcs.
And then let's use the flag minus P to pass a new parameter and let's set the simple int param to be
30 this time for example.
So let's press enter.
And now this means that we are starting the simple parameter node, assigning a value to the simple
int parameter.
Here there is an error, so it should be simple int parameter.
Okay, perfect.
And so we basically with this new value 30 it is overriding the default value that was here.
28 And so if we launch again the Ros two param get on the simple int parameter actually we can see that
its value is 30.
Not only we can change our parameter by relaunching the node, so here we add to restart the node to
assign a value to the simple int parameter.
We can also do so while the node is running.
For example, let's do this with the simple string parameter.
First, let's read its current value with the Ros two param get and from the simple parameter let's
read the simple string parameter.
And now for the moment, we can see that the value is Antonio.
That is a string and is exactly the default value that we assigned to this parameter in the code.
And now to change its value, we can use the command ros2 param set still followed by the name of the
node of which we want to change the parameters.
That is the simple parameter followed by the name of the parameter that we want to change.
And so the simple string parameter.
And then we need to assign a new value.
And so as this is a string, let's print for example.
So let's change its value to I ros two and let's press enter.
As soon as we do so, we can see here that our node so the simple parameter gets notified.
So the callback function gets called and we can see that the new value so it is printing the new value
of the simple string parameter that is the string Ros that we have just assigned to this parameter.
And also if we use for example, the Ros two param get again, we can see that the value of the parameter
is not anymore the string.
Antonio but is the string I Ros two.
The Aroostook Command line interface also offers many other commands to interact with the parameters
and you can see the list of them by typing ros2 param.
And then if you use Tab twice you can see the list of all the commands.
So the list of the available commands that you can use to interact with the parameters of a node.
I encourage you to try out some of these as they are quite self explicative and they will help you to
better understand how the parameter works in Ros to.