Main Content

Create and Run Real-Time Application from Simulink Model

This tutorial begins with a non-real-time Simulink® model of a damped oscillator, slrt_ex_osc_nrt.

Open the Non-Real-Time Model

To open the model, in the MATLAB® Command Window, type:

open_system('slrt_ex_osc_nrt');

To complete the tutorial, you must already know how to create, configure, and simulate such a model. As you go through the tutorial, you transform slrt_ex_osc_nrt into a Simulink Real-Time™ model configured to build as a real-time application. You then build, download, and execute the real-time application on your target computer.

The final model is named slrt_ex_osc_rt. To open the model, in the MATLAB Command Window, type:

open_system('slrt_ex_osc_rt');

Transform Simulink Model to Real-Time Application

Add blocks and set configuration parameters for running a Simulink model as a real-time application.

To run a Simulink model as a real-time application under Simulink Real-Time, add and configure a real-time File Log block and set configuration parameters for code generation and target execution.

Add Simulink Real-Time File Log Block

Simulink Real-Time supports a real-time File Log block. This tutorial uses the File Log block, which logs signal data for display in the Simulation Data Inspector after the simulation run.

  1. In the MATLAB Command Window, type slrt_ex_osc_nrt. MATLAB loads the oscillator model and displays the Simulink block diagram.

  2. In Simulink Editor, from the Apps tab, click Simulink Real-Time.

  3. From the Real-Time tab Prepare section, click Library Browser.

  4. In the Simulink left pane, browse to and double-click the node Simulink Real-Time.

  5. From the list of I/O block categories, click node Logging.

  6. Click and drag the File Log block to the Simulink block diagram. Simulink adds a new real-time File Log block to the model.

  7. Connect the Mux output to the File Log block input.

  8. On the Simulation tab, from the Save button, click Save As. Enter a file name. For example, enter slrt_ex_osc_ucf, and then click OK. To open the unconfigured model slrt_ex_osc_ucf, in the MATLAB Command Window, type:

open_system('slrt_ex_osc_ucf');

Set File Log Block Parameters

File Log block parameters define the decimation for logged signals. After the simulation run, the signals that you log by using this block are available in the Simulation Data Inspector. For this tutorial, configure a File Log block.

  1. In the MATLAB Command Window, type slrt_ex_osc_ucf. MATLAB loads the oscillator model and displays the Simulink block diagram.

  2. Double-click the File Log block.

  3. In the Decimation text box, type 1. This value means that data is collected at each sample interval.

  4. Click OK, and then from the Simulation tab, click Save.

Set Configuration Parameters

The example model, slrt_ex_osc_ucf, is a non-real-time model of a damped oscillator. You enter the simulation and real-time run parameters in the Configuration Parameters dialog box. These parameters provide information to Simulink Coder™ on how to build a real-time application from the Simulink model.

After you open a Simulink model and start the target computer, you can enter the simulation parameters.

  1. In the MATLAB Command Window, type slrt_ex_osc_ucf.

  2. In Simulink Editor, from the Apps tab, click Simulink Real-Time.

  3. From the Real-Time tab, click Hardware Settings.

  4. In the Configuration Parameters dialog box, click the Solver node.

  5. In the Solver selection section, from the Type list, select Fixed-step.

  6. From the Solver list, select a solver. For example, select the general-purpose solver ode4 (Runge-Kutta).

  7. Under Solver details, in the Fixed-step size (fundamental sample time) box, enter the sample time for the real-time application. For example, enter 0.00025 seconds (250 microseconds). After creating the real-time application, you can change this value. If you find that a value overloads the CPU on the target computer, try a larger Fixed-step size value, such as 0.0002 seconds. The sample times of the model blocks can be multiples only of Fixed-step size. If you enter 'auto' in Fixed-step size, the fundamental sample time is calculated from the sample times of the model blocks.

  8. Click OK.

  9. From the Apps tab, select Simulink Real-Time. This selection configures the system target file and other model settings for Simulink Real-Time.

  10. In the Simulation tab, from the Save button, click Save As.

  11. Enter a file name. For example, enter slrt_ex_osc_rt.

Start Target Computer and Display Status Monitor

Boot the RTOS on the target computer and display the status monitor.

Starting the target computer boots the RTOS. The target computer waits for the Simulink Real-Time software to download and start a real-time application from the development computer or to start a real-time application that was previously downloaded.

After you have configured the Simulink Real-Time product by using the Simulink Real-Time Explorer, you can start the target computer and connect the development computer to the target computer. Before building the real-time application, you start the target computer. After the build process is complete, you download the real-time application to the target computer.

The status monitor application on the target computer displays status of the real-time application and other target computer status information. The target computer display supports multiple sessions. You can choose to display the status monitor (default, session 1) or display the target computer command line interface (session 2). To display the target computer status monitor:

  1. Start the target computer.

  2. The target computer displays session 1 (default) and the target computer status monitor.

To view the status monitor from the development computer, you can use PuTTY to open an SSH client and start the status monitor application /usr/target/bin/statusmonitor on the target computer.

For more information, see Target Computer Status Monitor.

Close Models

bdclose("all");

See Also

| | |

Related Topics