Log Signal Data with Outport Blocks and Simulink Real-Time Explorer

To use Simulink® Real-Time™ Explorer for signal logging, add an Outport block to your Simulink model. Activate logging on the Data Import/Export pane in the Configuration Parameters dialog box.

To access the data log that the real-time application creates when it is running on the target computer, use Real-Time Application Properties.

The example begins with the model ex_slrt_rt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_rt_osc')))). The final configured model is ex_slrt_outport_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_outport_osc')))):

The logged outputs are the signals connected to Simulink Outport blocks. The model has one Outport block, with index 1. This Outport block shows the signals leaving the block labeled Mux.

Data Logs

Simulink Real-Time stores logged data in four data logs that you can access on the development computer by using Real-Time Application Properties. In the following list, tg is the name of the SimulinkRealTime.target object that you use to communicate with the target computer.

  • tg.TimeLog — Time or T-vector, specified as a vector of double. To turn on, in the Data Import/Export pane, set the Time model parameter.

  • tg.OutputLog — Output or Y-vector, specified as a matrix. To turn on, in the Data Import/Export pane, set the Output model parameter.

  • tg.TETLog — Task-execution-time vector, specified as a vector of double. To turn on, in the Simulink Real-Time Options pane, set the Monitor Task Execution Time model parameter.

  • tg.StateLog — State or X-vector, specified as a matrix. To turn on, in the Data Import/Export pane, set the State model parameter.

Turn on logging for only the data that you are interested in.

Each Outport block has an associated column vector in tg.OutputLog. You can access the data that corresponds to a particular Outport block by specifying the column vector for that block. For example, to access the data that corresponds to Outport 2, use tg.outputlog(:,2).

To download part of the logs, use the target object method getlog.

Note

  • The data logging variables tout, xout, yout, and logsout are available only when you use Simulink to simulate the model in non-real-time.

  • You cannot use the Simulation Data Inspector to create a data log on the target computer. You can log only signals that are connected to an Outport block.

Configure the Model for Data Logging

  1. Open Configuration Parameters. On the Real-Time tab, click Hardware Settings.

  2. To allow Simulink to log signals. Select Data Import/Export > Time and select Data Import/Export > Output. These check boxes are selected by default.

  3. To plot the task execution time, select Code Generation > Simulink Real-Time Options > Monitor Task Execution Time. This check box is selected by default.

  4. To create a buffer for the signals that you are logging, set Code Generation > Simulink Real-Time Options > Signal logging buffer size in doubles to the required value.

    The default value of 100000 units is large enough for this model.

  5. Save the model as ex_slrt_outport_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_outport_osc')))). On the Simulation tab, from Save, click Save as.

Log the Data

  1. Connect to the target computer. On the Real-Time tab, toggle the Disconnected indicator to Connected.

  2. Build and download the real-time application to the target computer. On the Real-Time tab, click Run on Target.

  3. Open Simulink Real-Time Explorer. On the Real-Time tab, click Prepare > SLRT Explorer.

  4. To start execution, click the real-time application, and then on the toolbar, click the Start button .

  5. To stop execution, click the real-time application, and then on the toolbar, click the Stop button .

Download and Plot the Data

  1. Download and plot the logged times and output values from the target computer. In the Command Window, type:

    tg = slrt;
    timelog = tg.TimeLog;
    outputlog = tg.OutputLog;
    plot(timelog, outputlog)

  2. Download and plot the task execution times for the target computer. In the Command Window, type:

    tetlog = tg.TETLog;
    plot(timelog, tetlog)

    The plot shown is the result of a real-time execution.

  3. In the Command Window, type:

    tg.AvgTET
    ans =
    
      5.7528e-006

    The percentage of CPU performance is the average TET divided by the sample time.

Task execution time (TET) measures how long it takes the kernel to run for one base-rate time step. For a multirate model, use the profiler to find out what the execution time is for each rate.

See Also

|

Related Topics