Documentation

Concurrent Execution on Simulink® Real-Time™

This example shows how to perform concurrent execution of a model on Simulink Real-Time. It displays the execution of each model thread using the Simulink Real-Time profiling tool.

dxpcmdsdemo runs the model with the default sample time 0.001 second.

To run the model with adjusted sample time nnn second, please type Ts = nnn before dxpcmdsdemo. For example:

Ts = 0.01;

dxpcmdsdemo;

Requirements

  1. Boot the target computer with the Simulink Real-Time real-time kernel.

  2. At the MATLAB® command prompt, type dxpcmdsdemo to download and run the model on the target computer.

Select and Open the Model

Open the model dxpcmds6t (see Figure 1). The model is mapped to 7 threads (Model1_R1, Model1_R2, Model1_R3, Model1_R4, Model2_R1, Model2_R3, and Model2_R4) running at sample times of Ts, 2*Ts, 3*Ts, 4*Ts, Ts, 3*Ts and 4*Ts respectively.

mdl='dxpcmds6t';
open_system(mdl);

Figure 1: A Model Comprised of Seven Tasks

Details in Model1

open_system([mdl, '/Model1']);

Figure 2: Four Tasks in Model1

Details in Model2

open_system([mdl, '/Model2']);

Figure 3: Three Tasks in Model2

Build, Download, and Run the Model

slrtpingtarget;
set_param(mdl,'RTWVerbose','off');
rtwbuild(mdl);
tg = slrt;
tg.load(mdl);
tg.startProfiler;
tg.start;
pause(2);
tg.stop;
### Starting Simulink Real-Time build procedure for model: dxpcmds_ref1

### Starting Simulink Real-Time build procedure for model: dxpcmds_ref2

### Starting Simulink Real-Time build procedure for model: dxpcmds6t
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Patching xml-file failed
### Successful completion of build procedure for model: dxpcmds6t
### Created MLDATX ..\dxpcmds6t.mldatx
### Looking for target: TargetPC1
### Download model onto target: TargetPC1

Display Profiling Data

The profiling data shows the execution time of each thread on a multi-core target computer

profData = tg.getProfilerData;
profData.plot;
Processing data, please wait ...
 

Figure 5: Plot of Recorded Profiling Data

Close the Model

close_system(mdl,0);
close_system('dxpcmds_ref1',0);
close_system('dxpcmds_ref2',0);
Was this topic helpful?