This example shows how to use Stateflow® to model a bang-bang control system that regulates the temperature of a boiler. The boiler dynamics are modeled in Simulink® in a boiler plant model.
The bang bang control logic lies within the Stateflow chart and controls when the boiler is turned on and off. Initially, the boiler is turned off through the use of the turn_boiler graphical function. Every 5 seconds, the boiler's LED flashes, again through the use of a graphical function. After 40 seconds, if the boiler is cold, the boiler is turned on. After 20 seconds, the boiler is turned off once again, and the bang bang control cycle repeats.
Note the use of absolute time temporal logic in the bang bang control logic to control the transition between the states and to periodically flash the LED. The syntax after(20,sec) means take the transition 20 seconds after the state was entered. Note that the chart does not have an input event called sec. sec is a keyword that can be used in temporal logic operators to specify delay in terms of simulation time rather than occurrences of events.
Since we cannot use the every temporal logic operator with the sec keyword, we use a "workaround" which involves an inner substate called Flash with a self-transition triggered by the condition after(5,sec). This means that the entry action of the Flash substate is performed every 5 seconds in this bang bang control system.