Live Streaming Basics: How to stream real-time signal data from Speedgoat hardware to Simulation Data Inspector (SDI) for live monitoring in R2020b and beyond?

조회 수: 20 (최근 30일)
I want to monitor and visualize signals in Simulation Data Inspector (SDI) while the real-time application is running on the Speedgoat hardware. Ideally, I'd like to dynamically add/remove signals from SDI during the simulation, without the need to rebuild the application. How can I do this in Simulink Real-Time (SLRT) R2020b and beyond?

채택된 답변

MathWorks Support Team
MathWorks Support Team 대략 8시간 전
편집: MathWorks Support Team 24분 전
There are several methods to stream signals to the Simulation Data Inspector (SDI) from Speedgoat hardware running a real-time application:
Option 1: Apply signal logging badges for default streaming
You can mark signals in your model for "permanent" streaming to SDI using signal logging badges (resembling blue WiFi symbols):
Real-time application signals that are marked for streaming are referred to as "instrumented signals".
Note that every time you add or remove a signal logging badge from a signal in your model, a rebuild of the model into a real-time application file (.mldatx) is required for the changes to take effect.
 
Option 2: Use instruments for dynamic streaming
To dynamically add or remove signals from SDI during the simulation, without rebuilding the model into a real-time application file (.mldatx) , consider the instrument-based approaches listed below: 

2.1 Instrument Buttons in Simulink Editor

Starting in R2021b, when using the "Run on Target" button in your Simulink model to start your simulation in External Mode, you can add or remove signals for live streaming to SDI by using the Add/Configure/Remove Instrument buttons in the Simulink Editor:
See Add Instruments to Real-Time Application from Simulink Model for an illustration of the workflow.

2.2 Instrument Buttons in Simulink Real-Time Explorer

When you use Simulink Real-Time Explorer to control your real-time application, you can select signals for streaming to SDI in the "Signals" panel. Click the Add Instrument and Remove Instrument (formerly "Start Streaming" and "Stop Streaming") buttons to add and remove the selected signals from SDI.
See Export and Import Signals in Instrument by Using Simulink Real-Time Explorer for an illustration of the workflow.

2.3 Instrument Objects in your MATLAB code or SLRT app

Instrument objects provide a command-line interface for adding and removing signals in SDI. You can use instrument objects in your MATLAB code or app code. See the following code example:
>> myInst = slrealtime.Instrument;
>> myInst.addSignal('mysignal'); % or myInst.addSignal('fullblockpath', portIdx)
>> tg = slrealtime;
% Start streaming to SDI - If the real-time application is already running, you will immediately see the signal in SDI.
>> tg.addInstrument(myInst);
% To stop streaming the signal, you can do the following:
>> tg.removeInstrument(myInst);
>> tg.removeAllInstruments;
The addSignal function allows you to add signals to an instrument, either by signal name, or by block name and port number. Then, use the addInstrument function to start streaming the signals in the instrument in SDI. See the Instrument Objects documentation for an overview.
Note that Simulink Real-Time Explorer has a handy 'Generate MATLAB code to create Instrument programmatically' button that will allow you to auto-generate the code needed to create your instrument object. Refer to the "Get MATLAB Code for Signals" section at: Export and Import Signals in Instrument by Using Simulink Real-Time Explorer

Considerations when using a deployed SLRT app with MATLAB Compiler:

If you design an SLRT app with App Designer, note that the SDI frontend is not available after deploying your standalone app with MATLAB Compiler. In that case, consider binding the instruments to elements in your app (e.g. Axes, EditFields) for immediate display - use the SLRT App Generator tool to facilitate this. Alternatively, you could still access the SDI backend and export and post-process the run data with slrealtime.exportRun (available from R2023a).
 

Control streaming to SDI using Start/Stop Recording API:

As an overlay to all the options mentioned above, there is an additional Start/Stop Recording API (available from R2022a) that allows you to globally control the streaming to SDI and create new runs while the simulation is running. See the following answer for more details:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Real-Time Application Instruments에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by