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:
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.
vehdyn RTDB, which ships with SimWB, corresponds to this model.
For a detailed example of this workflow, see Generate Code for Simulink Model Using MLToolkit.
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.
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.
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).
ccur_hev_vehdyn model uses buses to bundle the inputs/outputs of high-level subsystems.
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.
ccur_hev_vehdyn model uses a reference to another model,
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.
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.
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.
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.
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,
which runs at 0.000250s.)
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.
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.
vehdyn RTDB ships with three HMIs, stored in
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.
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.
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.
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.
ccur_hev_opmode models have been tested in only MATLAB 8.2
Simulink®, developed by MathWorks, is a graphical modeling environment.