2 Example: Generating the Plugin Solver Code for the Full Powertrain Model - MapleSim Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : MapleSim Toolboxes : MapleSim Connector for VI-CarRealTime : Getting Started Guide : MapleSimCRTConnectorGSG/Chapter02

2 Example: Generating the Plugin Solver Code for the Full Powertrain Model

2.1 Generating the Plugin Solver Code for the Full Powertrain Model

Preparing a Model

In this example, you will perform the steps required to generate the plugin solver code using the Full Powertrain model.

 1 Open the Full Powertrain example.
 2 Generate the MapleSim Connector for VI-CarRealTime template.
 3 Define template settings.
 4 Generate the plugin solver code.

To open the Full Powertrain example

1. In MapleSim, expand the VI-CarRealTime Examples palette.

2. Click the Full Powertrain example to open it.

To generate the MapleSim Connector for VI-CarRealTime template

 1 If you have not already done so, open the Full Powertrain example found in the VI-CarRealTime Examples palette.
 2 Click Templates ( ) in the main toolbar. The Create Attachment for FullPowertrain window appears.
 3 From the list, select the VI-CarRealTime Plugin Solver Generation template.
 4 In the Attachment field, enter Powertrain as the worksheet name.

 5 Click Create Attachment. Your MapleSim model opens in Maple, using the selected template.

To define the template settings

 1 Select the FullPowertrain1 subsystem from the Main drop-down list in the toolbar above the model diagram.

 2 Select your version of VI-CarRealTime from the VI-CarRealTime Version list.
 3 Click Load Selected Subsystem. All of the template fields are populated with information specific to the subsystem displayed in the model diagram.
 4 In the Inputs/Outputs and Parameter Management section, specify which subsystem parameters to keep as configurable parameters in the generated block. The following assignments should be made:
 • Inputs: The table below shows the appropriate input variable assignments.

Table 2.1: Input variable assignments for the Full Powertrain model.
 Input Variables Port Grouping Name Main.FullPowertrain1.Wheel_L2_Omega(t) "OUTPUT_FV_Wheel_L2_Omega" Main.FullPowertrain1.Wheel_R2_Omega(t) "OUTPUT_FV_Wheel_R2_Omega" Main.FullPowertrain1.driver_demands_throttle(t) "OUTPUT_FV_driver_demands_throttle"

 • Outputs: The table below shows the appropriate output variable assignments.

Table 2.2: Output variable assignments for the Full Powertrain model.
 Output Variables Port Grouping Name Main.FullPowertrain1.INPUT_FV_mdrv_L1(t) "INPUT_FV_mdrv_L1" Main.FullPowertrain1.INPUT_FV_mdrv_L2(t) "INPUT_FV_mdrv_L2" Main.FullPowertrain1.INPUT_FV_mdrv_R1(t) "INPUT_FV_mdrv_R1" Main.FullPowertrain1.INPUT_FV_mdrv_R2(t) "INPUT_FV_mdrv_R2" Main.FullPowertrain1.engine_max_trq(t) "INPUT_FV_engine_max_trq" Main.FullPowertrain1.engine_min_trq(t) "INPUT_FV_engine_min_trq" Main.FullPowertrain1.engine_omega(t) "INPUT_FV_engine_omega" Main.FullPowertrain1.engine_trq(t) "INPUT_FV_engine_trq" Main.FullPowertrain1.transmission_ratio(t) "INPUT_FV_transmission_ratio"

 5 In the C Code Generation Options section, set the following options:

C Code Generation Options

Setting

Solver Options

 • Fixed step solver

Euler

Optimization Options

 • Level of code optimization (0=None, 3=Full)

3

Constraint Handling Options

 • Maximum number of projection iterations
 • Error tolerance
 • Apply projection during event iterations

3

0.1e-4

Event Handling Options

 • Maximum number of event iterations
 • Width of event hysteresis band

10

0.1e-9

Baumgarte Constraint Stabilization

 • Apply Baumgarte constraint stabilization

Baserate

 • The rate at which the model runs
 • Number of internal steps

0.1e-2

1

 6 In the Generate Plugin Solver Code section of the template, specify the Target directory, the VI-CarRealTime installation directory, the Visual C++ directory, and the Model Name. The following figure gives an example of some of these settings. Note that the locations of your VI-CarRealTime installation directory and your Visual C++ directory depend on the operating system you are running (XP, Vista, or Windows 7), its version (32- or 64-bit), and the version of VI-CarRealTime.

To generate the plugin solver code

 1 Select either 32-bit or 64-bit for Target binary, depending on the version of VI-CarRealTime you have installed.
 2 Click Generate Plugin Solver Code to generate the C code source files. The C source files are created along with a batch file that you can use to compile the source files.
 3 Click Generate and Compile Plugin Solver Code to generate the C code source files and then compile them.

The generated files are stored in a subdirectory of the Target directory. The name of the subdirectory is the same as the Model Name. For example, if you entered C:\MS_CRT_models for the Target directory and FullPowertrain1 for the Model Name, then your C code files are saved in a directory called C:\MS_CRT_models\FullPowertrain1.

You can view the generated plugin solver code  files (the VI-CarRealTime Interface C Code and cMsimModel.c) in the View C Code section of the template.

Note: Generating a block may require a few minutes.

Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam