Main Content

set

Set value of ROS parameter or add new parameter

Description

set(ptree,paramname,pvalue) assigns the value pvalue to the parameter with the name paramname. This parameter is sent to the parameter tree ptree.

set(ptree,namespace,pvalue) assigns multiple values as a dictionary in pvalue under the specified namespace.

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

  • 32-bit integer — int32

  • Boolean — logical

  • double — double

  • strings — string scalar, string, or character vector, char

  • list — cell array (cell)

  • dictionary — structure (struct)

example

Examples

collapse all

Connect to the ROS network.

rosinit
Launching ROS Core...
Done in 0.47181 seconds.
Initializing ROS master on http://172.20.149.99:56663.
Initializing global node /matlab_global_node_66187 with NodeURI http://dcc786972glnxa64:38477/ and MasterURI http://localhost:56663.

Create a ROS parameter tree. Set a double parameter. Get the parameter to verify it was set.

ptree = rosparam;
set(ptree,'DoubleParam',1.0)
get(ptree,'DoubleParam')
ans = 
1

Shut down the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_66187 with NodeURI http://dcc786972glnxa64:38477/ and MasterURI http://localhost:56663.
Shutting down ROS master on http://172.20.149.99:56663.

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

Connect to a ROS network.

rosinit
Launching ROS Core...
Done in 0.44923 seconds.
Initializing ROS master on http://172.20.149.99:55976.
Initializing global node /matlab_global_node_08613 with NodeURI http://dcc786972glnxa64:44357/ and MasterURI http://localhost:55976.

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 parameter 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_08613 with NodeURI http://dcc786972glnxa64:44357/ and MasterURI http://localhost:55976.
Shutting down ROS master on http://172.20.149.99:55976.

Input Arguments

collapse all

Parameter tree, specified as a ParameterTree object handle. Create this object using the rosparam function.

ROS parameter name, specified as a string scalar or character vector. This string must match the parameter name exactly.

ROS parameter value or dictionary of values, specified as a supported MATLAB data type.

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
stringstring scalar, string, or character vector, char
listcell array (cell)
dictionarystructure (struct)

ROS parameter namespace, specified as a string scalar or character vector. All parameter names starting with this string are listed when calling rosparam("list",namespace).

Limitations

Base64-encoded binary data and iso 8601 data from ROS are not supported.

Extended Capabilities

Version History

Introduced in R2019b

See Also

|