| Simscape™ | ![]() |
| On this page… |
|---|
About Code Generation from Simscape Models Related Simulink Code Generation Documentation |
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.
Note Code generated from Simscape models is intended for rapid prototyping and hardware-in-the-loop applications. It is not intended for use as production code in embedded controller applications. Vertical products based on Simscape platform also support code generation, with some variations and exceptions described in their respective User's Guides. Consult those User's Guides for more information. |
Consult Simulink Acceleration modes, Real-Time Workshop, and xPC Target™ documentation for general information on code generation.
Code generation has many purposes and methods. There are two essential rationales:
Compiled code versions of Simulink and Simscape models run faster than the original block diagram models. The time savings can be dramatic.
An equally important consideration for Simscape models is the stand-alone implementation of generated/compiled code. Once you convert part or all of your model to code, you can deploy the stand-alone executable program on virtually any platform, independently of MATLAB application.
Converting a model or subsystem to code also hides the original model or subsystem.
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 Task | Component or Feature |
|---|---|
| Link existing code written in C or other supported languages to Simulink models | Simulink customized blocks (S-functions) |
| Speed up Simulink simulations | Accelerator mode Rapid Accelerator mode |
| Generate stand-alone fixed-step code from Simulink models | Real-Time Workshop software |
| Generate stand-alone variable-step code from Simulink models | Real-Time Workshop Rapid Simulation Target (RSim) |
| Convert Simulink model to code and compile and run it on a target PC | Real-Time Workshop and xPC Target software |
In general, using the code generated from Simscape models is similar to using code generated from regular Simulink models. There are certain differences.
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.
Reusable subsystems in Simulink reuse code that is generated once from the subsystem. You cannot generate reusable code from subsystems containing Simscape blocks.
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.
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.
![]() | Linearizing Simscape Models | Limitations | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |