| Stateflow User's Guide |
 |
Simulating Event Triggers and Modified Output Data
In this section, you test the features that you add to the Controller diagram and the Simulink block of the SFcontrol2 model in the following previous sections:
It is important to test new features that you add to the model to make sure that they behave as you expect. Test the new features by simulating the Controller diagram of the SFcontrol2 model with the following steps:
- In the Simulink diagram, make sure that the Manual Switch points downward to the -1 pole. If not, double-click it to change its position.
- Choose Start from the Stateflow diagram editor Simulation menu to start simulation of the model.
- After a small delay during which the model builds, simulation of the Controller Stateflow diagram begins in the Stateflow diagram editor with the introduction of a gray background as shown.
Stateflow begins in simulation mode. The Controller diagram is active, but nothing in it is.
|

|
- In the Simulink model, double-click the Manual Switch to move it from the -1 pole to the 1 pole.
- Since
on_switch is a rising edge triggered event, the rise in signal from -1 to 1 sends an on_switch event to the Controller block. The Controller diagram responds as follows:
The on_switch event causes the Controller diagram to look for an available transition. The only available transition is the default transition. Because this transition is not guarded, it reacts to any event, and is therefore taken.
|

|
The destination state of the default transition, the state Off, is entered. Also, the data speed is set to a value of 0 as part of the entry action for the state Off. The state Off remains active until another event is sent to the Controller diagram.
|

|
- In the Simulink model, double-click the Manual Switch to move it from the 1 pole to the -1 pole.
- Since
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. Only the transition to the On state is available. However, it is guarded by an on_switch event trigger. No transition takes place and the Off state remains active.
|

|
- In the Simulink model, double-click the Manual Switch to move it from the -1 pole to the 1 pole.
- Since
on_switch is a rising edge triggered event, the rise in signal from -1 to 1 sends an on_switch event to the Controller block. The Controller diagram responds as follows:
The on_switch event causes the Controller diagram to look for an available transition. Only the transition to the On state is available. Because it is guarded by an on_switch event trigger, this transition takes place.
|

|
The Off state is exited and the On state is entered and becomes active. Also, the data speed is set to a value of 1 as part of the entry action for the state On. The state On remains active until another event is sent to the Controller diagram.
|

|
The value for speed is displayed in the Display block of the Simulink model as shown.

- In the Simulink model, double-click the Manual Switch to move it from the 1 pole to the -1 pole.
- The fall 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. Only the transition to the Off state is available. Because it is guarded by an off_switch event trigger, this transition takes place.
|

|
The On state is exited and the Off state is entered and becomes active. Also, the data speed is set to a value of 0 as part of the entry action for the state Off. The state Off remains active until another event is sent to the Controller diagram.
|

|
The value for speed is displayed in the Display block of the Simulink model as shown.

- Continue to send events by double-clicking the Manual Switch in the Simulink window to repeat the sequence in the preceding steps 5 and 6.
- Choose Stop from the graphics editor Simulation menu to stop the simulation.
- Once simulation stops, Stateflow resets the model to be editable.
| Sending Stateflow Output Data to Simulink | | Controlling with Junctions |  |
© 1994-2005 The MathWorks, Inc.