In this example, a finite state machine is used to describe a simple elevator.
The control panel of the elevator contains N buttons, to select a target level. These buttons are labeled 0,...,N-1, where N is the total number of levels. In addition there is a Stop and a Go button available to stop and run the elevator. There is also a display to show the current level the elevator is on.
The elevator FSM contains the following interface elements:
|Type of interface element||Name||Type|
Upon simulation startup, the initial state S1 becomes the finite state machine’s current state. The FSM remains in state S1 until a LevelIn event occurs, to undergo a state change to S2.
State S3, as the default entrance destination of state S2, becomes the next current state and the entry action associated with state S3 is performed, that is, the TargetLevel memory is assigned the integer value of the LevelIn input port.
Possessed by state S3 are 4 transitions T2, T7, T3 and T4, where T2 and T7 are inherited transitions of a higher priority then T3 and T4.
The transitions T2, T3 and T4 are synchronous transitions and triggered immediately after S3 is entered. One of the three synchronous transitions fires, dependent on the value of the TargetLevel memory. If the value of the TargetLevel memory is unequal to the value of the CurrentLevel memory, the finite state machine goes either to state S4 or S5. If the value of the TargetLevel memory is greater than the value of the CurrentLevel memory, state S4 becomes the next current state, and its entry action is performed.
The entry action of state S4 schedules the Timer event to occur 5 time steps later than the current time. This time frame simulates the time the elevator needs to move from one level to the next. The integer value of the CurrentLevel memory is placed on the DisplayLevel output port.
Possessed by state S4 are the 3 transitions T2,T7 and T5. The synchronous transition T2 can not fire immediately, since the values of the CurrentLevel and TargetLevel memories are unequal. The finite state machine remains now in state S4 until a Timer or Stop event occurs.
In the case of a Timer event, the state S4 is exited. After the value of the CurrentLevel memory is incremented by the action associated with transition T5, state S4 is re-entered and its entry action is performed again, since transition T5 is a self transition of state S4. If now the value of the CurrentLevel memory is equal to the value of the TargetLevel memory, the synchronous transition T2 fires immediately and the states S4 and S2 are exited and state S1 is entered. In the case of a Stop event, while the elevator is in between two levels, so the FSM is either in S4 or S5, the current state and its ancestor state S2, are exited with the exit action of state S2 to cancel the current Timer event and state S6 is entered.
After a Go event, the state S6 is exited and the state, stored in the history, either S4 or S5, becomes again the current state. A new Timer event is scheduled by the entry action of either state S4 or state S5. When this new Timer event occurs, the elevator moves on, in the same direction, as before the Stop event.