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.70113 seconds.
Initializing ROS master on http://172.30.144.24:49883.
Initializing global node /matlab_global_node_96523 with NodeURI http://dcc796195glnxa64:35815/ and MasterURI http://localhost:49883.

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_96523 with NodeURI http://dcc796195glnxa64:35815/ and MasterURI http://localhost:49883.
Shutting down ROS master on http://172.30.144.24:49883.

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.66963 seconds.
Initializing ROS master on http://172.30.144.24:59754.
Initializing global node /matlab_global_node_57799 with NodeURI http://dcc796195glnxa64:46883/ and MasterURI http://localhost:59754.

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_57799 with NodeURI http://dcc796195glnxa64:46883/ and MasterURI http://localhost:59754.
Shutting down ROS master on http://172.30.144.24:59754.

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

|