Apply Simulink Real-Time Model Template to Create Real-Time Application

This example shows how to use the Simulink Real-Time template to create a Simulink model. Starting from the model template for Simulink Real-Time provides a new model that has configuration parameters set up for building a real-time application.

To see the Simulink Real-Time commands for each operation in this example, view the example code.

Create a Simulink Model from Template

To create this model from the Simulink start page, in the MATLAB Command Window, type:

simulink

Select the Simulink Real-Time template from the start page and create the exampleSlrtApp model. Or, in the Command Window, use the Simulink.createFromTemplate command.

Add Blocks, Connections, and Data Logging to the Model

The Simulink Real-Time model template contains a Gain block that connects an inport to an outport. To make this model produce more interesting data to view on a target scope and to view with the Simulation Data Inspector (SDI), add these blocks and connections. You can use the UI for these steps or use the script commands shown:

  • Add a signal generator by using the add_block command. Use the set_param command to set its Amplitude parameter value to 4 and set its Frequency parameter value to 400.

  • Add a target scope by using the add_block command.

  • Remove the connections between the Gain block, inport, and outport by using the delete_line command.

  • Connect the signal generator to the gain block input by using the add_line command.

  • Connect the gain block output to the target scope by using the add_line command.

  • Mark the Gain block output for data logging by using the set_param command.

Build the Real-Time Application and View Logged Data

You are ready to build the real-time application, run it on the target computer, and view the logged data with these steps:

  • Make sure that the development computer has a connection to the target computer.

  • Build the model and download the real-time application to the target computer. On the Real-Time tab, click Run on Target. Or, use the rtwbuild command and the load command.

  • Run the real-time application and log data by using the start command.

  • Open the Simulation Data Inspector by double-clicking the Simulation Data Inspector icon on the Gain block output signal or by using the Simulink.sdi.view command.

More Information