Module 2.4
RoadWorks


A.M.D.G.


Roadworks is an alternative traffic light control system. There is only one lane of traffic and lights have been put up at either end.

Using the control table you need to allow traffic to pass through the lights without accidents.

This system also uses sensors that sense if there is traffic present or not.

On the main screen of Roadworks you have a grid containing 7 columns and 99 rows. You don’t need to use the 99 rows, but you must use all 7 columns.

From left to right the columns are:

Left light state: This is the left lights state (R for red, G for green etc).
Right light state: This is the right lights state.
Left sensor state: This is the state of the sensor on the left-hand light.
Right sensor state: This is the sensor on the right-hand light.
New Left light state: What the left light will change to when there is a match (see below).
New Right light state: What the right light will change when there is a match (see below).
Delay: The wait until the program looks for another match.

You can assign the following states:

In the Light columns :

G = Green
A = Amber
R = Red
S = amber and red

And in the sensor columns :

N = No
Y = Yes
A = Any

In the Delay column: the delay can be anything between 0 and 50 (in seconds)

Each row of the table you have defined is examined in turn. If the light states and heat sensors values match the current row of your table then the lights will change to whatever you have specified in that row. For example if you had:

Left Light State
Right Light State
Left Sensor State
Right Sensor State
New Left Light State
New Right Light State
Delay
G
R
N
Y
R
G
5

In this example: when the lights are green on the left and red on the right and there is a car on the right, but not at the left. Then this line will trigger, causing the colour of the lights to change to Red on the left, and green on the right.

If a car arrives at the left now, the next line could be:

Left Light State
Right Light State
Left Sensor State
Right Sensor State
New Left Light State
New Right Light State
Delay
R
G
Y
N
S
A
5

 

WHy is this the next line of code?

 

The new light state from the first example was....

New Left Light State
New Right Light State
R
G

this means that the next line of instruction start with...

Left Light State
Right Light State
R
G

 

It must also take account of the fact that there are no cars on the right but there are cars waiting on the left. this means that the next instruction line must also have...

 

Left Sensor State
Right Sensor State
Y
N

 

the rest of the line of code simply states what happens next hence the next line to be followed would be

 

Left Light State
Right Light State
Left Sensor State
Right Sensor State
New Left Light State
New Right Light State
Delay
R
G
Y
N
S
A
5

Each line that you add must start by matching the previous new light state and sensor state for it to be run.

When you have completed the control table start the simulation by clicking on the Start button.

Initially the lights and delay will be set to what you have specified in the first row.

Cars will come at different intervals - depending on what is selected on the Options/Traffic dialog. Cars pass at different speeds, but they will always obey follow what the light indicates. i.e. they will not wait if the light shows green and a car is already coming down the road. On the event of a crash the simulation will stop running.

 

Task 1

create a simple set of codes to let traffic through without build ups of more than 2 cars per side.

 

Task 2

change the settings - go to the options menu then traffic.

Change setting to rush hour traffic. Modify the code to stop cars building up to anymore than 3 per side.

 

Task 3

change the settings again but this time change initial car build up to 24. do not allow traffic to build up to anymore than 10 per side.