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
. to open
the model, in the matlab® command window, type:
open_system(fullfile(matlabroot, 'toolbox', 'slrealtime', ... 'examples', '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(fullfile(matlabroot, 'toolbox', 'slrealtime', ... 'examples', 'slrt_ex_osc_rt'))
transform simulink model to 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 block. this tutorial uses the 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 block to the simulink block diagram. simulink adds a new real-time block to the model.
connect the mux output to the 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(fullfile(matlabroot, 'toolbox', 'slrealtime', ... 'examples', 'slrt_ex_osc_ucf'))
set file log block parameters
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 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-listitem
.from the solver list, select a solver. for example, select the general-purpose solver
ode4 (runge-kutta)
.under solver details, in the fixed-listitem 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-listitem size value, such as
0.0002
seconds.the sample times of the model blocks can be multiples only of fixed-listitem size. if you enter
'auto'
in fixed-listitem 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
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 .
see also
| | |