Stateflow transition does not work when using output bus field

Hello together,
I am facing a strange behaviour of my Simulink model. That model is comprised of a Simscape subsystem and a Stateflow subsystem. The latter is used to controll the operation mode of the Simscape model.
For a clear data transfer I implemented several data buses as Stateflow inputs and outputs. For that, I created the necessary Simulink Bus Objects and it works fine so far. But when I want to use one field of the Getoperationdata bus to describe the transition condition, the transition is not exceeded despite the condition is true (as shown in the figure below). The state Empty_Pump_Chamber remains active but should switch to Empty_Complete.
The Getoperationdata bus is implemented as an output bus. When defining a transition condition with a variable from another input bus, the model succeeds. Very strange. Even when I define a local variable, set this variable equal to Getoperationaldata.emptyComplete2 and use this new variable to state the transition condition, the model succeeds. Very strange! What is wrong?
Kind Regards!

1 Comment

While trying to fix my problem I figured out, that the value (true) is just temporarily stored in the bus field ("Getoperationdata.emptyComplete2). Only during the state is active, the value is available. I tested following scenario: I used a dummy variable "a" for creating the transition. In parallel, I observed emptyComplete2 throughout simulation.
I paused the simulation right before the transition. As seen in the figure below, emptyComplete2 is true as it should be.
Right after transition, emptyComplete2 is kind of overwritten by its initial target (0 / false).
Now I guess, that Stateflow prevents the transition created with the bus field because when transition is carried out, the transition condition is not true anymore because of that observed variable reset.
Can someone explain how to change the data handling behavior and to prevent data reset while state transition?

Sign in to comment.

Answers (1)

Hello @Guillermo,
I see you're trying to use an output bus field (Getoperationdata.emptyComplete2) as a transition condition in your Stateflow chart to control the operation modes of your Simscape model.
Assuming you have the output bus configured correctly and the value does get set to "true" during state execution, I think the issue is happening because output data in Stateflow has different timing and scope than local variables.
When you set "Getoperationdata.emptyComplete2 = true" inside the "Empty_Pump_Chamber" state, that value is written to the output bus, but Stateflow may reset or flush output values as part of its execution cycle. By the time the transition condition is evaluated, the output field may already be back to its initial value (false), so the transition never fires. This explains why you see it as "true" right before the transition but "false" right after.
You could try:
1.) Use a local variable for the transition condition (which you already discovered works):
% In Empty_Pump_Chamber state:
localComplete = true;
Getoperationdata.emptyComplete2 = localComplete;
% Transition condition:
[localComplete == true]
2.) Use Data Store Memory for persistent state that needs to survive across execution cycles
3.) Check your chart's execution order settings - make sure state actions complete before transition evaluation
The key is to separate concerns: use local/persistent variables for control flow and output buses only for sending data out of the Stateflow chart to other Simulink blocks.
Let me know if this helps!

1 Comment

Thank you for your detailed answer. You exactly described what I have been looking for. Using buses in Stateflow needs to keep in mind that output data in Stateflow has different timing and scope than local variables - the output bus is reset during state transitions and therefore can not be used for transition conditions.
In my case, I changed the model architecture and defined the Getoperationdata bus as lokal bus. Now it works, even though I have another bus which is used to send data from Stateflow to Simulink, but storing this data is also necessary. Therefor, my pragmatic approach is to simply copy the data from the output bus to a local variable - not smart but I do not see any other solution.
Again, thanks a lot!

Sign in to comment.

Categories

Find more on Decision Logic in Help Center and File Exchange

Asked:

on 15 Apr 2026 at 13:44

Commented:

on 22 Apr 2026 at 14:28

Community Treasure Hunt

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

Start Hunting!