Stateflow User's Guide Previous page   Next Page

Adding Event Triggers to Transitions

If you want a transition to respond only to a specific event, you specify an event trigger for the transition in its label. An event trigger limits the response of its transition to the occurrence of the named event.

In this topic, you add an event trigger to each of the transitions between the On and Off states of the Controller Stateflow diagram with the following steps:

  1. If not already loaded, load the Simulink model SFcontrol1 you build in Building an On-Off Control Model and save it as SFcontrol2.
  2. Click the transition from the state Off to the state On.
  1. The transition highlights to show that it is selected. Also, a question mark character (?) appears next to the point on the transition that you clicked as shown.

  1. Place the mouse cursor over the question mark character.
  2. When the mouse cursor changes to a text cursor, click the mouse.
  1. A blinking text cursor appears in place of the question mark, as shown.

  1. Type the text on_switch and click a location outside the transition.
  1. You should now see the following label for the transition from the state Off to the state On.

    The transition label that you entered (on_switch) is an event trigger. Event triggers are part of the syntax for transition labels. A transition event trigger watches for the event it is named after. If the event on_switch occurs and the Off state is active, the transition to the On state is taken. The transition is not taken for any other event. This provides the Stateflow diagram the ability to change the active state from the Off state to the On state when it receives a specific event that is meant to turn the device on.

  1. Click-drag the on_switch label to a point outside its transition and then click an empty part of the diagram.
  1. You can click-drag the label for a transition to any point in the Stateflow diagram to change the appearance of the diagram. If the two get separated, you can always tell what transition a label belongs to by clicking on the label. When you do, both the label and its transition become highlighted. Similarly, when you click on the transition, both the transition and its label become highlighted.

    You should now see something like the following:

  1. Use the preceding steps to label the transition from the state On to the state Off with off_switch as shown.

Event triggers control the execution of the transitions that they guard. Before you added the event triggers, the transitions from the Off to the On state and the On to the Off state take place in response to any event. Now the Stateflow diagram responds only to the events named in the event triggers.


Previous page  Guarding Transitions with Event Triggers Adding Multiple Trigger Events to a Stateflow Chart Next page

© 1994-2005 The MathWorks, Inc.