1020: Introduction to Programming Winter 2014

Assignment 5

Due: Monday March 3. 2014 at 12:00 noon.

This assignment is to be done in pairs. Each pair of students should submit only one solution, but both names must be listed in the code.

In this assignment you will create a C++ function to drive the robot following a (relatively) straight black line and detecting branches (right angle turns) coming off it. We have provided the following files:

To complete this assignment, download the above files as for previous assignments, and save them in the project directory. You must then create assign5.cpp and in it give definitions for the function described below. You must include appropriate commenting for your file and for each function.

The function you are to implement is as follows:

  1. void countIntersections(int& left, int& right)
    Image of track A function to cause the 3π to drive along a straight track, as pictured to the right, following the black line and count the branches leaving to the left and right. Once it reaches the end of the main track it should stop. Tip: to help you know what your program is doing, it is helpful if the 3π gives an audible signal when it detects each branch. You can do this using the play function. Also note that, depending on how fast the 3π is moving, it may read the sensors several times while it passes over one branch. Your code must take this into account.

While you are welcome to change the code in assign5_3pi.cpp, there are some aspects of it that are important for correct functioning. In particular, lineCalibration must be used before the sensors will function correctly. To run the test program, after you have written your countIntersections function, compiled it and downloaded it to the 3π, follow the following steps:
  1. Set the 3π down so that the sensors are approximately centered over the line at the start of the course.
  2. Press B to start the calibration. After a short pause the 3π will turn left about a half turn, then turn right twice as much, and then left again so that it ends up where it started. During this motion the line sensors must pass over the black line and on to clear white space so that they are calibrated.
  3. You may want to adjust the position of the 3π at this point so that the number displayed is about 2000.
  4. Press B again to start following the line.
  5. When your function ends the 3π will play the success song, and print the number of branches you detected on the left and right edges of the LCD and "Done." on the second line.

After you have tested your program and are confident it is right, have a TA observe your robot functioning correctly and check you off, then submit assign4.cpp using websubmit.

Last modified $LastChangedDate: 2014-02-22 18:23:58 -0330 (Sat, 22 Feb 2014) $