Main Content

Generate ROS or ROS 2 Packages for Model Reference Hierarchy in Simulink

Model references in Simulink® enable modular development and code reuse in large components. In robotics and autonomous systems applications, using a model reference hierarchy facilitates seamless integration during parallel development efforts for perception, motion-planning, and control algorithms. During code generation and deployment of Simulink model reference hierarchies as ROS or ROS 2 packages, you can package the code in one of these ways:

  • Standalone top-level packages

  • Subdirectories under the same top level package

This table illustrates the generated source code, and library hierarchy along with the code artifacts, for the two package options on a Linux® device:

Model Reference Package OptionGenerated Source Code HierarchyGenerated Library HierarchyGenerated Code Artifacts
Standalone top-level package
  • src

    • toplevel_model_package

    • reference_model_package1

    • reference_model_package2

  • install

    • include

    • lib

      • toplevel_model_package

        • libtoplevel_model_package.a

      • libreference_model_package1.a

      • libreference_model_package2.a

Multiple TAR archives

  • toplevel_model_package.tgz

  • reference_model_package1.tgz

  • reference_model_package2.tgz

Subdirectory under same top-level package
  • src

    • toplevel_model_package

      • reference_model_package1

      • reference_model_package2

      • …..

      • src

        • CMakeLists.txt

        • package.xml

  • install

    • include

    • lib

      • toplevel_model_package

        • libtoplevel_model_package.a

        • libreference_model_package1.a

        • libreference_model_package2.a

Single TAR archive

toplevel_model_package.tgz

To configure generated ROS or ROS 2 packages for a model reference hierarchy, follow these steps:

  1. In the top-level model containing the model reference hierarchy, select the Apps tab of the Simulink Toolstrip and, in the Apps gallery, select Robot Operating System (ROS).

  2. In the dialog box, select a value for ROS Network to configure the model for ROS or ROS 2 node generation. Then, in the ROS tab of the Simulink Toolstrip, specify your network parameters.

  3. In the Prepare section, select Hardware Settings. This opens the Hardware Implementation section of the model configuration parameters.

  4. Under Hardware board settings, select Target hardware resources > Build options.

  5. Set Generate model reference code as to Standalone package or Sub-directory in same package to specify whether to generate the model reference code as a standalone package or as a subdirectory in the same top-level package.

Model reference code package options in the model settings dialog.

For more information about using model references in Simulink, see Model Reference Behavior and Capabilities (Simulink).

See Also

Topics