Main Content

setParameter

Set value of parameter declared in ROS 2 node

Since R2022b

Description

setParameter(nodeObj,paramName,paramValue) sets the value of the parameter paramName associated with the ROS 2 node object nodeObj to the value, paramValue. If paramName does not exist in the ROS 2 node, this syntax throws an error.

example

Examples

collapse all

Create a structure that contains all the parameters for the ROS 2 node.

nodeParams.my_double = 2.0;
nodeParams.my_namespace.my_int = int64(1);
nodeParams.my_double_array = [1.1 2.2 3.3];
nodeParams.my_string = "Keyparams";

Create a ROS 2 node and specify nodeParams as the parameters.

node1 = ros2node("/node1",Parameters=nodeParams);

Set the parameter my_double to a new value.

setParameter(node1,"my_double",5.2);

Obtain the new value of the parameter my_double.

doubleValue = getParameter(node1,"my_double")
doubleValue = 
5.2000

Input Arguments

collapse all

A object on the network, specified as a ros2node object handle.

Name of the parameter, specified as a string scalar or a character vector.

Value of the parameter, specified as a scalar or an array.

Data Types: int64 | logical | char | string | double | cell

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2022b