The boolean flags never changes in finite state flow chart of state machine implementation.
Show older comments
Hello everyone,
I am working on implementing a state machine to coordinate the actions of two vehicles, SWAMP1 and SWAMP2. Here’s the intended behavior:
- Initial State (Stop)
- SWAMP1 starts at rest and sends an event (SWAMP1Ready) to indicate its readiness to SWAMP2.
- SWAMP2 receives this event, responds with its own readiness event (SWAMP2Ready), and sets its flag to true (SWAMP2Flag = true).
- Once SWAMP1 receives the event from SWAMP2, it also sets its flag to true (SWAMP1Flag = true).
2. Transition to Move
- The system transitions from Stop to Move when both flags are true (SWAMP1Flag && SWAMP2Flag) and the distance to the edge exceeds a threshold (distanceToEdge > threshold).
3. Transition to Stop
- Once the vehicles reach the edge threshold, they transition back to Stop.
4. Transition to Turn
- If both flags remain true, the system transitions from Stop to Turn.
- The vehicles continue turning until the turning angle exceeds 90 degrees (turningAngle >= 90).
5. Restart the Process
- After turning is completed, the system transitions back to Stop, and the cycle repeats.
Here is how I implemet it:
I’ve built a Stateflow chart with two parallel (AND) states, SWAMP1 and SWAMP2, each having Stop, Move, and Turn substates. I use local events (SWAMP1Ready, SWAMP2Ready) to do a handshake so that both SWAMPs set flags (SWAMP1Flag, SWAMP2Flag) to true before transitioning from Stop to Move. I’ve verified:
- The top‐level decomposition is set to Parallel (AND).
- My input signals (like distanceToEdge1) start out above the threshold (0.1).
- I’m sending SWAMP1Ready and SWAMP2Ready exactly as recommended (“on SWAMP1Ready: …”, etc.).
- SWAMP1Flag and SWAMP2Flag remain stuck at false, and both SWAMPs stay in Stop.
Despite all this, the states never leave Stop and the flags never become true. What could be causing my local events not to be recognized in the parallel state, and how can I fix this so the chart transitions correctly from Stop to Move?
Relevant details:
Classic Stateflow chart, local events, booleans cleared on entry to Stop, then set to true in the on event handler. Distance signals come from Step blocks set to values > 0.1.
Here is swampaction.m file to define the outputs and a pcture of SWAMP1 substate. You can find the simulation block in the attachment.
I would truly appreciate any insights.
Best regards
classdef swampaction < Simulink.IntEnumType
enumeration
Stop(0),
Move(1),
Turn(2)
end
methods (Static)
function defaultValue = getDefaultValue()
defaultValue = swampaction.Stop;
end
function dScope = getDataScope()
dScope = 'Auto';
end
function desc = getDescription()
desc = 'Action commands for SWAMP: Stop, Move, Turn.';
end
end
end

Accepted Answer
More Answers (0)
Categories
Find more on Syntax for States and Transitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


