What is a ROS Parameter?

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.

Great!

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 are learning ROS?

Check out ROS For Beginners and learn ROS step by step.


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.

What is a ROS parameter ? 1/2

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.

What is a ROS parameter ? 2/2

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.

Conclusion

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:

  • Boolean
  • Integer number
  • Double number
  • String
  • List of previous data types

Did you find this tutorial useful?

Do you want to learn how to program with ROS?

If yes, this course is for you:

ROS For Beginners - A Step By Step Course

>> ROS For Beginners - A Step By Step Course <<