Learning · Robot club · about 15 min
What a model gets: the sensor views as lists of numbers.
[1 mark]How many numbers are in the depth grid from tof_grid()?
[1 mark]What does this program print?
grid = list(range(64)) level = grid[16:32] print(len(level), level[0], level[-1])
16 16 31
grid[16:32] takes items 16 up to but not including 32: sixteen items, the third and fourth rows of eight.
[1 mark]Which rows of the depth grid look straight ahead, level with the robot?
[1 mark]One cell of the depth grid reads 400. What does that mean?
[1 mark]The camera image is 320 by 240 pixels, and each pixel is three numbers. How many numbers is one frame?
[1 mark]A model has only seen the depth grid with the robot facing a wall straight on. The robot turns a little. What happens to the numbers?
[1 mark]What is the name for the small set of numbers you choose to hand to a model, which still tell the situations apart?
Print the level rows' nearest and farthest readings as depth: min <cm>, max <cm>. Do not drive.
# 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() print(grid)
The hint students can ask for: Take the level rows of the depth grid (rows 2 and 3, 16 numbers) and print depth: min <cm>, max <cm>. Do not drive.
from bugbot import *
connect()
grid = tof_grid()
level = grid[16:32]
for row in range(8):
print(' '.join('%3d' % d for d in grid[row * 8: row * 8 + 8]))
print(f'depth: min {min(level)}, max {max(level)}')
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.