Main Content

Generate Code for a Multibody Model

This example shows how to configure and generate C code for a simple Simscape™ Multibody™ model. The example is based on a four-bar model named FourBarExample. The model uses a variable-step solver, ode45 (Dormand-Prince), and therefore requires the rsim target to generate code.

  1. At the MATLAB® command prompt, enter OpenExample("sm/FourBarExample").

    MATLAB software opens the four-bar example model. Save the model with a different name in a convenient folder.

  2. In the Modeling tab, click Model Settings.

    The Model Configuration Parameters window enables you to specify a code generation target and set the code generation report options for your model.

  3. In the Code Generation node of the Model Configuration Parameters window, set the System target file parameter to rsim.tlc.

    The rsim.tlc target file is compatible with Simscape Multibody models that have variable-step solvers.

  4. In the Code Generation > Report node of the Model Configuration Parameters window, check the Create code generation report check box and click OK.

    MATLAB software creates and opens a code generation report when you build your model.

  5. In the Apps tab, click Simulink Coder.

    Simulink® Coder™ software generates C code for the four-bar model. The code generation report for your model opens with a list of generated code and data files.

Related Topics