| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → SimDriveline |
| Contents | Index |
| Learn more about SimDriveline |
| On this page… |
|---|
About Code Generation from SimDriveline Models Using Code-Related Products and Features |
You can use SimDriveline software with Real-Time Workshop 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 SimDriveline models.
Code versions of SimDriveline models typically require fixed-step Simulink solvers, which are discussed previously in Improving Performance. Some SimDriveline features are restricted when you translate a model into code. See Limitations in this chapter.
Note Code generated from SimDriveline 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. SimDriveline software shares most of the same code generation features as the Simscape product. This section describes code generation features specific to SimDriveline software. Consult the Simscape documentation for general information on code generation and Physical Modeling. |
With Simulink, Real-Time Workshop, and xPC Target 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 | 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 |
| 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 SimDriveline models or subsystems, but not with Simscape software. Converting a SimDriveline subsystem to an S-function block allows you to run a model with Simulink alone.
In general, using the code generated from SimDriveline 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 SimDriveline code generation is that some SimDriveline blocks do support a limited set of tunable parameters. Consult Using Run-Time Parameters in Generated Code and Most SimDriveline Parameters Not Tunable following, as well as the SimDriveline block reference.
When SimDriveline software generates code for a model, it creates a set of code source and header files. This set includes modelname.c and modelname_data.c, containing all the model's run-time parameters. (For C++, these are .cpp files.) In addition, SimDriveline software generates two files separately that specify driveline structure and initialization procedures for the SimDriveline blocks alone.
The modelname.c file contains all the run-time parameters used in the compiled simulation. To find run-time parameters and change their values, you need to look in modelname_data.c. Once you change them, recompile the code to simulate with the new values.
Caution By default, modelname_data.c contains comments that identify run-time parameters by the names of their parent blocks. If you disable comments in your code generation, you can no longer identify run-time parameters in modelname_data.c alone. You also need to examine the associated header file, modelname.h, to identify the data structure elements containing the run-time parameters. Once you identify particular parameters, you can change their values in modelname_data.c. |
If you generate code from your SimDriveline model using the RSim target, you have an alternative way to change run-time parameters in your code by using the Real-Time Workshop rsimgetrtp function. For full information on rsimgetrtp, enter help rsimgetrtp at the command line and consult Running Rapid Simulations in the Real-Time Workshop User's Guide.
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. rsimgetrtp allows 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.
Obtain from rsimgetrtp a data structure appropriate to your model and containing the new variables. Save it as a MAT-file, for example, newrtP.mat.
Enter modelname -p 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 Iner for the value of its inertia. Originally, its value was 1. To change the value of 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
![]() | How SimDriveline Software Works | Limitations | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |