Traffic light controller

From FBSwiki
Jump to: navigation, search

A finite state machine is a model in which the states of the system are represented using a finite collection of ``modes. The dynamics of a finite state machine are given by transitions between these modes, possibly in response to external signals.

Consider a finite state machine model of a traffic light control system, as shown below.

Traffic-light.png    Traffic-fsm.png

We represent the state of the system in terms of the set of traffic lights that are turned on (either east-west or north-south). In addition, once a light is turned on it should stay that way for a certain minimum time, and then only change when a car comes up to the intersection in the opposite direction. This gives us two states for each direction of the lights: waiting for a car to arrive and waiting for the timer to expire. Thus, we have four states for the system, as show on the right of the figure above.

The dynamics for the light describe how the system transitions from one state to another. Starting at the left most state, we assume that the lights are set to allow traffic in the north-south direction. When a car arrives on the east-west street, we transition to the state at the top of the diagram, where a timer is started. Once the timer reaches the designated amount of time, we transition to the state on the right side of the diagram and turn on the lights in the east-west direction. From here we wait until a car arrives on the north-south street and continue the cycle.

Viewed as a control system, this model has a state space consisting of four discrete states: north-south waiting, north-south countdown, east-west waiting, and east-west countdown. The inputs to the controller consist of the signals that indicate whether a car is present at the roads leading up to the intersection. The outputs from the controller are the signals that change the colors of the traffic light. Finally, the dynamics of the controller are the transition diagram that controls how the states (or modes) of the system change in time.