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

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

  2. In the Simulink® menu, select Simulation > Model Configuration Parameters.

    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 Simulink menu bar, select Code > C/C++ Code > Build Model.

    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

Was this topic helpful?