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金宝apporStateflowModel

  1. In the Simulink®Editor, on theSimulationtab, fromNew中,选择Model.

  2. From the Simulink start page, select a model template or clickBlank 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.

因为向量的计算时间是没有连接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 theAppstab, clickSimulink Real-Time. This selection sets theSystem target filemodel parameter toslrealtime.tlcand sets theTypemodel parameter toFixed-step.

    2. On theReal-Timetab, clickHardware Settings. InConfiguration Parameters>Solver>Fixed-step size中,选择a step size that is compatible with the real-time requirements of your model.

    3. On theReal-Timetab, clickHardware Settings. Select options forConfiguration 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. AddSimulink 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. SeeView Data in the 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 theSimulink Real-Timereal-time RTOS by using:

Build and Download Real-Time Application

  1. On theReal-Timetab, toggle theToggle target computer connectionto连接and clickRun 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, seeExecute 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 usingSimulink Real-TimeExplorer.

  2. To log signal data on the target computer and view the data after the real-time application runs, insertFile Logblocks 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 aInstrumentobject. 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-Timedoes 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