| Stateflow User's Guide |
 |
Controlling a Physical Plant
The primary use of Stateflow is to simulate the control of control objects in a physical plant. For example, you can use the Stateflow diagram you developed in Controlling Objects with Parallel Superstates, SFcontrol8, to control two fans in an attic space.
- Load the Simulink model
SFcontrol8 you save in Controlling Objects with Parallel Superstates and save it as SFcontrol9.

- Delete the Constant and Display blocks and their connections to the Controller Stateflow block.

- Add a subsystem to the right of the Controller block and name it Physical Plant.

- Double-click the subsystem to open it and program it as follows:

- The part of the model that simulates the attic air space is packaged in a single subsystem. Because it is only an example, the model uses a nonanalytical means for computing the air temperature in an attic space. The cooling value is chosen by a multiport switch that takes the value of the data speed output from the Stateflow block as an index. If speed = 2, both fans are running, and the chosen cooling rate is -.015 degrees per sample. If speed = 1, only one fan is running, and the cooling rate is -.01 degrees per sample. If speed = 0, no fans are running, and a cooling rate is .01 degrees per sample (that is, heating) is chosen.
The cooling value is further modified by a factor that depends on how close attic air temperature is to ambient air temperature. Obviously, the closer that ambient air temperature is to the attic temperature, the less cooling takes place. The amount of cooling that is finally calculated is added to a running integral sum that is the attic temperature. This temperature is fed to the output of the physical plant subsystem.
- In the top level Simulink diagram, connect the speed output port of the Controller block to the speed input port of the subsystem.

- Use a Constant block set at a value of 90 to provide input to the ambient input port of the subsystem.

- Connect the
temp output port of the subsystem to the temp input port of the Controller Stateflow block.

- This sends the temperature computed by the physical plant back to the Stateflow block to make a decision on whether the second fan should be running or not.
- Connect the
temp output port of the subsystem to a Scope block.

The physical plant model is now complete. Continue by simulating it and observing the temperature in the Scope block display as follows:

| Stateflow in Simulink | | The Bang-Bang Boiler Demo |  |
© 1994-2005 The MathWorks, Inc.