ParameterTree

Access ROS parameter server

Description

A ParameterTree object communicates with the ROS parameter server. The ROS parameter server can store strings, integers, doubles, Booleans, and cell arrays. The parameters are accessible globally over the ROS network. You can use these parameters to store static data such as configuration parameters.

To directly set, get, or access ROS parameters without creating a ParameterTree object, see rosparam.

The following ROS data types are supported as values of parameters. For each ROS data type, the corresponding MATLAB® data type is also listed.

ROS Data TypeMATLAB Data Type
32-bit integerint32
booleanlogical
doubledouble
stringcharacter vector (char)
listcell array (cell)
dictionarystructure (struct)

Creation

Description

ptree = rosparam creates a parameter tree object, ptree. After ptree is created, the connection to the parameter server remains persistent until the object is deleted or the ROS master becomes unavailable.

example

ptree = ros.ParameterTree(node) returns a ParameterTree object to communicate with the ROS parameter server. The parameter tree attaches to the ROS node, node. To connect to the global node, specify node as [].

Properties

expand all

This property is read-only.

List of parameter names on the server, specified as a cell array.

Example: {'/myParam';'/robotSize';'/hostname'}

Data Types: cell

Object Functions

getGet ROS parameter value
hasCheck if ROS parameter name exists
searchSearch ROS network for parameter names
setSet value of ROS parameter or add new parameter
delDelete a ROS parameter

Examples

collapse all

Start the ROS master and create a ROS node.

master = ros.Core;
node = ros.Node('/test1');

Create the parameter tree object.

ptree = ros.ParameterTree(node);

Set multiple parameters.

set(ptree,'DoubleParam',1.0)
set(ptree,'CharParam','test')
set(ptree,'CellParam',{{'test'},{1,2}});

View the available parameters.

parameters = ptree.AvailableParameters
parameters = 3x1 cell array
    {'/CellParam'  }
    {'/CharParam'  }
    {'/DoubleParam'}

Get a parameter value.

data = get(ptree,'CellParam')
data=1×2 cell
    {1x1 cell}    {1x2 cell}

Search for a parameter name.

search(ptree,'char')
ans = 1x1 cell array
    {'/CharParam'}

Delete the parameter tree and ROS node. Shut down the ROS master.

clear('ptree','node')
clear('master')

Use structures to specify a dictionary of ROS parameters under a specific namespace.

Connect to a ROS network.

rosinit
Initializing ROS master on http://bat1074105glnxa64:40703/.
Initializing global node /matlab_global_node_40835 with NodeURI http://bat1074105glnxa64:40231/

Create a dictionary of parameter values. This dictionary contains the information relevant to an image. Display the structure to verify values.

image = imread('peppers.png');

pval.ImageWidth = size(image,1);
pval.ImageHeight = size(image,2);
pval.ImageTitle = 'peppers.png';
disp(pval)
     ImageWidth: 384
    ImageHeight: 512
     ImageTitle: 'peppers.png'

Set the dictionary of values using the desired namespace.

rosparam('set','ImageParam',pval)

Get the parameters using the namespace. Verify the values.

pval2 = rosparam('get','ImageParam')
pval2 = struct with fields:
    ImageHeight: 512
     ImageTitle: 'peppers.png'
     ImageWidth: 384

Shut down ROS network.

rosshutdown
Shutting down global node /matlab_global_node_40835 with NodeURI http://bat1074105glnxa64:40231/
Shutting down ROS master on http://bat1074105glnxa64:40703/.

Introduced in R2019b