Log Signal Data with Outport Block and MATLAB Language

To use MATLAB® language for signal logging, add an Outport block to your Simulink® model. Activate logging by using MATLAB commands.

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 with SimulinkRealTime.target Properties

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, set the SaveTime model parameter.

  • tg.OutputLog — Output or Y-vector, specified as a matrix. To turn on, set the SaveOutput model parameter.

  • tg.TETLog — Task-execution-time vector, specified as a vector of double. To turn on, set the RL32LogTETModifier model parameter.

  • tg.StateLog — State or X-vector, specified as a matrix. To turn on, set the SaveState model parameter.

Note

The tg.TimeLog, tg.OutputLog, tg.TeTLog, and tg.StateLog properties will be removed in a future release.

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.

Data Logs with the Simulation Data Inspector and Data Profiler

The tg.TimeLog, tg.OutputLog, tg.TeTLog, and tg.StateLog properties will be removed in a future release. Consider these replacement approaches.

If using . . .

Replace with . . .

tg.TimeLog, tg.OutputLog, or tg.StateLog

Access the Simulink.sdi.Run object for a run created by logging signals of interest to the Simulation Data Inspector. From the Simulink.sdi.Run object you can get Simulink.sdi.Signal objects that you can use to view data. For example:

run = Simulink.sdi.getRun(runID);
% Get signal objects for the signals in the run
signal1 = fuelRun.getSignalByIndex(4);
signal2 = fuelRun.getSignalByIndex(9);

tg.TETLog

The Code Execution Profiling Report. Setup the profiler and then use:

profiler_object = getProfilerData(tg);

For an example, see Data Logging With Simulation Data Inspector (SDI).

Configure the Model for Data Logging

  1. Open model ex_slrt_rt_osc.

    mdl = 'ex_slrt_rt_osc';
    open_system(mdl);
  2. Check that signal data and task execution time are being logged.

    get_param(mdl,'SaveTime')
    
    ans =
    
    on
    get_param(mdl,'SaveOutput')
    
    ans =
    
    on
    get_param(mdl,'RL32LogTETModifier')
    ans =
    
    on

    These parameters are set to 'on' by default.

  3. Check that Signal logging buffer size in doubles is set to a value large enough to accommodate the number of signals that you are logging.

    get_param(mdl,'RL32LogBufSizeModifier')
    ans =
    
    100000

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

  4. Save the model under a new name.

    save_system(mdl,'ex_slrt_outport_osc');

Log the Data

  1. Build the real-time application.

    rtwbuild(mdl);
    tg = slrt('TargetPC1');
    load(tg,mdl);
  2. Set the stop time and start execution.

    tg.stoptime = 1;
    start(tg);
  3. Stop execution.

    stop(tg);

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