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:

Notes (read all of these!):

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. Test your solution before handing it in!

  8. 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