Lab 7

purpose | preparation | procedure

In this lab, you will teach your 3π robot to solve a maze.

In-lab presentation

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.

Purpose and Outcomes

The purpose of your lab this week is to make your 3π robot solve a maze like this one:

A maze to be solved by a 3π robot

There are several important features to note about this maze:

  • it uses the same electrical tape lines as in previous line-following lab,
  • all line segments are straights and meet at right angles and
  • the end of the maze is a large block of electrical tape (i.e., it looks like a very long “double intersection”).

Preparation

  1. Examine the definition of readSensors in engi1020.cpp. Using this code as a guide, describe how to access the value read by any individual sensor on the 3π robot.

  2. Design an algorithm for detecting whether or not the robot has reached the end of the maze. Write this algorithm down in pseudocode.

  3. Consider, design and write down an algorithm for solving a maze with a line-following robot like the 3π. Assume that you are able to call functions to:

    • ask whether or not you have reached the end of the maze or
    • follow a line segment until you reach an intersection or the end.

    You may, if you choose, find it helpful to consult the Wikipedia entry on maze solving algorithms. These algorithms all apply to the general maze-solving problem, but some (e.g., the one I’ve linked to directly) can be adapted to the sort of line maze depicted above. You may also find the following video useful as a source of inspiration:

You may find it helpful to print this PDF of a simple maze.

Procedure

Follow the procedure below in the lab. Note that you will have two weeks to complete this lab.

1. Initial setup

  1. Import the lab 7 template file (lab7.zip) just as you did in previous labs.

  2. Create a C++ source file called lab7.cpp within your project. You should put all of your implementation code in this file.

  3. Copy your implementation of the turn function from lab 3 into the new project.

  4. Create stub implementations of the followSegment, atMazeEnd and solveMaze functions. Ensure that the project compiles and can be downloaded to your 3π.

2. Implement atMazeEnd

Using the first algorithm that you designed in the Preparation section, implement the atMazeEnd function. Test it by placing the robot on the maze, on a segment that leads directly to the end-of-maze box.

3. Implement followSegment

Design and implement the followSegment function described in lab7.h. You may find it helpful to refer to your countIntersections function from lab 5 when designing the algorithm for followSegment. You may also find it helpful to examine the internals of the readSensors function in engi1020.cpp: you now have all of the array knowledge you need to understand how this function works. Test this function independently of any maze-solving functionality.

4. Implement solveMaze

Using the above functions and the second algorithms that you designed in the Preparation section, implement solveMaze.

5. Conclusion

Describe what you observed in this lab. Were there any pitfalls along the way? What did you learn?

Submit your work:

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.