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.
In the MATLAB Command Window, type
slrt_ex_osc_nrt
. MATLAB loads the oscillator model and displays the Simulink block diagram.In Simulink Editor, from the Apps tab, click Simulink Real-Time.
From the Real-Time tab Prepare section, click Library Browser.
In the Simulink left pane, browse to and double-click the node Simulink Real-Time.
From the list of I/O block categories, click node Logging.
Click and drag the File Log block to the Simulink block diagram. Simulink adds a new real-time File Log block to the model.
Connect the Mux output to the File Log block input.
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 modelslrt_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.
In the MATLAB Command Window, type
slrt_ex_osc_ucf
. MATLAB loads the oscillator model and displays the Simulink block diagram.Double-click the File Log block.
In the Decimation text box, type 1. This value means that data is collected at each sample interval.
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.
In the MATLAB Command Window, type
slrt_ex_osc_ucf
.In Simulink Editor, from the Apps tab, click Simulink Real-Time.
From the Real-Time tab, click Hardware Settings.
In the Configuration Parameters dialog box, click the Solver node.
In the Solver selection section, from the Type list, select
Fixed-step
.From the Solver list, select a solver. For example, select the general-purpose
solver ode4 (Runge-Kutta)
.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.In the Configuration Parameters dialog box, click the Code Generation node.
To build a real-time application, in the Target selection section, click Browse at the System target file list. Click
slrealtime.tlc
, and then click OK.Click OK.
In the Simulation tab, from the Save button, click Save As.
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:
Start the target computer.
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
- System Configuration
- Set Up and Configure Simulink Real-Time
- Apply Simulink Real-Time Model Template to Create Real-Time Application
- Build and Download Real-Time Application by Using Run on Target
- Execute Real-Time Application in Simulink External Mode by Using Step-by-Step Commands
- Troubleshoot Missing Real-Time Tab