Main Content

Access the ROS Parameter Server

This example explores how to add and retrieve parameters on the ROS parameter server. The parameter server usually runs on the same device that launches the ROS master. The parameters are accessible globally over the ROS network and can be used to store static data such as configuration parameters. Supported data types include strings, integers, doubles, logicals, and cell arrays.

Prerequisites: Get Started with ROS, Connect to a ROS Network

Create Parameter Tree

Start the ROS master and parameter server in MATLAB.

Launching ROS Core...
.Done in 1.3665 seconds.
Initializing ROS master on
Initializing global node /matlab_global_node_63793 with NodeURI http://dcc277159glnxa64:41427/ and MasterURI http://localhost:50367.

Create a parameter tree object to interact with the parameter server. Use the parameter tree to interact with the parameter server and call functions such as set, get, del, has and search. Create a new parameter server using rosparam.

ptree = rosparam
ptree = 
  ParameterTree with properties:

    AvailableParameters: {0x1 cell}

Add New Parameters

To set a parameter for the robot IP address, use the parameter name ROBOT_IP. Check if a parameter with the same name already exists. Use the has function.

ans = logical

If has returns 0 (false) as the output, then the ROBOT_IP name could not be found on the parameter server.

Add some parameters indicating a robot's IP address to the parameter server. Use the set function for this purpose.


The ROBOT_IP parameters are now available to all nodes connected to this ROS master. You can specify parameters within a namespace. For example, the /myrobot/ROBOT_IP parameter is within the /myrobot namespace in this example.

Set more parameters with different data types.


Use a cell array as an input to the set function. Set a parameter that has the goal coordinates {x, y, z} for the robot.


Set additional parameters to populate the parameter server.


Get Parameter Values

Retrieve the robot's IP address from the ROBOT_IP parameter in the /myrobot namespace using the get function:

robotIP = get(ptree,'/myrobot/ROBOT_IP')
robotIP = 

Get List of All Parameters

To get the entire list of parameters stored on the parameter server, use dot notation to access the AvailableParameters property. The list contains all the parameters that you added in previous sections.

plist = ptree.AvailableParameters
plist = 7x1 cell
    {'/MAX_SPEED'          }
    {'/ROBOT_IP'           }
    {'/goal'               }
    {'/myrobot/MAX_SPEED'  }
    {'/myrobot/ROBOT_IP'   }
    {'/myrobot/ROBOT_NAME' }

Modify Existing Parameters

You can also use the set function to change parameter values. Note that the modification of a parameter is irreversible, since the parameter server will simply overwrite the parameter with the new value. You can verify if a parameter already exists by using the has function.

Modify the MAX_SPEED parameter:


The modified value can have a different data type from a previously assigned value. For example, the value of the MAX_SPEED parameter is currently of type double. Set a string value for the MAX_SPEED parameter:


Delete Parameters

Use the del function to delete a parameter from the parameter server.

Delete the goal parameter.


Check if the goal parameter has been deleted. Use the has function.

ans = logical

The output is 0 (false), which means the parameter was deleted from the parameter server.

Search Parameters

Search for all the parameters that contain 'myrobot' using the search command:

results = search(ptree,'myrobot')
results = 1x3 cell
    {'/myrobot/MAX_SPEED'}    {'/myrobot/ROBOT_IP'}    {'/myrobot/ROBOT_NAME'}

Shut Down the ROS Network

Shut down the ROS master and delete the global node.

Shutting down global node /matlab_global_node_63793 with NodeURI http://dcc277159glnxa64:41427/ and MasterURI http://localhost:50367.
Shutting down ROS master on

Next Steps

Related Topics