Main Content

get

Get ROS parameter value

Description

pvalue = get(ptree) returns a dictionary of parameter values under the root namespace: /. The dictionary is stored in a structure.

pvalue = get(ptree,paramname) gets the value of the parameter with the name paramname from the parameter tree object ptree.

pvalue = get(ptree,namespace) returns a dictionary of parameter values 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

[pvalue,status] = get(ptree,paramname) returns the parameter values and the associated status. status indicates whether the pvalue successfully returned.

pvalue = get(ptree,paramname,"DataType",ptype) specifies the ROS parameter data type when generating code. The input parameter type value must match the existing parameter type else the function returns the pvalue as empty, [], for the requested type.

Examples

collapse all

Create the parameter tree. A ROS network must be available using rosinit.

rosinit
Launching ROS Core...
Done in 0.66449 seconds.
Initializing ROS master on http://172.30.144.24:56705.
Initializing global node /matlab_global_node_00238 with NodeURI http://dcc796195glnxa64:36283/ and MasterURI http://localhost:56705.
ptree = rosparam;

Set a parameter value. You can also use the simplified version without a parameter tree:

rosparam set 'DoubleParam' 1.0

set(ptree,'DoubleParam',1.0)

Get the parameter value.

get(ptree,'DoubleParam')
ans = 
1

Alternatively, use the simplified versions without using the parameter tree.

rosparam set 'DoubleParam' 2.0
rosparam get 'DoubleParam'
2

Disconnect from ROS network.

rosshutdown
Shutting down global node /matlab_global_node_00238 with NodeURI http://dcc796195glnxa64:36283/ and MasterURI http://localhost:56705.
Shutting down ROS master on http://172.30.144.24:56705.

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 character vector. This string must match the parameter name exactly.

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).

ROS parameter data type, specified as either 'int32', 'logical', 'double', or 'char'.

Output Arguments

collapse all

ROS parameter value, returned as a supported MATLAB data type. When specifying the namespace input argument, pvalue is returned as a dictionary of parameter values under the specified namespace. The dictionary is represented in MATLAB as a structure.

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

  • string — character vector (char)

  • list — cell array (cell)

  • dictionary — structure (struct)

Status of ROS parameter value, returned as true or false. If the status is false, the pvalue value is returned as empty, [].

Data Types: logical

Limitations

Base64-encoded binary data and iso 8601 data from ROS are not supported.

Extended Capabilities

Version History

Introduced in R2019b

See Also

|