Mapping · University · about 25 min
What a map has to do for a robot, why a grid is the usual answer, and what a cell costs.
[1 mark]What does this program print?
CELL = 5.0 x, y = 102.4, 187.6 col = int(x / CELL) row = int(y / CELL) print(col, row) print(col * CELL + CELL / 2, row * CELL + CELL / 2)
20 37 102.5 187.5
Rounding down gives col 20 and row 37, and the centre of that cell is 5 x 20 + 2.5 = 102.5 and 5 x 37 + 2.5 = 187.5.
[1 mark]What does this program print?
CELL = 5.0 grid = [0] * 40 x = -7.0 grid[int(x / CELL)] = 1 print(grid.index(1))
39
int(-1.4) is -1, and a negative index in Python counts from the end, so a reading 7 cm off the mat marks cell 39 on the far side. That is why the bounds are checked every time.
[1 mark]Why do occupancy grids beat feature maps for planning, despite using far more memory?
[1 mark]A 200 by 200 cm mat is mapped with 1 cm cells, each stored as a 4 byte float. How many bytes does the grid need?
[1 mark]Which cell size best follows the page's rule of thumb for a robot that must fit through 20 cm gaps, with a sensor whose noise is about 2 cm?
[1 mark]Every mapping task in U8 gives the robot its true pose from the overhead camera. Why?
The robot stands at (100, 50) on the mat facing straight up it. Print cells:, how many cells a 5 cm grid needs for this mat, and hit col: and hit row:, the cell the reading ahead lands in.
from bugbot import * connect() CELL = 5.0 W = 40
The hint students can ask for: The robot stands at (100, 50) on the mat facing straight up it, so the thing it can see ahead is at y = 50 plus the reading. A cell index is a coordinate divided by the cell size, rounded down.
from bugbot import *
connect()
CELL = 5.0
W = 40 # 200 cm of mat at 5 cm a cell
print("cells:", W * W)
readings = []
for i in range(12):
readings.append(distance())
wait(0.1)
d = sum(readings) / len(readings)
# the robot stands here and faces straight up the mat, so the hit is d further up
X0, Y0 = 100.0, 50.0
hx, hy = X0, Y0 + d
print("hit col:", int(hx / CELL))
print("hit row:", int(hy / CELL))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.