| Stateflow User's Guide |
 |
Simulating with a Sensor Event, Junction, and Function
In this section, you test the features that you add to the Controller diagram and the Simulink block in the SFcontrol4 model in the previous sections:
Test the new features by simulating the Controller diagram of the SFcontrol4 model 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 130.
- The Simulink diagram should have the following appearance:

The Stateflow diagram editor for the Controller block should already be open. If not, double-click the Controller block.
- Choose Start from the Simulink window Simulation menu to start simulation of the model.
The Stateflow diagram editor updates with every broadcast event. Because the temperature sensor event, temp_event, is broadcast every second, the Stateflow diagram updates and the default transition to state Off is taken.
|

|
The only outgoing transition from Off requires an on_switch event. So Off stays active until you send it that event.
|

|
- In the Simulink model, double-click the Manual Switch to move it from the -1 pole to the 1 pole.
- This sends an
on_switch event to the Controller block. The Controller diagram responds as follows:
The on_switch event causes the Controller diagram to take the transition to the junction guarded by an on_switch event trigger. The junction gives priority to the outgoing transition with a condition, which it tests. Because hot returns a value of true, it is taken.
|

|
The value for the data speed is set to 2 (see Simulink Display block) and the Hi state becomes active, and stays active.
|

|
Notice that the function hot continues to be highlighted while the Hi state is active.

This occurs because the event temp_event is broadcast to the diagram every second. When a broadcast occurs, the diagram is updated, and the Hi state looks for an outgoing transition. The only outgoing transition is guarded by the condition [!hot()]. Because hot() returns a value of true, !hot() is false, and the transition is not taken. This computation is taking place every second.
- In the Simulink diagram, change the value of the Constant block attached to the data temp input port to 110.
When the value of temp is changed to 110, hot() returns a value of false and !hot() is true. This means that the update event temp_event causes the transition to Lo to be taken.
|

|
The value for the data speed is set to 1 (see Simulink Display block) and the state Lo becomes active. It stays active because its only outgoing transition requires an off_switch event.
|

|
- In the Simulink model, double-click the Manual Switch to move it from the 1 pole to the -1 pole.
- Because
off_switch is a falling edge triggered event, the drop in signal from 1 to -1 sends an off_switch event to the Controller block. The Controller diagram responds as follows:
The off_switch event causes the Controller diagram to look for an available transition. Because the transition to the Off state requires an off_switch event, it is taken.
|

|
The value for the data speed is set to 0, and the Off state is active, and stays active, until an on_switch event occurs. This puts the model simulation back at the beginning of its behavior cycle.
|

|
| Calling a Graphical Function | | Simulating Junction Behavior |  |
© 1994-2005 The MathWorks, Inc.