The answersDownload the PDF
Worksheet

2.6 Project: the maze

Sensing · Robot club · about 25 min

BugBotLab
NameClassDate

What this lesson is about

Walls, corners and a goal. Everything in this module in one run.

Questions 7 marks in all

  1. [1 mark]Put the maze legs in order.

    Number the lines 1 to 5 to put them in the right order.

    1. Drive along the top until the right-hand wall is close
    2. Turn right
    3. Drive down the middle channel into the goal
    4. Drive up the left channel until the top wall is close
    5. Turn right again
  2. [1 mark]What does this program print?

    def drive_to_wall(gap):
        reading = 50
        while reading > gap:
            reading = reading - 10
        print("stopped at", reading)
    
    drive_to_wall(15)
  3. [1 mark]In the side-wall check, left_side is 6 cm. What does the program set sideways to, and why?

    sideways = 0
    if left_side < 8:
        sideways = 30
    elif right_side < 8:
        sideways = -30
    1. A30, to slide right, away from the left wall
    2. B-30, to slide left towards the wall
    3. C0, because the gap ahead is still big
    4. D60, to drive forward faster
  4. [1 mark]Why write one leg as drive_to_wall(gap)?

    1. AThe same few lines drive every leg, with the gap passed in
    2. BFunctions make the robot drive straighter
    3. CThe maze task will not run without a function
    4. DIt stops the robot touching the walls
  5. [1 mark]Which ideas from Module 2 does the maze use?

    Tick every answer that is true.

    1. AThe distance sensor to find walls
    2. BTurns at the corners
    3. CThe depth grid to stay off the side walls
    4. DCorrection so long runs stay straight
    5. EThe camera to read signs
  6. [1 mark]What does this program print?

    legs = [("up", 15), ("right", 15), ("down", 15)]
    for leg in legs:
        print(leg[0], "until", leg[1], "cm")
  7. [1 mark]How does the left-hand rule get a robot through a maze it has not seen?

    1. AIt always keeps the left wall close
    2. BIt always turns left at every corner, wall or not
    3. CIt remembers the whole maze first
    4. DIt drives towards the furthest reading

The task: the maze

Up the left channel, right along the top, down the middle channel into the goal, without touching either wall. Forty-five seconds.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

def drive_to_wall(gap):
    while distance() > gap:
        # drive forward at 60 (keeps going until the next command)
        forward(60)
        # pause 0.1 s (the robot keeps doing what it was told)
        wait(0.1)
    # all motors off
    stop()

drive_to_wall(15)
# turn, second leg, turn, third leg

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/2-6-project-maze/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Get through the maze in under 25 seconds.
  2. Write the maze as a list of legs [("up", 15), ("right", 15), ("down", 15)] and a loop that drives them.
  3. Make the robot solve a maze it has not seen: always keep the left wall close (the left-hand rule).