What is a ROS parameter ? Before diving into the explanation, let’s see the problem we have here.
This post is a part of the What is ROS? series.
Why do you need ROS parameters ?
So, you have a nice robot application with many packages and nodes inside those packages.
Now, you want to be able to create some global settings, for example:
- The name of your robot.
- The frequency at which you read some sensors.
- A simulation flag that you can use in all your nodes to inform that the robot is running in real mode or simulation mode.
Well, if you don’t have a way to store those settings globally inside the ROS environment, it will become a real mess.
You certainly don’t want to hardcode those settings in all your nodes, and you also don’t want to get too many useless dependencies between your nodes.
You’ll also realize that it could be great to start a node again with different input parameters, without having to change the code for the node – and worse, recompile the code for C++ nodes.
At this point, you realize that you need a sort of global dictionary for shared settings in your application, that can be retrieved at runtime, when you launch your nodes.
The ROS parameter server
Here comes the ROS parameter server.
After you launch the ROS master, the parameter server is automatically created inside the ROS master.
The parameter server is basically a dictionary containing global variables which are accessible from anywhere in the current ROS environment.
Those global variables are called ROS parameters.
Here I have set 3 parameters:
- Robot name (string type)
- Sensor read frequency (integer type)
- Simulation mode flag (boolean type)
At any time, a node can read a parameter, modify a parameter, and can create new ones.
In this example, we have 4 nodes included in 3 different packages. As you can see, any node from any package can get access to the ROS parameter server. The only (and obvious) condition is that the nodes should be on the same environment as the ROS master.
When node A is started, it can add a new parameter into the parameter server. If node B starts after node A, node B will have access to this new parameter.
When you create a ROS master, a ROS parameter server is created. It contains a dictionary, accessible globally on the ROS environment.
A ROS parameter is basically just one of the shared variable stored in the parameter server.
A ROS parameter has a name, and a data type. Among the most common types, you can use:
- Integer number
- Double number
- List of previous data types
You are now aware of what are ROS parameters, and why we need them. Feel free to ask your questions in the comment section below!