Main Content

Manage Array Sizes for ROS Messages in Simulink

A ROS message is represented as a bus signal. For more information on bus signals, see Virtual Bus (Simulink).

If you are working with variable-length signals in Simulink®, the non-virtual bus used for messages cannot contain variable-length arrays as properties. All variable-length arrays are converted to fixed-length arrays for non-virtual buses. Therefore, you must manage the maximum size for these fixed-size arrays. In the Simulation tab, select ROS Toolbox > Variable Size Message to manage array sizes. If your model uses ROS messages with variable-length arrays, the following dialog box opens. Otherwise, Simulink displays a message.

Because the message properties have a variable length, it is possible that they can be truncated if they exceed the maximum size set for that array. You have the option of Truncate with warning or Truncate silently. Either way, the simulation will run, but Truncate with warning displays a warning in the Diagnostic Viewer that the message property has been truncated. When using generated code, the warning will be emitted using Log Statements in ROS. The warning will be a ROS_WARN_NAMED log statement and the name is the model name.

The Message types in model section shows all the ROS message types that are currently used by Publish, Subscribe and Blank Message blocks in your Simulink model. You have the option to use the default limits for this message type by clicking the check box. Otherwise, select each message type individually to set the Maximum length (items) of each Array Property as desired. This maximum length is applied to all instances of that message type for that model. The maximum length is also stored with the model. Therefore, it is possible to have two models accessing the same message type with different maximum length limits.

Managing the size of your variable-length arrays can help improve performance. If you limit the size of the array to only include relevant data, you can process data more effectively. However, when running these models, consider possible issues associated with truncation and what could happen to your system if some data is ignored.

Note: If you would like to know the appropriate maximum lengths for different message types. You can simulate the model and observe the sizes output in the warning. To see an example of using ROS messages and working with variable-length arrays, see Get Started with ROS in Simulink®.

See Also


Related Topics