Stateflow User's Guide Previous page   Next Page

Entering Transition Conditions

Transitions to and from junctions are referred to as transition segments. Transitions, which, by definition, go from state to state, use transition segments to make a complete transition. The transition segments you add in Adding and Connecting Junctions define two possible destinations for the transition from Off: Hi or Lo. To know which of the two destinations to take, you need to provide a logical decision.

Use the following steps to enter conditions on the transition segments from a junction:

  1. Label the transition from the junction to the state Hi with the condition [temp >= 120] as shown.

  1. If the Off state is active and an on_switch event occurs, the transition segment to the junction is taken. Once the junction becomes active, Stateflow searches for a valid outgoing transition segment. Stateflow always gives higher priority to transitions that have conditions over other transitions that have no conditions. This means that if the temperature of the attic, temp, equals or exceeds 120 degrees, the attic fan enters the Hi state. If not, the attic fan enters the Lo state. Once the Lo or Hi state becomes active, no more transitions are taken in the diagram until another event occurs.

  1. Draw a transition from the Hi state to the Lo state and label it with the conditions [temp < 120] as shown.

  1. This transition allows the device you are controlling to transition to the Lo state when the temperature of the controlled drops below 120 degrees. Because this transition is from state to state, it requires a regular event provided by the temperature sensor event, temp_event, which occurs every second.

  1. Draw a transition from the Lo state to the Off state and label it with the event trigger off_switch as shown.

  1. The Controller needs to stop the control device if it receives an off_switch event and either the Lo or Hi state is active. The transition from Hi to Off already takes care of part of this requirement. You add a similar transition from the state Lo to the state Off with an off_switch event for the rest of the requirement.

  1. Save the current model (as SFcontrol4.mdl).

Previous page  Adding and Connecting Junctions Adding a Graphical Function for Convenience Next page

© 1994-2005 The MathWorks, Inc.