This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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. Click Simulation > Model Configuration Parameters.

  2. To allow Simulink to log signals, in the Data Import/Export pane, check that the Time and Output check boxes are selected. These check boxes are selected by default.

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

  4. To create a buffer for the signals that you are logging, set Signal logging buffer size in doubles to the required value.

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

  5. From the File menu, click Save as.

    Enter ex_slrt_outport_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_outport_osc')))). Click Save.

  6. Click OK.

Log the Data

  1. In the Simulink Editor, on the toolbar, click the Build Model button .

  2. Run Simulink Real-Time Explorer (Tools > Simulink Real-Time).

  3. To connect to the target computer in the Targets pane, click the Connect button  on the toolbar.

  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