This assigment will give you the chance to practice using loops.
The slides that Ms Hogan, the lab instructor, delivered in the lab are visible in the frame to the right. If they are difficult to see, however, you can also download the slides.
In the lab, you will explore the use of looping flow control via
While doing this, you will:
In this week’s lab, you will start to use the IR sensors on your 3$\pi$ robot to make the robot navigate more reliably. In previous weeks, we have used dead reckoning: we turned the power on, waited some time and then turned the power off, hoping the robot ended up where we wanted it to. If we measured well, the robot might travel the correct distance (for instance), but we had no way to correct any drifting off-course.
This week, we will use the IR sensors on the underside of the 3$\pi$ robot in order to follow a line reliably, whether that line is straight or curved. An example of a “course” with several curved lines, one after the other, is shown to the right.
Your top-level goal for this lab is to make your robot follow a curved line until it ends.
Find the contract for the
readLineLocation() function in
Summarize its purpose and the meaning of its return value.
What values, when returned from
readLineLocation(), would indicate that
the 3$\pi$ robot is not on the line at all?
Given your answers to the previous questions, draw a flowchart for an
algorithm that could be used to keep a 3$\pi$ robot “on course”
when following a line.
Use only the
Translate your flowchart from the previous question into pseudocode.
Ensure that the code compiles and can be downloaded to your 3$\pi$ robot, even though it doesn’t yet make the robot move.
The lab4 template contains a stub (incomplete) implementation of the
This function should return
true if the line location passed to it represents
a valid sensor reading and
Complete this function using the values you identified in your prelab.
The lab4 template also contains a stub implementation of
This stub calls
readLineLocation to determine where the line is with
respect to the robot, then ignores this information.
You must complete this implementation based on your prelab.
As with the stub implementation you have been given, the robot should beep
whever it reaches the end of a line segment.
Once you have finished writing up your lab activity, submit your log book to the TAs in the lab. If you need extra time to finish the lab, you can submit your log book in the Engineering One Help Centre.