set

Set value of ROS parameter or add new parameter

Description

example

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)

Examples

collapse all

Connect to the ROS network.

rosinit
Initializing ROS master on http://bat1074506glnxa64:40669/.
Initializing global node /matlab_global_node_44139 with NodeURI http://bat1074506glnxa64:36091/

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_44139 with NodeURI http://bat1074506glnxa64:36091/
Shutting down ROS master on http://bat1074506glnxa64:40669/.

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

Connect to a ROS network.

rosinit
Initializing ROS master on http://bat1074506glnxa64:38305/.
Initializing global node /matlab_global_node_66038 with NodeURI http://bat1074506glnxa64:37959/

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_66038 with NodeURI http://bat1074506glnxa64:37959/
Shutting down ROS master on http://bat1074506glnxa64:38305/.

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.

See Also

|

Introduced in R2019b