Configure and Control a Real-Time Application

You can configure and control a real-time application by using the Simulink® Real-Time™ Explorer and Simulink external mode. This tutorial uses Simulink Real-Time Explorer. The model is a real-time model of a damped oscillator, ex_slrt_rt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_rt_osc')))).

Execute Real-Time Application with Simulink Real-Time Explorer

To perform this procedure, you must have already created a Simulink Real-Time boot disk and started the target computer. See Start Target Computer). This procedure begins with the real-time application ex_slrt_rt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_rt_osc')))) already downloaded to the target computer. See Build and Download Real-Time Application by Using Run on Target.

  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 pane, click the target computer icon for which you have downloaded the real-time application. On the toolbar, click the Connect button . The target computer icon turns to Connected .

  3. In the Applications pane, select the real-time application.

  4. To start execution, click the real-time application. On the toolbar, click the Start button . The application starts running.

    To view output from the real-time application, in the Simulink Editor, mark the output signal for buffered data logging. Then rebuild, load, and run the real-time application. Open the Simulation Data Inspector and view the output. In the Real-Time tab, click Data Inspector.

  5. To stop execution, click the real-time application. In the Real-Time tab, click the Stop button .

    The real-time application on the target computer stops running. The target computer displays messages like these messages.

    minimal TET: 0.0000006 at time 0.001250
    maximal TET: 0.0000013 at time 75.405500

Alternatively, you can use functions in the MATLAB Command Window to start and stop the real-time application. For more information about these functions, such as load, see SimulinkRealTime.target.

Change Stop Time and Sample Time

To observe operation of the real-time application, you can change the stop time and sample time in the real-time application configuration. You must have already downloaded the real-time application ex_slrt_rt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_rt_osc')))) to a target computer.

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

  2. In Simulink Real-Time Explorer, in the Applications pane, expand the node of the loaded real-time application.

  3. On the toolbar, click the Properties button .

  4. In the Application Configuration workspace, under the Properties arrow, enter a new value for Stop time. For example, enter inf and press Enter. The real-time application now runs until you stop it.

  5. Enter a new value for Sample Time. For example, enter 0.00010 and press Enter.

    Note

    Some blocks produce incorrect results when you change their sample time at run time. If you include such blocks in your model, the software displays a warning message during model build. To avoid incorrect results, change the sample time in the original model, and then rebuild and download the model.

  6. To start execution, click the real-time application. In Simulink Real-Time Explorer, click the Start button .

  7. To stop execution, click the real-time application. In Simulink Real-Time Explorer, click the Stop button .

If you specify a sample time that is too small, a CPU overload can occur. If a CPU overload occurs, the target object property CPUOverload changes to detected. In that case, change Fixed step size to a larger value and rebuild the model.

See Also

|

Related Topics