| Stateflow User's Guide |
 |
Simulating the Superstate
In this section, you test the superstate that you add to the Controller diagram of the model SFcontrol5 in Adding Superstates to Simplify Control. Test the new superstate with the following steps:
- In the Simulink diagram,
- Make sure that the Manual Switch points downward to the -1 pole.
- Set the Constant block feeding the port
temp on the Stateflow Controller block to a value of 110.
- Choose Start from the Simulink window Simulation menu to start simulation of the model and observe the following:
The Stateflow diagram updates with the first temp event and the default transition to state Off is taken.
|

|
Off is entered and stays active.
|

|
- In the Simulink model, with the Manual Switch block, send an
on_switch event to the Controller block.
The transition to the On state is taken.
|

|
The On state is entered and becomes active. The default transition to substate Lo is taken.
|

|
The Lo state is entered. Both On and its substate Lo remain active.
|

|
- In the Simulink diagram, change the value of the Constant block attached to the data
temp input port to 130.
The Stateflow diagram updates with a temp event. Both the On and Lo state test for valid outgoing transitions. Because the value of temp is changed to 130, the function Hot() returns a value of true and the transition from Lo to Hi is taken. The transition from On to Off responds only to the event off_switch and is, therefore, not taken.
|

|
The value for the data speed is set to 2 and the state Hi becomes active and stays active, along with its parent state, On.
|

|
- Alternate the value for
temp between 110 and 130 and observe the transitions from the Hi to the Lo state and from the Lo to the Hi state.
- In the Simulink diagram, use the Manual Switch block to send an
off_switch event trigger to the Stateflow block Controller.
With the broadcast of the off_switch event, the transition from On to Off is taken.
|

|
Before On is exited, its active substate, Hi, is exited and is no longer active.
|

|
On is exited and is no longer active.
|

|
Finally, the data speed is set to 0 and the state Off is entered and becomes active.
|

|
| Adding a Superstate | | Adding a History Junction to Save State |  |
© 1994-2005 The MathWorks, Inc.