The answersDownload the PDF
Worksheet

2.3 The depth grid

Sensing · Robot club · about 20 min

BugBotLab
NameClassDate

What this lesson is about

64 readings, 8 columns: seeing left and right, not just ahead.

Questions 7 marks in all

  1. [1 mark]The grid is 8 rows of 8, and a reading is at grid[row * 8 + col]. At what position in the list is row 2, column 5?

  2. [1 mark]Which rows of the grid look level, straight ahead?

    1. ARows 2 and 3
    2. BRows 0 and 1
    3. CRows 6 and 7
    4. DAll eight rows
  3. [1 mark]Why are the bottom rows of the grid always close readings?

    1. AThe sensor sits 3 cm above the mat, so the bottom rows see the mat a few centimetres ahead
    2. BThere is always a wall in front
    3. CThe bottom rows are broken
    4. DThe robot is always driving uphill
  4. [1 mark]Which direction does column 0 look?

    1. AAbout 20 degrees to the left
    2. BAbout 20 degrees to the right
    3. CStraight ahead
    4. DStraight down at the mat
  5. [1 mark]What does this program print?

    row = [30, 90, 60, 20]
    line = ""
    for d in row:
        line += "#" if d < 40 else ("+" if d < 80 else ".")
    print(line)
  6. [1 mark]What does this program print?

    left_side = 45
    right_side = 80
    if left_side < right_side:
        print("more room on the right")
    else:
        print("more room on the left")
  7. [1 mark]The level-row readings for columns 0 to 7 are 35, 38, 90, 120, 110, 40, 33, 30. Which way is the way through?

    1. AColumn 3, about straight ahead
    2. BColumn 0, the left edge
    3. CColumn 7, the right edge
    4. DColumn 5

The task: widest gap

There are two blocks ahead, one left and one right, with a gap between. Without moving, print clear: column <n> for the column with the largest reading in the level rows: that is the way through.

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

# 64 distances, 8 rows of 8
grid = tof_grid()
best_col = 0
best = 0
# find the column whose reading in the level rows is the largest
print("clear: column", best_col)

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

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

Challenges

  1. Print the grid picture every half second while driving slowly forward.
  2. Write column_distances() that returns the 8 per-column numbers from the level rows as a list.
  3. Steer towards the widest gap: strafe left if it is in columns 0 to 3, right if 4 to 7, then drive forward.