Search this site
Embedded Files
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
  • More
    • Home
      • Computer Geek
      • Learning
      • Math Geek
      • Projects

ROS Parameter Server

< Back to ROS Intermediate tutorials
What is the Parameter Server?
Tool: rosparam
YAML Files
APIs
C++
Python
Additional Material
Links

What is the Parameter Server?

Official page

The Parameter Server is a place where variables can be stored, accessed and modified during runtime. The variables are stored as a key-value map, where the key is the name and the value is the stored contents of the variable. ROS uses XMLRPC for the implementation of the Parameter Server and provides APIs to access the parameters. ROS also provides a YAML friendly interface for the user to load and store the parameters on the server. The tool used for interacting with the parameter server is rosparam. In this tutorial, we must learn about using YAML files for parameter configurations, APIs for C++ and Python to access the parameter server.

Tool: rosparam

The rosparam tool allows interfacing with the parameter server through a terminal. It allows us to set, get, load, dump, delete and list parameters. Do the following:

  • Run roscore on a terminal
  • Run rosparam list to get a list of keys. These are the names of the parameters currently running on the parameter server. The standard parameters that are created when roscore is spawned are shown in the terminal.
  • To get a parameter (say "/run_id"), run rosparam get /run_id. The result will be the value of the parameter. The same can be applied to any parameter.
  • To create a parameter on the parameter server (say "var1" as key and "Value 1" as value), run the command rosparam set /var1 "Value 1". This creates a parameter with name (key) as /var1 and "Value 1" as value.
  • To delete a parameter (say with "var1" as key), run rosparam delete /var1 to delete the parameter.

YAML Files

YAML is a language that is commonly used for configuration files. It make loading parameters and storing parameters to and from the parameter very simple. The complete language documentation for this language can be found here but whatever you come across in this tutorial is more than enough to get you started.

For this tutorial, refer to the package test_rosyaml on GitHub. Please build it in an active workspace.

Usually, all configuration files are stored in a separate folder named "config". But for this package, the files are stored in a folder named "param_configs". The file shown below is param1.yaml. To load the parameters from a YAML file to the ROS parameter server, we use the command rosparam load, we can load the parameters using the command:

  • rosparam load param1.yaml

This will load the parameters on the parameter server. To see the results, run the command rosparam dump. This command is used to dump the parameters into a specified YAML file. But, if nothing is specified, it prints them out to the terminal.

Parameters that are spawned along with the roscore. These parameters are loaded by default and all have string as the datatype for values.
Output of rosparam dump for the file param1.yaml (different run, therefore the URI is different from the one above).
The structure of a generic YAML File.File param1.yaml in the package test_rosyaml

APIs

C++

We use the Node Handler to interact with the parameter server. The docs can be found here. The functions that it provides are follows:

  • hasParam: Used to check for an existing parameter.
  • getParam: Used to retrieve the value of a parameter.
    • Note that the passed variable into which the value has to be stored has to have the same data type as that of the parameter. If this is not the case, then the function returns false and blank parameter value. To see the difference, run the node h2_ns2_param_val with the files param1.yaml and param2.yaml (difference in the parameter "/header2/ns2").
  • getParamNames: Used to get a string vector of names (keys) of the parameters.
Output of single_param_val, all_params and h2_ns2_param_val when the parameters are from param1.yaml
Output of h2_ns2_param_val using param2.yaml parameters

Python

In Python, the parameters are handled through the rospy module. The documentation can be found here. Here are a few functions that it provides:

  • get_param: To get the value of a particular parameter. Note that Python is type safe and the function returns the parameter regardless of the data type. Documentation here.
  • get_param_names: To get a list of parameters on the parameter server. Documentation here.
Output of param_v1.py, get_all_params.py and param_h2_ns2.py when the parameters are from param1.yamlNotice that the script param_h2_ns2.py performed correctly, unlike the C++ version of it
Output of param_h2_ns2.py when using param2.yaml parameters

Additional Material

Links

  • Package on GitHub here, README here.
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse