In this lecture, we're going to go over using parameters in ROS to parameters are essentially dynamic
variables which are associated with nodes.
These dynamic variables have information stored in it which can be set, retrieved or changed freely.
Parameters can have a variety of uses like keeping track of the state of a system or have data related
to, say, physical attributes of the robot.
Let's go ahead and open up a terminal and run our RPM pub node we created in the publishers and subscriber
project.
Once it's running, we'll go ahead and open a new terminal tab and launch the speed publisher we created
in the same project.
We'll open another terminal tab and we're going to run Ross to parameter list.
Here we can see a list of parameters sorted by Node.
In this case, both our nodes have one parameter called use SIM time.
This is a default parameter added to nodes.
We can see the value of this node by using the ROS two parameter get command.
This command takes in the name of the package.
So for instance, we can do the RPM publisher node and then the name of the parameter we want to see
the value of.
In this case, use SIM time so we can see the parameter is set to false by default, which means it's
using the time on our computer instead of a time from a simulation.
You can set it to true if you wanted to use the time being generated by a simulation you had running.
If you want to see more information about a parameter, you can use the ROS two parameter type command
with the same arguments.
Here we can see the type and any constraints the parameters may have.
All right.
So I'm going to go ahead and stop all of these nodes.
All right.
So how can parameters be useful for us in our Ross code?
Well, in my RPM pub node, I hardcoded the value of our RPM to simulate a wheel encoder sensor going
at a constant rate.
Instead, let's use a parameter so that if someone wants to change the RPM value, they don't have to
edit my source code.
We also did this in the speed calc notes.
If I go ahead and open that up, we hardcoded in a wheel radius.
Now this is a potential value we would change if we were using it with a different robot, which makes
it prime to use it as a parameter.
So let's go ahead and use a parameter by using the declared parameter function right after I initialize
my node to create a parameter called wheel radius and set the default value to our wheel radius variable.
To make this a bit more clear, I will just state that this is the default wheel radius variable.
So for the time being, I'll just also set this wheel radius variable here to wheel radius default.
But we'll be changing this to use our parameter in a bit.
But before we do that, I want to print out some things about our parameter so you can see how it works.
So we can use the get parameter function of our node.
So this function will return a parameter object in order to get the actual value from the parameter.
We have to use the get parameter value method of this particular class.
So we'll go ahead and print it out.
We will have to include one more thing, but let's just see what this looks like so far.
So I'll go ahead and save the file.
And since we're using can build Simulink install, we don't need to recompile our workspace and instead
I'll just head over to our terminal where we are running our speed calc node.
And if I run it, we get this bound method, get parameter value.
And so that's actually because I forgot to put the parentheses to actually call this function.
Let's try this one more time.
Save that.
And we'll rerun the node.
So here we can see printing through the screen the contents of the parameter value message type.
We can see this parameter is type three, which means it is of a type double.
And in the double value section we see the value is 0.125, which is the value we set the default wheel
radius variable.
As we can also see, this parameter is available if we use the ROS two parameter list command and then
use raw super and get.
If we wanted to, we could set a different value for this parameter using the ROS two parameter set
command.
In this case, I can set the wheel radius to 0.5.
And now if I get this parameter one more time, we see that it is indeed changed to 0.5 and this will
also take effect within our node.
So let's go ahead and wrap this up by adjusting our speed calc node to instead use this parameter value
instead of the default wheel radius variable we used.
And we will call the double value to get.
The particular value stored in this double value part of the object.
And I'll go ahead and stop this node from running.
And we can go ahead and change instead of using this default wheel radius variable to instead use the
parameter.
All right, So now in our calculate speed publisher, we check for what the value of the wheel radius
parameter is and get the double value of it.
Then we calculate the speed using that parameter value.
Great.
So with that, we can go ahead and save this speed calc node.
Open up a terminal.
Now click the screen.
And now if I rerun both my speed calc node and my RPM pub node.
I can go ahead and clear the screen on my third terminal and echo out the speed topic.
All right.
So here we see the information coming in from the speed topic.
And if I open up a fourth terminal, I can go ahead and change the parameter value.
So, Ross two parameter set the name of the node and then the name of the parameter we want to change.
So in this case, I'll set the wheel radius parameter to 0.5.
And now that the parameters change, we see that our speed calculations have also changed with it.
So it is successfully using our parameter to help calculate the given speed of our robot.
Congratulations.
You successfully implemented parameters in your very own ROS to code.
It is worth noting that if you have multiple nodes that you want to share parameter values with, you
can use ROS services to request the parameter variables between nodes.
Now we'll learn about services later on in the course, so don't worry about it for now.
In this lecture, we talked about parameters.
We went over a few different terminal commands such as RAS, Super M list, get and set in order to
look at our parameters and see what their values are as well as set them.
We then learn how to use parameters in Python by utilizing the declare parameter function of our node,
which we pass in a parameter name and a particular value.
We can then utilize our nodes, get parameter command to then get this parameters value.
In the next lecture, we'll be learning about launch files where we can automate the launching of nodes
as well as setting of parameter values.