Triggering Fixed-Length Data Capture from Infinite-Length Simulink Simulation (Real-Time)

7 visualizaciones (últimos 30 días)
I am currently using Simulink with a Real-Time Windows Target in order to control and perform tests on a hardware-in-the-loop system. The hardware device is unstable, so I have designed a simple closed-loop controller in Simulink to keep the system stable during testing. I am using a fixed-step discrete-time solver (no continuous states).
A testing period lasts about an hour, so I use the "Inf" simulation end time trick to keep the controller operating the whole time. However, I need to perform a series of 30-second data collection trials during this hour. These data capture periods must be triggered manually by a technician.
During a given data capture period, I would like to save 30-second lengths of several signals to the workspace. For now, let's say that the technician starts a data capture period by pressing a button in a GUIDE GUI. I'm familiar with making a GUI modify Simulink parameters during run-time.
While implementing this functionality is trivial using M-code or C, I'm drawing a blank as to how to do it in Simulink. It seems as though the triggered or enabled subsystem blocks could be used, but I'm unsure how to they could be "turned off" at the correct time. In particular, the (seeming) inability to code for-loops that work from time-step to time-step instead of within a single time-step is frustrating.
Is there a good way to implement this functionality in Simulink? Thanks for any help.

Respuesta aceptada

Jan Houska
Jan Houska el 13 de Oct. de 2014
This can be done by utilizing the External Mode triggering feature. In the model, just leave the Analog Input (or whatever) block outside any triggered or enabled subsystem, so that it measures the data for the whole duration of the experiment. Then, use External Mode to only log the intervals you are interested in.
To do this, go to Code, External Mode Control Panel, Signal & Triggering. There, select the Duration parameter so that it corresponds to 30 seconds - e.g., for sample rate of 1 kHz, that would be 30.000 samples, so you would set this as Duration. Then, set the Mode to one-shot, so that data logging stops and is not re-triggered after one buffer of data is collected. Finally, deselect Arm when connecting to target so that data logging does not start immediately after the model is started, and close the GUI.
Then, build and run your model, leaving the External Mode Control Panel open. Every time you want to log the data, press the Arm Trigger button and you'll get one buffer of data. If you prefer to build your own GUI instead, command-line equivalents of setting the External Mode parameters and arming the trigger do exist.
You may also want to take a look at the Data Archiving feature that allows you to automatically save the captured data buffers into MAT-files with auto-incremented names, so you don't need to take care of reading the captured buffer from workspace.
And, if you want to automate the process further, you may set External Mode to start the logging automatically when some signal crosses a specified value, and this can also include pre-trigger (start logging before the trigger event occurs). Please see the documentation for more information on that.
  2 comentarios
Cody
Cody el 13 de Oct. de 2014
Excellent, this is exactly what I was looking for! Thanks so much!
Cody
Cody el 14 de Oct. de 2014
Could you point me in the right direction for arming the trigger from the command line? The only information I've found on the topic is here, although it doesn't appear he received an answer to his question.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by