1020: Introduction to Programming Winter 2014

Assignment 6

Due: Monday March 10, 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 some C++ functions to drive the robot following a track consisting of (relatively) straight black line segments joined at (approximately) right angles and keeping track of the sequence of turns (left or right). 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 assign6.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 followSegment(bool& left, bool& right, bool& straight)
    A function to cause the 3π to drive along a straight track following the black line until it reaches an intersection (branch on left or right) or dead end and report the options available at this point. The function should adjust the position of the 3π so that, if there is a branch on the left or right and the 3π turns 90 degrees in the correct direction then it will be correctly positioned to follow the next segment. It should set left, right and straight to indicate what options are available at this point. Note: You need to work hard to ensure that this function leaves the 3π in the right position when it returns -- getting it right it will make a big difference for future assignments.
  2. int followTrack(char turns[], int maxTurns)
    Image of track A function to cause the 3π to drive along a track, as pictured to the right, following the black line segments (using followSegment and keep track of the route by adding to turns 'L' for each left turn it makes, and 'R' for each right. It counts the turns found, which should not exceed maxTurns and returns that number. Once it reaches the end of the track it should stop.
  3. void turnRight()
    Cause the 3π to turn on the spot 90 degrees to the right (clockwise).
  4. void turnLeft()
    Cause the 3π to turn on the spot 90 degrees to counter clockwise.

While you are welcome to change the code in assign6_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 functions, 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 either A or B to start the test.
    1. Follow one line segment to the next intersection and report what is returned by followSegment.
    2. Follow the track until the end is detected, at which point the 3π will play the success song and display the resulting path.

After you have tested your program and are confident it is right, submit assign6.cpp using websubmit. Do not submit your testing code.

Last modified $LastChangedDate: 2014-02-28 23:04:29 -0330 (Fri, 28 Feb 2014) $