Simulink Variable Time Logging

6 views (last 30 days)
Fabi
Fabi on 11 Sep 2024
Commented: Fabi on 11 Sep 2024
Hi,
is it possible to get a simulink "to workspace" block to log the data with variable time steps? I have a model in which some parameters are used to send it to hardware and the testrig is basically controlled with my model. For some commands I send to the testrig it is not really useful to have the logged within the sample time I have for my model, for example some preparation steps when I change the temperature, which could take quite long. I tried to have the different sample times in a varaible in the base workspace and after the command in simulink/ stateflow is processed the variable is changed. I had the variable of the sample time in my "to workspace" block, and it seemed to work sometimes to refresh the block and it changed to a new sample time, but it kept it that way for the whole simulation. Do you have any suggestions on how I could do this or maybe a better way to do this?

Answers (1)

Paul
Paul on 11 Sep 2024
One approach ...
Put a To Workspace block with inherited sample time inside a Triggered Subsystem.
Send the data to be logged as the input to the Triggered Subsystem and connect the subsystem Inport to the To Workspace block.
Trigger the subsystem at the times at which the data is to be logged.
  3 Comments
Paul
Paul on 11 Sep 2024
The approach I proposed would only record data when the subsystem is triggered, which you can do at arbitrary times based on whatever logic is applicable to your problem.
Or, instead of a triggered subsystem, maybe an an Enabled Subsystem with a To Workspace block inside will be a solution if you want to collect data for certain stretches of the simulation but not others.
I confess I don't 100% understand how you're determining when data should be logged or not, just providing some options for how data can be logged non-periodically.
Fabi
Fabi on 11 Sep 2024
Thank you for the suggestion Paul!
The sample time is determined by my predefined testplan. you can imagine a table and this should be processed line by line. In one line it may say to change the current of a lithium-ion battery (just as an example). I want a very high logging rate to see how the battery behaves in detail. When I am changing the temperature I may want a low logging rate, as not that much happens and I only want to condition my test environment. But I still want to get some data in this phase as well. The testplan is executed within stateflow line by line. One column could be defined as the logging rate and for each line of my testplan, there could be a different rate of how I log my Data.
But nonetheless thank you!

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!