Main Content

Configure and Control Real-Time Application by Using Simulink Real-Time Explorer

You can configure and control a real-time application by using Simulink® Real-Time™ Explorer. This tutorial uses Simulink Real-Time Explorer to control the slrt_ex_osc_rt real-time application, which is a real-time model of a damped oscillator. To open the example model, in the MATLAB® Command Window, type:

openExample('slrealtime/SlrtCreateAndRunRealTimeAppFromSimulinkModelExample', ...
    'supportingFile','slrt_ex_osc_rt.slx')

Execute Real-Time Application

This procedure assumes that you have built the real-time application slrt_ex_osc_rt from the model and are ready to load on the target computer. For more information, see Execute Real-Time Application in Simulink External Mode by Using Step-by-Step Commands.

  1. In the Simulink Editor, open Simulink Real-Time Explorer. In the Real-Time tab, from the Prepare section, click SLRT Explorer.

  2. In the Targets Tree panel, click the target computer icon for which you have downloaded the real-time application.

  3. To connect to the target computer, click the Disconnected label. The label toggles to Connected and the target computer icon indicates connected status.

  4. To select and load a real-time application on the target computer, click Load Application.

  5. Click File Selector to select the application. In the dialog box that opens, select the file and click Load.

  6. To view the contents of the real-time application on the target computer, click the Signals tab or Parameters tab.

  7. To run the application for 10 seconds, change the Stop time value to 10.

  8. To view application signals, click Data Inspector. The Simulation Data Inspector opens.

  9. To run the real-time application, click Start.

    In Explorer, clicking the Start button is equivalent to executing this command for target object tg:

    start(tg, 'ReloadOnStop', true)
  10. The Simulation Data Inspector displays the run data for 10 seconds.

  11. To observe the event status of the Target object, install a listener for object events.

Alternatively, you can use functions in the MATLAB Command Window to start and stop the real-time application. For more information, see the functions for the Target object.

Change Stop Time and Other Application Options

To control the operation of the real-time application, you can change the stop time and other real-time application options by using MATLAB commands.

The real-time application slrt_ex_osc_rt is already built from the model and installed on the target computer. For more information, see Build and Download Real-Time Application by Using Run on Target.

  1. Open Simulink Real-Time Explorer. In the Real-Time tab, from the Prepare section, click SLRT Explorer. The explorer shows information for the selected target computer and loaded real-time application.

  2. To change the application stop time option, enter Inf in the Stop time field.

  3. To change other application options, create an Application object. The other options are accessible as object properties. To create an Application object for the slrt_ex_osc_rt application, in the MATLAB Command Window, type:

    my_app = slrealtime.Application('slrt_ex_osc_rt');
  4. View application options by getting the application Options property values:

    my_app.Options.get
    ans = 
    
      struct with fields:
    
          fileLogMaxRuns: 1
                loglevel: "info"
        pollingThreshold: 1.0000e-04
                stoptime: Inf
  5. Change the application option value for file log maximum runs:

    my_app.Options.set("fileLogMaxRuns",4);
  6. Save application options to a MATLAB variable. Apply options from the variable to the real-time application by using the load function:

    my_options = my_app.Options.get;
    my_app.Options.set(my_options);

Alternatively, you can use functions in the MATLAB Command Window to change the real-time application stop time, get parameter values, and set parameter values. For more information, see the functions for the Target object.

Related Topics