Skip to content
Login / Sign Up

Hybrid Electric Vehicle

Demos | SIMulation Workbench

This example shows how SimWB can be used to perform HIL simulations for a complex Simulink® model of a hybrid electric vehicle (HEV). The example also highlights SimWB features such as:

Easy Code Generation

The MLToolkit GUI provides an intuitive interface for generating SimWB-compliant C code for your Simulink model. This example uses the model ccur_hev_vehdyn, which ships with the MLToolkit. This model includes the components for modeling a complex hybrid car: an internal combustion engine (ICE), an electric motor (EM) (traction motor), a Nickel-Metal-Hydride (NiMH) battery, a planetary gear, etc.

To open this model, after installing the MLToolkit, type ccur_hev_vehdyn at the MATLAB command prompt. The vehdyn RTDB, which ships with SimWB, corresponds to this model.

Generating SimWB-compliant C Code for your Simulink Model

Figure 1: Workflow to generate SimWB-compliant C Code for a Simulink Model


For a detailed example of this workflow, see Generate Code for Simulink Model Using MLToolkit.

High-Frequency, High-Fidelity Physical Modeling

SimWB provides a reliable, hard real-time platform that supports running models at high frequencies. So, you can simulate models containing high-fidelity physical components, which generally run very fast.

The ccur_hev_vehdyn model includes physical modeling blocks such as a Nickel-Metal-Hydride battery, a Permanent Magnet Synchronous Machine (traction motor), and a Universal Bridge (part of a six-step inverter). The model runs at a base sample-rate of 250 μs.
Physical Modeling Components used in ccur_hev_vehdyn

Figure 2: Physical modeling components used in ccur_hev_vehdyn


Nested Bus Support

In Simulink®, buses (composite signals) provide a way to group data and reduce model complexity. So, buses are useful for large-scale models or multi-group workflows. MLToolkit supports code generation for buses (including nested buses).

The ccur_hev_vehdyn model uses buses to bundle the inputs/outputs of high-level subsystems.
Nested output bus used in a subsystem of ccur_hev_vehdyn

Figure 3: Example of nested output bus used in ccur_hev_vehdyn


Model Reference Support

You can use model referencing in Simulink® for modular development. Other advantages of model referencing include: model protection (intellectual property), inclusion by reference, and incremental code generation. The MLToolkit supports code generation for model referencing.

The ccur_hev_vehdyn model uses a reference to another model, ccur_hev_opmode. The referenced model handles the logic for controlling the ICE and EM based on the current car speed, throttle, battery state of charge (SoC), and brake inputs.
Reference to the model ccur_hev_opmode in ccur_hev_vehdyn

Figure 4: Reference to the model ccur_hev_opmode in ccur_hev_vehdyn


Multirate Model Support

Complex models often have multiple sample rates to accurately model subsystems. Multirate models run at a base sample rate (fundamental sample rate), but slower subsystems use sample rates that are integer multiples of the base rate. The MLToolkit supports code generation for multirate models and generates threads for each discrete sample rate used in the model.

The ccur_hev_vehdyn model runs at a fundamental sample rate of 250 μs, but it has slower subsystems, too. For example, the subsystem which controls the left/right indicators runs as 1ms.
Multiple sample rates of ccur_hev_vehdyn; each sample rate translates to a process thread

Figure 5: Multiple sample rates of ccur_hev_vehdyn; each discrete sample rate translates to a process thread


Figure 5 shows the sample-time legend in Simulink to the left, which indicates five discrete sample rates in the model. To the right, you can see a snapshot of the simulation test definition in the SimWB Control Center. Each discrete sample rate in the Simulink model results in a process thread that will be run by SimWB.

Multiprocessor (Multithreaded) Simulation

When you simulate a model with multiple threads or multiple models, SimWB allows you to specify the CPU core for each thread/model. As a result, you can run simulations at very high frequencies, because the processing is distributed between the available CPU cores to optimize the run time. Also, SimWB supports CPU shielding, which ensures that the relevant CPU cores are dedicated solely to the simulation.

The example test that runs the ccur_hev_vehdyn model is called vehdyn. You can view this test using the SimWB Control Center GUI. As shown in the figure below, this test is configured to use CPU cores 2-6 for the five threads associated with the model. (CPU 2 is associated with the main model thread, ccur_hev_vehdyn_1, which runs at 0.000250s.)
Example of assigning CPU cores for each process thread/model

Figure 6: Example of assigning CPU cores for each process thread/model


Runtime Monitoring

SimWB provides the Real-Time Viewer (RT Viewer) to monitor the simulation results in real time. The RT Viewer allows you to:

  • View the RTDB variable and model parameters values in real time, using either a table or a chart (plot). You can also modify their values in real time using the RT Viewer.
  • View the run-time statistics, such as maximum/minimum run time for each process.
View RTDB variable values in real time

View simulation statistics in real time

View RTDB variable values in real time

Figure 7: RT Viewer for monitoring and controlling the simulation in real time

Human Machine Interface (HMI)

Create beautiful and sophisticated HMIs to control and monitor your simulation in real time. These HMIs can be run simultaneously from multiple remote client machines. This allows you, for example, to test a car model, with multiple groups of engineers monitoring and interacting with the test. Each group can use an HMI that is customized for their engineering needs.

SimWB provides the HMI Display Builder, which allows you to build an HMI with widgets such as gauges, sliders, plots, and tables. You can add buttons to start/stop the test session. You can also create custom SVGs, which have dynamic behavior controlled by relevant RTDB variables using JavaScript.

The vehdyn RTDB ships with three HMIs, stored in $SIMWB_ROOT$/SimGUI/HMI/displays/hev:

  • HEV Dashboard (dashboard.swbd) – Depicts the HEV car dashboard, allows you to specify the throttle and brake input, and start/stop the test session. Click on the Manual Inputs button to switch from the preset input profile to manually specified inputs.
  • HEV Car Monitor (side_panel.swbd) – Shows the top and side profiles of the car, providing information on whether the car is running and indicator status. Includes a battery status indicator.
  • HEV Test statistics (stats.swbd) – Shows the runtime for each model thread.

All HMIs are configured to run with the RunCarWithStats session of the vehdyn test. To run an HMI, in the Control Center, load the vehdyn RTDB. Click on the HMI display icon, browse to and select the HMI of interest.

Available widgets


Car Monitor

Test Statistics

Figure 7: RT Viewer for monitoring the simulation in real time

Multi-Model, Multi-Vendor Integration

You can run multiple models for a single simulation in SimWB. Suppose you have a model that describes the internal combustion engine (ICE) and another that describes the electric motor. The SimWB RTDB provides a common platform for communication between the models, allowing for a fully-integrated simulation. SimWB also gives you the flexibility to run simulations that use models from multiple vendors for a single test.


The ccur_hev_vehdyn and ccur_hev_opmode models have been tested in only MATLAB 8.2 (R2013b).

Related Links



Simulink®, developed by MathWorks, is a graphical modeling environment.

Back to top