In: Electrical Engineering
What would be the state diagram of the following:
The traffic light cycle will have 5 states:
State 1: Transition into Major (NS) traffic, All lights red
State 2: Left turn signals Major are on
State 3: Major roadway straight green lights on
State 4: Transition into Country (EW) traffic, All lights red
State 5: Country roadway straight green lights on
* In-state only light are listed are not red others are red.
*Major straight-lane is green for 10 sec.
* The transition states (1 and 5) shall be activated for 0.67 sec for the next traffic.
*The country street is green for 6 sec.
*The major road left signals will on by switches which determine if a car is present either the major left-turn lane.
The signal of the switch on the Major lane is called "left". Unless mentioned otherwise, a light is assumed to be red. The two transition states (1 and 4) will be on for 0.67 sec. It is assumed that the right of way is given to left going traffic.
We must start by listing out all the states and their outputs:
State 1: Transition into Major traffic, all lights red
State 2: Major roadway time slot, major left turn green lights on
State 3: Major roadway time slot, major straight green lights on
State 4: Transition into Country traffic, all lights red
State 5: Country roadway time slot, country straight green lights on
Next we must connect states that can transition:
Next we must write down the conditions for transition:
S1 -> S2 : "(0.67 sec elapsed) and (left switch on)"
S1 -> S3 : "(0.67 sec elapsed) and (left switch off)"
S2 -> S3 : "left switch off"
S3 -> S4 : "10 sec elapsed"
S4 -> S5 : "0.67 sec elapsed"
S5 -> S1 : "6 sec elapsed"
And incorporate them into the state diagram:
Below is the program code (in Graphviz) used to draw the above diagram:
digraph finite_state_machine {
rankdir=LR;
size="8,5"
S1 [ label = "S1\nAll Red" ];
S2 [ label = "S2\nMajor Left Green" ];
S3 [ label = "S3\nMajor Straight Green" ];
S4 [ label = "S4\nAll Red" ];
S5 [ label = "S5\nCountry Straight Green" ];
node [shape = circle];
S1 -> S2 [ label = "(0.67 sec) and left" ];
S1 -> S3 [ label = "(0.67 sec) and !left" ];
S2 -> S3 [ label = "!left" ];
S3 -> S4 [ label = "10 sec" ];
S4 -> S5 [ label = "0.67 sec" ];
S5 -> S1 [ label = "6 sec" ];
}