State Flow Transitioning Issue Delay?
12 次查看(过去 30 天)
显示 更早的评论
Hello all,
I have two state blocks, A and B. If you are in state A, you can move to state B if you meet the conditions to 'exit state A' and 'enter state B'. There is a timer delay (1s) between the states. Currently, if you can re-enter state A during the timer delay transition period, you have to wait for the 1s to finish, enter state B and then, you can re-enter state A.
Instead, I want to be able to constantly monitor the transition so that at any point during the 1s transition, if you meet the requirements to re-enter state A, you can do, and no longer need to fulfil the entire 1s.
I believe this is posisble using state flow blocks.
Thanks
2 个评论
Epsilon
2025-6-16
Hi Sam,
Does adding two transitions, one with the delay and other with the desired condition work?
Do consider attaching the model as it is difficult to discern the scenario based on the provided description.
回答(2 个)
Epsilon
2025-6-16
编辑:Epsilon
2025-6-16
Hi Sam,
It is indeed possible to have such a system in Stateflow. The two states can be just StateA and StateB. The transition condition from one state to another can be mentioned inside the square brackets(condition section) of the transition. The delays can be mentioned in the curly brackets(action section) of the transitions.
An implementation for the same could look something like this(also find the attached model):

In the above implementation whenever conditionA becomes false i.e.0 and conditionB becomes true(1) the state transitions from A to B. If the condition for A becomes true the state transitions from B to A irrespective of the condition for B thus giving a higher priority to conditionA.
For further exploration and getting started with Stateflow please refer to this documentation: https://www.mathworks.com/help/stateflow/getting-started.html
The Stateflow Onramp is also another resource that can be useful: https://matlabacademy.mathworks.com/details/stateflow-onramp/stateflow
Hope this helps!
2 个评论
Epsilon
2025-6-17
Hi Sam,
Thank you for the clarification. Please see the chart attached below and the attached file:

The chart shows a transition from StateA to StateB, with an intermediate DelayState1 state. If the conditions for StateA are met during the DelayState1 state, the system immediately returns to StateA. Otherwise, it transitions to StateB after a 1-second delay.
While in StateB, if the conditions for StateA are met again, the system transitions back to StateA after a 1-second delay. Since StateA has higher priority, checks to transition back to StateB from StateA can be skipped.
The "during" (du: as stated above) statements execute while a state is active at every timestep. Once a transition condition is met at a timestep, the system immediately moves to the next state for that transition. "Entry" and "exit" statements run only when entering or exiting a state at the timestep. Transition conditions are evaluated at each time step for the active state.
Samhitha
2025-6-16
To handle the 1-second delay when moving from state A to state B, while still checking if you need to go back to state A during that time, introduce an intermediate state let’s say, Transition. When the conditions to leave A and head toward B are met, move from A to this Transition state. In Transition, you can use after (1, sec) to trigger the move to B after the delay. At the same time, make sure you have a transition from Transitioning back to A if the conditions for returning to A come up during the wait.
Example of the state transitions:

Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stateflow Charts 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!