// JP opened flex table

Click to See Complete Forum and Search --> : A simulation of a traffic light systems at a junction


nelum
February 3rd, 2002, 10:21 PM
Problem statement

The intersection of Hay and Williams Streets in central Perth is being revamped. The traffic in William St is one-way travelling south. Hay St is open to traffic west of William St and that traffic flows one-way namely east. Hay St east of William St is a pedestrian zone known as Hay St Mall and no traffic is permitted to enter from this intersection. Consequently the east-bound traffic in western Hay St must turn right at William St and travel in the only direction allowed in William St namely south. In addition to vehicular traffic, there are pedestrians who wish to cross the intersection.
The Town Council has decided to install traffic lights to control the traffic and pedestrian movements. These lights will be controlled by sensors in the roads, indicating a car waiting to cross, and by push buttons operated by pedestrians. The road sensors are behind the stop-lines on the northern side of the intersection across all lanes in William St and on the western side of the intersection across all lanes of Hay St. The pushbuttons are mounted on the traffic light poles in four locations. On the north-western corner of the intersection is one button for pedestrians wishing to cross either William St or Hay St. A similar button is located on the south-western corner of the intersection. Two further buttons are mounted on the eastern side of the intersection for people wishing to cross to either side of the western section of Hay St..
When a car approaches a red light it will stop and the sensor will indicate that the cycle of traffic light changes will need to advance to eventually allow the car to pass through the intersection. A car approaching a green light will continue through the intersection. When a pedestrian push button is pushed, the cycle of traffic light changes will need to advance to eventually halt all vehicular flow and indicate that pedestrian traffic can cross the intersection. The push buttons also emit one of two sounds one of which indicates no movement whilst the other indicates that crossing of the intersection is allowed.
In order to study the proposed traffic light system, the council has decided to commission the students in this unit to prepare a simulation of the intersection on a computer screen. At this stage, some simplifying assumptions have been specified such as assuming that both streets only carry one lane of traffic. Furthermore, the cycle of the traffic lights is simplified and set out below. A maximum of one car will be visible in each street at any time.

The simulation will display a representation of the intersection including the vehicles and pedestrians as well as the roads, traffic lights and surroundings (not necessarily true to life!). The simulation display will include two buttons, a clock-like display and a simulation of a push button:

·The first button will cause a vehicle to approach the intersection along Hay St and the other button will cause a pedestrian to approach the intersection. Cars travelling along William St. will appear at random intervals.
·A clock-like display will indicate state of the traffic lights as they move through the cycle of traffic light patterns. The traffic lights will stay in any given state for at least 5 seconds. After the 5 seconds and once one or more buttons have been pressed or sensors activated, the traffic lights will move to the next state The sequence of states, if all are requested, will be:
1.Pedestrians can walk and then
2.Cars in William St can proceed and then
3.Cars in Hay St can proceed and then back to 1
·A display representing the push buttons on the traffic lights will include the button, which will flash once when any button has been pressed, and a "Wait" light that will illuminate and remain illuminated until pedestrians are p

11. Create a class (or adapt an existing one) called Simulator that extends JApplet. Add the two push buttons with appropriate labels. These buttons will respectively create the pedestrians wishing to cross the intersection and the Hay St vehicles approaching the intersection;
12. Create a class (or adapt an existing one) called Intersection that extends the JPanel class. The Intersection class paintComponent method should draw an image of the intersection.
13. Create a class (or adapt an existing one) called WaitPanel that extends the JPanel class. The WaitPanel class paintComponent method should draw a rectangle containing the button that flashes when pressed and the "Wait" light.
14. Add the visual interactions so that, when the Pedestrian button on the simulator is pressed, any relevant text output appears and the WaitPanel displays a flash and the "Wait" light illuminates.
15. Create a class (or adapt an existing one) called TrafficClock that extends the JPanel class. The TrafficClock class paintComponent method should draw the clock like display indicating the progress of the traffic lights through its phases.
16. Create a class (or adapt an existing one) called TrafficLight that extends the JPanel class. The class paintComponent method should draw a small icon that represents a traffic light showing coloured segments in each direction.

dlorde
February 4th, 2002, 05:19 AM
Very interesting. What is your question?

Dave

//JP added flex table