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')
Start 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.
In the Simulink Editor, open Simulink Real-Time Explorer. In the Real-Time tab, from the Prepare section, click SLRT Explorer.
In the Targets Tree panel, click the target computer icon for which you have downloaded the real-time application.
To connect to the target computer, click the Disconnected label. The label toggles to Connected and the target computer icon indicates connected status.
To select and load a real-time application on the target computer, click Load Application.
Click File Selector to select the application. In the dialog box that opens, select the file and click Load.
To view the contents of the real-time application on the target computer, click the Signals tab or Parameters tab.
To run the application for 10 seconds, change the Stop time value to
10.To view application signals, click Data Inspector. The Simulation Data Inspector opens.
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)The Simulation Data Inspector displays the run data for 10 seconds.
To observe the event status of the
Targetobject, 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.
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.
To change the application stop time option, enter
Infin the Stop time field.To change other application options, create an
Applicationobject. The other options are accessible as object properties. To create anApplicationobject for theslrt_ex_osc_rtapplication, in the MATLAB Command Window, type:my_app = slrealtime.Application('slrt_ex_osc_rt');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: InfChange the application option value for
file log maximum runs:my_app.Options.set("fileLogMaxRuns",4);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.
Add Signals to Instrument in Real-Time Application
Simulink Real-Time user interfaces help you visualize signals by using:
There are programmatic options for collecting signal data that do not require adding File Log blocks or marking signals for logging in the model. These options include:
You can apply the
addForFileLogfunction to add signals to an instrument in aTargetobject. The instrument transfers the signal data from the target computer to the development computer in the same manner and with the same controls (for example,AutoImportFileLogoption for thestartfunction) as when file log data is collected through a File Log block.You can apply the
addForSDIfunction to add signals to an instrument in aTargetobject. When added to aTargetobject, the instrument transfers of signal data from the target computer to the development computer in the same manner and with the same controls (for example, thestartRecordingandstopRecordingfunctions) as streaming signal data. The streaming data is available in the Simulation Data Inspector during the simulation run, and the data is not saved on the target computer.You can apply the
addForMATLABfunction to add signals to an instrument in aTargetobject. When added to aTargetobject, the instrument transfers of signal data from the target computer to the development computer in the same manner and with the same controls as streaming signal data; same as with theaddForSDIfunction. The difference is that the streaming data is accessible through apps written in MATLAB rather than being accessible through the Simulation Data Inspector.
Tip
This additional signal logging and streaming support is dynamic. You can modify signal logging and streaming selections in your real-time application without re-building your model.
These steps show how to add a signal to an instrument then add the
instrument to a Target object for
file logging.
Create a target object and connect to target computer. Open a model and configure model for target computer. Build a real-time application from the model. Create an instrument object and add a signal from real-time application.
objTarg = slrealtime; connect(objTarg); model = 'slrt_ex_osc'; openExample(model); modelSTF = getSTFName(objTarg); set_param(model,"SystemTargetFile",modelSTF); slbuild(model); mldatxname = 'slrt_ex_osc.mldatx'; objTargInst = slrealtime.Instrument(mldatxname); objTargInst.Name = 'TargetInstrument'; addSignal(objTargInst,'SigGen');
Add an instrument to the
Targetobject for file logging.addForFileLog(objTarg.Instruments,objTargInst);
Load and run the real-time application. After the simulation runs, import the file log data to the development computer and visualize signals in the Simulation Data Inspector.
See Also
Application | Target | addForFileLog | addForMATLAB | addForSDI | getAllForFileLog | getAllForMATLAB | getAllForSDI | removeAllForFileLog | removeAllForMATLAB | removeAllForSDI | removeForFileLog | removeForMATLAB | removeForSDI