Best practices for stream/save simulation data to file while model is running

5 views (last 30 days)
Hi all,
I am using Simulink to develop a data collection and (very low rate) control system for a piece of experimental apparatus. While I have a complete working first prototype of this system, I have already run into some issues with how I save experimental data out of the system - including one which led to the loss of important data.
First, some background on the system:
  • My model is designed in conventional Simulink - not SLDRT or SLRT. The model runs in Normal mode, with pacing turned on, a fixed step sized of 0.5s, and for an infinite duration.
  • Generically, the model uses a LabJack T7 data acquisition interface + my slx_LJM library to measure a series of sensors and control a series of actuators. I also use Stateflow to manage the system moving between distinct states, and a fairly extensive Dashboard for monitoring and controlling the system
  • When the experimental apparatus is in normal operation, I typically start the Simulink model when I first boot up the apparatus - e.g. at the beginning of the day. Ideally, I won't stop the model until we're ready to shut down the apparatus - which could be at the end of the day, or even a few days later - because doing so prevents me from monitoring system state/controlling system actuators.
There are two primary problems that I'm facing:
  1. Save distinct "experiments" within larger model runtime: Even though my model may run for hours or even days, I'm not running an experiment for that entire duration - and consequently don't need to collect data for that entire duration. An actual "experiment" may take between a few minutes and a few hours to complete; I may run multiple experiments back-to-back, or may run an experiment --> wait an hour --> run the next experiment. Ideally, I would like to just save the data generated during these experiment phases.
  2. Save data continuously to prevent data loss: I am also concerned about preventing data loss with this system, especially because of the very long runtime of the core model. We have already experienced one failure where the method I've been using to save data out during experiments (last technique from this page) caused the system to stop instead of writing the data logs + saving the "out" variable to file. I have experimented with using the To Workspace, To File, and Record blocks; as well as saving to persistent storage, but none of these techniques save data until the simulation is paused or stopped normally. I would like to find a technique for directly logging experiment data to disk as the model runs, so that I a) never have to stop the model, and b) don't have to worry about data loss.
I'd appreciate any and all guidance on how I can address these challenges! Right now, my feeling from what I've read is that I need to re-architect my system to separate control (talking to LabJack --> read sensors, drive actuators) from command (set output states, start and end "experiments," save data to file). I'm thinking maybe a Simulink model running for the controller, and then a MATLAB App Designer app for the command interface...but that's a giant project, and if there are faster and easier workarounds to address the two problems I've described, I'd love to hear them.
Thank you all for your help! Looking forward to hearing your thoughts.

Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!