Real-time simulation and testing is used in two ways, differing only in whether the design or the prototype is being modeled in software.
Rapid control prototyping (RCP) — Model a design with software and connect it to a physical system. In this way, you can work out the design flaws before investing in a physical prototype and uncover requirements for new applications.
Hardware-in-the-loop (HIL) simulation — Connect a physical prototype of the design to a software plant model. In this way, you can test the prototype for safety and performance without expensive downtime for the rest of the system. You can test operation and failure conditions that are difficult to replicate and substitute for unavailable parts of the system.
Real-time simulation and test requires the following basic steps.
Create a Simulink® or Stateflow® model.
Create block diagrams in Simulink by dragging blocks to your model. If possible, set model and block parameters to use a fixed-step solver and specify a sample time compatible with the real-time requirements of your model.
Simulate the model as a non-real-time application.
Simulink uses a computed time vector to step the model. After computing the outputs for a given time value, Simulink immediately repeats the computation for the next time value until it reaches the stop time.
Because the computed time vector is not connected to a physical clock, the outputs are calculated as fast as your computer can run. The elapsed time of the simulation can differ significantly from the elapsed time of the real system.
You can log simulation results for later comparison.
Configure the development and target computers.
Configure the communication method between the development and target computers.
Configure the development and target computers using:
Prepare the model for real-time execution.
Set the model Configuration Parameters to values compatible with real-time execution:
In the Code Generation pane, set
System target file to
In the Solver pane:
Set Type to
Set Fixed-step size to a step size that is compatible with the real-time requirements of your model.
Add Simulink Real-Time™ I/O blocks representing your I/O boards.
To visualize the simulation results, add real-time scope blocks. See Add Simulink Real-Time Scope Block.
Configure the build environment.
To create a real-time application that runs on the target computer, configure the build environment. The environment includes Simulink Coder™ options, Simulink Real-Time build options, and C compiler options.
Connect to physical hardware.
Install I/O modules in the target computer and connect the modules to the physical hardware.
Restart the target computer.
Restart the target computer with the Simulink Real-Time real-time kernel using:
Target computer restart button.
Build and download the real-time application.
Build and download the real-time application using:
Execute the real-time application.
Execute the real-time application under command from the development computer or by restarting the target computer in standalone mode.
The Simulink Real-Time software uses real-time resources on the target computer. Based on your sample rate, the Simulink Real-Time software uses interrupts to step the model at the sample rate. With each new interrupt, the real-time application computes the block outputs from your model.
Create real-time scopes and Simulink Real-Time Explorer instruments. Use them to acquire and display signal data from the real-time application. You can filter and group hierarchical signals in Explorer.
Scopes created by real-time scope blocks acquire data according to Simulink sample time rules. Scopes can gather data at the top level or in an enabled or triggered subsystem. Scopes created dynamically (from the MATLAB® Command Window or the API) sample at the base rate, irrespective of the sample time of their signals.
To create instrument panels, use Simulink Real-Time Explorer to create instrument panels. You can drag graphical instruments to the instrument panels, and drag signals to the instruments to display signal data.
Visualize signals using:
Tune observable parameters such as time delays, input and output amplitudes, and input and output frequencies. You can filter and group hierarchical signals in Explorer.
Simulink Real-Time does not support parameters of multiword data types.
Tune parameters using:
Prepare regression and stress tests.
Write MATLAB scripts that perform parameter sweep and extreme-value testing in a repeatable manner, accumulating results as known good data.
In addition to the basic process steps, you can be required to perform other tasks:
Visualize the model with Simulink Real-Time Explorer instruments.
Configure Simulink Real-Time Explorer with instrument panels configured with real-time scopes and with signal display and parameter tuning graphical instruments.
Run the model where the physical device runs.
Configure the real-time application to run outside MATLAB, for example in a moving vehicle. Export the Simulink Real-Time Explorer configuration as a standalone control program.
Prepare regression and product tests with Simulink Test™.
Extend the regression and stress tests to cover functionality over the full parameter range.
Integrate the model into a third-party test environment.
Use MATLAB Coder to translate MATLAB regression test scripts into C for integration into a third-party test environment.