State Flow Transitioning Issue Delay?

12 次查看(过去 30 天)
Sam
Sam 2025-6-12
评论: Epsilon 2025-6-17
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
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.
Sam
Sam 2025-6-16
Hi, thanks for the comment. I have attached an example image. State A is higher priority that State B, so if at any point during State B you meet State A entry, you can enter it. But to go from A to B, you need to no longer meet A conditions AND meet the B conditions.
As you can see now the only way betwee states is through the 1s delay, i would ideally like a monitoring system that can immediately go back to the previosu state if at any point the conditions become true again.
Thank you

请先登录,再进行评论。

回答(2 个)

Epsilon
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 个评论
Sam
Sam 2025-6-16
Hi Epsilon,
Thank you for the detailed explanation, i really appreciate your help.
Although, I'm unsure if this will still work. Thus, during the delay time from state A to B, can the condition go back to state A during this delay period if A conditions are met? Or does this still wait for the delay to finalise, enter B and then re-enter A?
Is there a simpler way of doing this that is more similar to the schematic I have shown?
Thank you for your help!
Epsilon
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
Samhitha 2025-6-16
Hi @Sam,
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!

产品

Community Treasure Hunt

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

Start Hunting!

Translated by