Main Content

Get Parameter

Get values from ROS parameter server

  • Get Parameter block

Libraries:
ROS Toolbox / ROS

Description

The Get Parameter block outputs the value of the specified ROS parameter. The block uses the ROS node of the Simulink® model to connect to the ROS network. This node is created when you run the model and is deleted when the model terminates. If the model does not have a node, the block creates one.

On each sample hit, the block checks the ROS parameter server for the specified ROS parameter and outputs its value.

Ports

Output

expand all

Parameter value from the ROS network. The value depends on the Data type parameter.

Status of ROS parameter, specified as one of the following:

  • 0 — ROS parameter retrieved successfully. The retrieved value is output in the Value port.

  • 1 — No ROS parameter with specified name found. If there is no known value, Value is set to the last received value or to Initial value.

  • 2 — ROS parameter retrieved, but its type is different than the specified Data type. If there is no known value, Value is set to the last received value or to Initial value.

  • 3 — For string parameters, the incoming string has been truncated based on the specified length.

Length of the string parameter, returned as an integer. This length is the number of elements of the uint8 array or the number of characters in the string that you cast to uint8.

Note

When getting string parameters from the ROS network, an ASCII value of 13 returns an error due to its incompatible character type.

Dependencies

To enable this port, set the Data type to uint8[] (string).

Parameters

expand all

Source for specifying the parameter name as one of the following:

  • Select from ROS network — Use Select to select a parameter name. The Data type parameter is set automatically. You must be connected to a ROS network.

  • Specify your own — Enter a parameter name in Name and specify its data type in Data type. You must match a parameter name exactly.

Parameter name to get from the ROS network, specified as a string. When Source is set to Select from ROS network, use Select to select an existing parameter. You must be connected to a ROS network to get a list of parameters. Otherwise, specify the parameter and data type.

Parameter name strings must follow the rules of ROS graph names. Valid names have these characteristics:

  • The first character is an alpha character ([a-z|A-Z]), tilde (~), or forward slash (/).

  • Subsequent characters are alphanumeric ([0-9|a-z|A-Z]), underscores(_), or forward slashes (/).

Data type of your parameter, specified as a string. The uint8[] (string) enables the Maximum length parameter.

Note

The uint8[] (string) data type is an array of ASCII values corresponding to the characters in a string. When getting string parameters, you can create a MATLAB Function (Simulink) block to compare the string to a desired parameter value. For more information, see ROS Parameters in Simulink.

Data Types: double | int32 | Boolean | uint8

Maximum length of the uint8 array, specified as a scalar. If the parameter string has a length greater than Maximum length, the ErrorCode output is set to 3.

Dependencies

To enable this port, set the Data type to uint8[] (string).

Default parameter value output from when an error occurs and no valid value has been received from the parameter server. The data type must match the specified Data type.

Interval between outputs, specified as a scalar. This default value indicates that the block output never changes. Using this value speeds simulation and code generation by eliminating the need to recompute the block output. Otherwise, the block outputs a new blank message at each interval of Sample time.

For more information, see Specify Sample Time (Simulink).

To enable error code output, select this parameter. When you clear this parameter, the ErrorCode output port is removed from the block. The status options are:

  • 0 — ROS parameter retrieved successfully. The retrieved value is output in the Value port.

  • 1 — No ROS parameter with specified name found. If there is no known value, Value is set to the last received value or to Initial value.

  • 2 — ROS parameter retrieved, but its type is different than the specified Data type. If there is no known value, Value is set to the last received value or to Initial value.

  • 3 — For string parameters, the incoming string has been truncated based on the specified length.

Extended Capabilities

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

Version History

Introduced in R2019b