Main Content

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

  1. In the Simulink® Editor, on the Simulation tab, from New, select Model.

  2. From the Simulink start page, select a model template or click Blank Model.

  3. 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

  1. Configure the communication method between the development and target computers.

  2. Configure the development and target computers by using:

Prepare Model for Real-Time Execution

  1. Set the model Configuration Parameters to values compatible with real-time execution:

    1. On the Apps tab, click Simulink Real-Time. This selection sets the System target file model parameter to slrealtime.tlc and sets the Type model parameter to Fixed-step.

    2. 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.

    3. 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.

  2. Add Simulink Real-Time™ I/O blocks representing your I/O boards to the model.

  3. To visualize the simulation results, mark signals in the model for data logging with the Simulation Data Inspector. See View Simulation Data in Simulation Data Inspector.

Connect and Restart Target Computer

  1. Connect the development computer to the Speedgoat target machine. Connect the IO Modules in the target computer to the physical hardware where applicable.

  2. Restart the target computer with the Simulink Real-Time real-time RTOS by using:

Build and Download Real-Time Application

  1. On the Real-Time tab, toggle the Toggle target computer connection to Connected and click Run on Target. For more information about building and downloading the real-time application, see:

  2. 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.

Visualize Signals

  1. 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.

  2. 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.

  3. 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 Instrument object. You insert graphical instruments into the instrument panels for data display.

  4. Visualize signals by using:

Tune Parameters

  1. Tune observable parameters such as time delays, input and output amplitudes, and input and output frequencies.

    Note

    Simulink Real-Time does not support parameters of multiword data types.

  2. 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.

Related Examples

More About