Generating Code

About Code Generation from Simscape Models

You can use Real-Time Workshop® software to generate stand-alone C or C++ code from your Physical Networks models and enhance simulation speed and portability. Certain features of Simulink software also make use of generated or external code. This section explains code-related tasks you can perform with your Simscape models.

Code versions of Simscape models typically require fixed-step Simulink solvers, which are discussed in the Simulink documentation. Some features of Simscape software are restricted when you translate a model into code. See How Simscape Code Generation Differs from Simulink following in this section, as well as Limitations.

Related Simulink Code Generation Documentation

Consult Simulink Acceleration modes, Real-Time Workshop, and xPC Target™ documentation for general information on code generation.

Reasons for Generating Code

Code generation has many purposes and methods. There are two essential rationales:

Using Code-Related Products and Features

Simulink, Real-Time Workshop, and xPC Target software, using several code-related technologies, enable you to link existing code to your models and generate code versions of your models.

Code-Related TaskComponent or Feature
Link existing code written in C or other supported languages to Simulink modelsSimulink customized blocks (S-functions)
Speed up Simulink simulationsAccelerator mode
Rapid Accelerator mode
Generate stand-alone fixed-step code from Simulink modelsReal-Time Workshop software
Generate stand-alone variable-step code from Simulink modelsReal-Time Workshop Rapid Simulation Target (RSim)
Convert Simulink model to code and compile and run it on a target PCReal-Time Workshop and xPC Target software

How Simscape Code Generation Differs from Simulink

In general, using the code generated from Simscape models is similar to using code generated from regular Simulink models. There are certain differences.

Simscape and Simulink Code Are Generated Separately

Real-Time Workshop software generates code from the Simscape blocks separately from the Simulink blocks in your model. The generated Simscape code does not pass through model.rtw or the Target Language Compiler. All the code generated from a single model resides in the same directory, however.

Simscape Code Reuse Is Not Supported

Reusable subsystems in Simulink reuse code that is generated once from the subsystem. You cannot generate reusable code from subsystems containing Simscape blocks.

Tunable Parameters Are Not Supported

A tunable parameter is a Simulink run-time parameter that you can change while the simulation is running. Simscape blocks do not support tunable parameters in either simulations or generated code.

Simscape Run-Time Parameter Inlining Ignores Global Exceptions

If you choose to enable parameter inlining for code generated from a Simscape model, the software inlines all its run-time parameters. If you choose to make some of the global Simscape block parameters exceptions to inlining, the exceptions are ignored. You can change global tunable parameters only by regenerating code from the model.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS