| Stateflow User's Guide | ![]() |
The Bang-Bang Boiler Demo
A good model to use in furthering your study of Stateflow is the Bang-Bang Boiler demo model. This model retains the basic structure of the Stateflow diagrams used in the Getting Started guide, but adds more levels of control with other Stateflow features.
Access the Stateflow demo model Bang-Bang Boiler as follows:
sf_boiler model.
The structure of this model is similar to the model you constructed in Controlling a Physical Plant. Note the following about this model:
sec defined for the Stateflow diagram.
reference defined for the Stateflow diagram.
boiler. For each time sample, the Boiler Plant Model calculates the value of the Simulink signal digital temp, which is input to the data temp for the Bang-Bang Controller block.
The Stateflow diagram for the Bang-Bang Controller block is very similar to the diagram you build in Creating Subcharts to Add More Substates. The diagram has two states at the top level, On and Off. In addition, the state On is a subchart containing other states. Also, the diagram includes the definition of three graphical functions that are called in the Stateflow diagram.
The Bang-Bang Controller Stateflow diagram also introduces you to the following new features:
Boxes are used to group parts of the model for the sake of design modularity. Boxes add no Stateflow behavior of their own; they just group things. This means that the states On, Off, and any substates of On are designated as part of a heater. Boxes can be grouped (as Heater is) or subcharted as well. They are also part of the containment hierarchy of a diagram, as you will see.
Temporal events count events and become true only when the count reaches the specified level. For example, the temporal event trigger after(20,sec) on the transition from On to Off means that if the state On is active, Stateflow waits for 20 sec events before the transition from On to Off is taken.
An on <event> action executes only if its state is active when it receives the event <event>. In this case, if Off becomes active, and stays active for five updates from the trigger event sec, the function flash_LED is called.
Supertransitions connect a substate with a peer or superstate of the parent state. This supertransition originates with a substate of On and ends with the state Off.
warm, which is defined inside of On. Because a transition is owned by the highest member of the hierarchy that it touches, the supertransition is owned by the chart. That is why the condition is called with [Heater.On.warm()] and not just [warm()].
A supertransition from a substate to a point outside of the parent superstate executes only when the substate and the superstate are active. This means that the supertransition from NORM to Off can execute only when NORM and On are both active.
during action. During actions for a state are executed when the state is active and receives an event such as the trigger event sec. If the event does not cause an outgoing transition from the state to be taken, the during action is executed.
| Controlling a Physical Plant | Where to Go from Here | ![]() |
© 1994-2005 The MathWorks, Inc.