Mapping · University · about 30 min
One reading is two statements: free all the way along the ray, occupied at the end of it.
[1 mark]A mapper marks only the cell at the end of each beam as occupied. What is wrong with the map it builds?
[1 mark]Which of these is the inverse sensor model?
[1 mark]The sensor finds nothing within range and returns its maximum. How should the mapper treat that beam?
[1 mark]Why does the free marking stop one cell short of the hit?
[1 mark]What does this program print?
import math CELL = 5.0 x, y, h = 100.0, 50.0, 90.0 a, r = 0.0, 40.0 th = math.radians(h + a) hit_x = x + r * math.sin(th) hit_y = y + r * math.cos(th) print(round(hit_x, 1), round(hit_y, 1)) print(int(hit_x / CELL), int(hit_y / CELL))
140.0 50.0 28 10
Heading is clockwise from +y, so 90 degrees faces along +x: sin is 1 and cos is 0. The hit is at (140, 50), which is cell (28, 10).
[1 mark]What does this program print?
CELL = 5.0
X0, Y0 = 100.0, 50.0
d = 100.0
free = set()
r = 0.0
while r < d - CELL:
free.add((int(X0 / CELL), int((Y0 + r) / CELL)))
r += CELL / 2
print(len(free), (int(X0 / CELL), int((Y0 + d) / CELL)))
19 (20, 30)
The steps run from y = 50 to 142.5, covering rows 10 to 28, which is 19 distinct cells. Half-cell steps visit each row twice, and the set removes the repeats. The hit at y = 150 is row 30.
[1 mark]A mapper's walls come out mirrored about the diagonal of the mat, and otherwise look plausible. What is the most likely bug?
Take a reading, run the inverse sensor model along it, and print free:, the number of different cells the ray passes through, and wall y:, the mat y of the cell it ended in.
from bugbot import * connect() CELL = 5.0 X0, Y0 = 100.0, 50.0
The hint students can ask for: Step out along the ray in steps smaller than a cell, keeping the cells you land in, and stop one cell short of the reading. The cell at the reading itself is the occupied one, and its centre is half a cell above the bottom of the row.
from bugbot import *
connect()
CELL = 5.0
X0, Y0 = 100.0, 50.0
readings = []
for i in range(12):
readings.append(distance())
wait(0.1)
d = sum(readings) / len(readings)
# free all the way along the ray, stopping one cell short of the end
free = set()
r = 0.0
while r < d - CELL:
free.add((int(X0 / CELL), int((Y0 + r) / CELL)))
r += CELL / 2
print("free:", len(free))
# and occupied at the end of it
row = int((Y0 + d) / CELL)
print("wall y:", round(row * CELL + CELL / 2, 1))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.