This is the accompanying documentation for CDS 110 homework
#2 [pdf] problem 3.
|
Traffic light controller. |
You are to implement a traffic light controller for a standard four-way
intersection. This controller should be implemented as a MATLAB function, with
the following 4 inputs and 2 outputs:
- First input: North side vehicle sensor (number in the set {0, 1})
- Second input: South side vehicle sensor (number in the set {0, 1})
- Third input: West side vehicle sensor (number in the set {0, 1})
- Fourth input: East side vehicle sensor (number in the set {0, 1})
- First output: North-South light color (string in the set {'red','yellow',green'})
- Second output: East-West light color (string in the set {'red','yellow',green'})
Notes (read all of these!):
- A MATLAB function is a text file containing MATLAB commands which begins
with a MATLAB "function" declaration. Type "help function" at the MATLAB
command prompt for information on how to construct a MATLAB function.
- Your MATLAB function will be called every second, and you will need some
timing information for your intersection to run smoothly. Declare a variable
as "persistent" that will represent time. See "help persistent" for why you
will need to do this. Your function will be called every second, so this
variable can be treated as an integer.
- Be sure to give the cars enough time to travel through the intersection
after the light turns green, and make your yellow lights last long enough to
give fair warning to approaching cars that the light is turning red.
- You can implement your controller with a series of if-else statements or
with a "switch" statement, and/or any other means you see fit.
- The sensors in the road will not always trigger (e.g. for cars that stop short,
motorcycles, etc.), so be sure to include timeouts on your red lights so no
vehicle waits forever.
- Include comments in your code beginning with the second line which
include your name, the date, a function summary, and usage instructions. These
should display when type "help [yourfunctionname]" at the command line from
the same directory as your function.
- Test your solution before handing it in!
- Your solution should be delivered as a printout of your M-file included
with the rest of your problem set, as well as electronic delivery of your
M-file (below). Your solution will be tested against a standard traffic scenario
and graded in part on the longest wait time for vehicles at your intersection.
Electronic delivery instructions:
Mail the MATLAB file containing your solution to lars@cds.caltech.edu.
Your solution must be sent in by 5 pm on Monday, 14 October, unless you have requested
and been granted an extension.
Lars Cremean, 7 Oct 2002