Real-Time Simulation and Testing
This workflow starts with real-time simulation and testing then leads from model creation through regression and stress testing.
Create Simulink or Stateflow Model
In the Simulink® Editor, on the Simulation tab, from New, select Model.
From the Simulink start page, select a model template or click Blank 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 Model as 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 Development and Target Computers
Prepare Model for Real-Time Execution
Set the model Configuration Parameters to values compatible with real-time execution:
On the Apps tab, click Simulink Real-Time. This selection sets the System target file model parameter to
slrealtime.tlcand sets the Type model parameter to
On the Real-Time tab, click Hardware Settings. In Configuration Parameters > Solver > Fixed-step size, select a step size that is compatible with the real-time requirements of your model.
On the Real-Time tab, click Hardware Settings. Select options for Configuration Parameters > Code Generation > Simulink Real-Time Options. These settings set the initial values for real-time application options. If needed, you can change these options for the real-time application after building the application.
Add Simulink Real-Time™ I/O blocks representing your I/O boards to the model.
To visualize the simulation results, mark signals in the model for data logging with the Simulation Data Inspector. See View Data in the Simulation Data Inspector.
Connect and Restart Target Computer
Connect the development computer to the Speedgoat target machine. Connect the IO Modules in the target computer to the physical hardware where applicable.
Restart the target computer with the Simulink Real-Time real-time RTOS by using:
Target computer restart button.
Build and Download Real-Time Application
On the Real-Time tab, toggle the Toggle target computer connection to
Connectedand click Run on Target. For more information about building and downloading the real-time application, see:
You also can build, deploy, and run the real-time applications by using in a step-by-step approach. For more information, see Execute Real-Time Application in Simulink External Mode by Using Step-by-Step Commands.
To view signal data while the real-time application runs, mark signals for logging with the Simulation Data Inspector. Use the marked signals to acquire and display signal data from the real-time application. You can group hierarchical signals for streaming to the Simulation Data Inspector by using Simulink Real-Time Explorer.
To log signal data on the target computer and view the data after the real-time application runs, insert File Log blocks and connect these to the signals for logging. After the run, the data is loaded into Simulation Data Inspector for viewing.
To view signal data in a MATLAB® instrument panel application, create an App Designer instrument panel application and connect the application to the real-time application by using a
Instrumentobject. You insert graphical instruments into the instrument panels for data display.
Visualize signals by using:
Tune observable parameters such as time delays, input and output amplitudes, and input and output frequencies.
Simulink Real-Time does not support parameters of multiword data types.
Tune parameters by 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.