Main Content

set

Set value of ROS parameter or add new parameter

Since R2019b

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
Launching ROS Core...
Done in 0.70171 seconds.
Initializing ROS master on http://172.29.194.91:53540.
Initializing global node /matlab_global_node_96978 with NodeURI http://dcc365816glnxa64:34331/ and MasterURI http://localhost:53540.

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_96978 with NodeURI http://dcc365816glnxa64:34331/ and MasterURI http://localhost:53540.
Shutting down ROS master on http://172.29.194.91:53540.

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.55082 seconds.
Initializing ROS master on http://172.29.194.91:52656.
Initializing global node /matlab_global_node_70463 with NodeURI http://dcc365816glnxa64:39751/ and MasterURI http://localhost:52656.

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_70463 with NodeURI http://dcc365816glnxa64:39751/ and MasterURI http://localhost:52656.
Shutting down ROS master on http://172.29.194.91:52656.

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

|