You can use Simscape™ Driveline™ software with Simulink® Coder™ to generate stand-alone C or C++ code from your driveline models and enhance simulation speed and portability. Certain Simulink features also make use of generated or external code. This section explains code-related tasks you can perform with your Simscape Driveline models.
Generated code versions of Simscape Driveline models typically require fixed-step Simulink solvers, which are discussed previously in Improve Performance. Some Simscape Driveline features are restricted when you generate code from a model. See Limitations in this chapter.
Note: Code generated from Simscape Driveline models is intended for rapid prototyping and hardware-in-the-loop applications. It is not intended for generating production code in embedded controller applications.
Simscape Driveline software shares most of the same code generation features as the Simscape product. This section describes code generation features specific to Simscape Driveline software. Consult the Simscape documentation for general information on code generation and Physical Modeling.
With Simulink, Simulink Coder, and Simulink Real-Time™ software, using several code-related technologies, you can 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 S-functions to generate customized blocks|
|Speed up Simulink simulations||Accelerator mode|
Rapid Accelerator mode
|Generate stand-alone fixed-step code from Simulink models||Simulink Coder software|
|Generate stand-alone variable-step code from Simulink models||Simulink Coder Rapid Simulation Target (RSim)|
|Convert Simulink model to code and compile and run it on a target PC||Simulink Coder and Simulink Real-Time software|
|Generate a block representing a Simulink model||S-function Target*|
|Generate code for designated models or subsystems||Model Reference Accelerator Mode|
* S-function Target is supported with Simscape Driveline models or subsystems, but not with Simscape software. Converting a Simscape Driveline subsystem to an S-function block allows you to run a model with Simulink alone.
In general, using the code generated from Simscape Driveline models is similar to using code generated from Simscape and normal Simulink models. The Simscape documentation discusses the differences between code generation in the Simulink and in Simscape.
The major difference between Simscape and Simscape Driveline code generation is that some Simscape Driveline blocks do support a limited set of tunable parameters. Consult Run-Time Parameters in Generated Code and Most Simscape Driveline Parameters Not Tunable.
When Simscape Driveline software generates code for a model,
it creates a set of code source and header files. This set includes
containing all the model's run-time parameters. (For C++, these are
In addition, Simscape Driveline software generates two files separately
that specify driveline structure and initialization procedures for
the Simscape Driveline blocks alone.
contains all the run-time parameters used in the compiled simulation.
To find run-time parameters and change their values, you need to look
Once you change them, recompile the code to simulate with the new
If you disable comments in your code generation, you can no
longer identify run-time parameters in
If you generate code from your Simscape Driveline model using
the RSim target, you have an alternative way to change run-time parameters
in your code by using the Simulink Coder
For full information on
rsimgetrtp at the command line.
To use this approach, the block parameters you want to change
need to be entered as workspace variable names in the corresponding
blocks. You control the block values of these parameters by changing
the values of the workspace variables.
you to propagate these changes from your workspace to the code generated
from a model without having to regenerate or recompile the code.
Change the values of the MATLAB workspace variables upon which your run-time parameter values depend.
rsimgetrtp a data structure
appropriate to your model and containing the new variables. Save it
as a MAT-file, for example,
newrtP.mat at your operating system command line to run
the generated executable with the new parameter values.
Example. Suppose an Inertia block references a workspace variable called
the value of its inertia. Originally, its value was 1. To change the
Iner to 5 in the code generated from its
model, enter at the MATLAB command line:
Iner = 5; rtP = rsimgetrtp('modelname'); save newrtP.mat rtP;
To run the generated code executable with the new value, enter at your operating system command prompt
modelname -p newrtP.mat