Reset timer to zero after leaving a state with a transition action

11 views (last 30 days)
I am working on a Stateflow block.
In it I have a state A. In the block, the state A can transition to B, back to A, from A to C, and then back to A.
During the transition from A to B I want to reset the internal clock to zero since there were some other processes happening before but all the interesting stuff starts when going from A to B. I'm also collecting data with a sensor in real time for the entire simulation, so it would be nice to have a final output like this.
t = [0, 0.01, 0.02, ...
T, 0, 0.01, 0.02, ...
];
F = [f(0), f(0.01), f(0.02), ...
f(T), f(T+0.01), f(t+0.02), f(t+0.03),...
];
I'm trying to illustrate that even though the clock reset at t = T, that F keeps on collecting data for each time step before and after until the simulation is done.
EDIT: I forgot to describe what I've done so far.
So far I have simply grabbed the current simulation time upon entering state A for the first time. If there's no way to "restart the clock" then I was simply going to subtract it from the time. It would give some negative times in my array but it would probably work sufficiently well for my case. But I would prefer to "restart the clock".
Is there an easy way to set the clock back to zero? Any tool has to be compatible with the 2016a version of MatLab/Simulink since that's what we use in the lab.
Thanks.

Accepted Answer

Mark McBroom
Mark McBroom on 14 Jun 2021
There is no way to reset the simulation time. The approach you are using, which is to get simulation time when the state transition occurs, and then compute delta time based on this captured time and the current time is the best approach.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!