Main Content

getParameter

Get value of parameter declared in ROS 2 node

Since R2022b

Description

example

paramValue = getParameter(nodeObj,paramName) returns paramValue, that contains the value of the specified parameter paramName associated with the ROS 2 node nodeObj. If it fails to return the parameter value, this syntax displays an error.

[paramValue,status] = getParameter(nodeObj,paramName) returns a status indicating whether the function was able to successfully return the parameter value. If it fails to return the parameter value, this syntax returns the paramValue as an empty double, and the status as false without displaying an error.

[paramValue,status] = getParameter(nodeObj,paramName,Datatype=dtype) specifies the expected return datatype of paramValue in the generated code using the name-value argument Datatype. You must specify this syntax for code generation. This syntax supports the returned datatype to be int64, logical, string, char or double.

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.

Output Arguments

collapse all

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

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

Status of the parameter return, returned as a logical scalar.

Extended Capabilities

Version History

Introduced in R2022b