Can I create new runs & discard data from SDI while running a Simulink Real-Time simulation in R2020b and beyond?

5 views (last 30 days)
I am doing iterative experiments with my Speedgoat hardware where I would like to start and stop signal monitoring during the simulation. Before 2020b, I used Target Scopes to trace & import the data, then removed the Target Scope after every iteration to clear the buffer. Target Scopes were removed in R2020b.
 
For accomplishing the same workflow in R2020b and beyond, I am trying to use instruments to start/stop streaming signals to Simulation Data Inspector (SDI) during a running simulation. However, all the data will be shown in the same run in SDI. This makes it hard to visualize the data in SDI, and I cannot clear the data from SDI between the iterations.
 
How can I achieve my desired workflow in Simulink Real-Time R2020b and beyond?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Sep 2022
Starting in R2022a, there is a new Start/Stop Recording API that creates a new SDI run while a real-time simulation is running. You could create multiple runs for each of your experiments, then delete older runs to discard the data (all while the same real-time simulation is running).  For more information, see the functions isRecordingstartRecording, and stopRecording.
From R2022b, the same functionality is available through 'Start Recording' and 'Stop Recording' buttons in Simulink Toolstrip, SLRT Explorer, and MATLAB Apps:
For more information about the file logging and streaming workflow, see Signal Logging and Streaming Basics.
As a workaround for R2020b through R2021b, it is possible to clear the data from SDI while running a real-time simulation by disconnecting the target using tg.disconnect. A new run will be created every time you disconnect and connect again with tg.connect. The code would look like this:
>> tg = slrealtime
% repeat loop
>> inst = slrealtime.Instrument
>> inst.addSignal('mysignal')
>> tg.addInstrument(inst) % start streaming
>> tg.removeInstrument(inst) % stop streaming
>> tg.removeAllInstruments
>> tg.disconnect;
% export data from SDI and clear
>> Simulink.sdi.clear
>> tg.connect
% repeat loop

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!