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:
- This file contains a simple driver main that calls one of the two follow functions depending on if button A or button B is pressed following the sensor calibration. If button A is pressed then followSegment is called and the result is displayed. If button B is pressed then followTrack is called and the result is displayed. You can use it for testing your functions, although you may want to change it to help you get your program right.
- This file contains the declarations for the functions that you are to implement.
- This file contains the declarations for the functions that are defined in util3pi.cpp.
- This file contains some useful function definitions. You can call any of these functions in your implementation. Note that you are expected to be able to understand all of the code in this file at this point in the course.
To complete this assignment, download the above files as for previous
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:
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.
int followTrack(char turns, int maxTurns)
A function to cause the 3π to drive along a track, as pictured to the right, following the black line segments (using
followSegmentand 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
maxTurnsand returns that number. Once it reaches the end of the track it should stop.
Cause the 3π to turn on the spot 90 degrees to the right (clockwise).
Cause the 3π to turn on the spot 90 degrees to counter clockwise.
lineCalibrationmust 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:
- Set the 3π down so that the sensors are approximately centered over the line at the start of the course.
- 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.
- You may want to adjust the position of the 3π at this point so that the number displayed is about 2000.
- Press either A or B to start the test.
- Follow one line segment to the next intersection and report what is returned
- Follow the track until the end is detected, at which point the 3π will play the success song and display the resulting path.
- Follow one line segment to the next intersection and report what is returned by
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) $