Lesson 6 of 9 ยท about 20 minutes
The robot stops before it hits a wall. The hard part: not stopping for the floor, a shiny table, or a blip.
On an empty floor the sensor sees the floor: about 17 cm ahead, and now and then as close as 13.5. So the bumper only cares about things closer than 12 cm. Then two rules:
seen = [zone.see(distances[i], self.moved) for zone, i in zip(self.zones, MIDDLE)]
self.ahead = max(seen) if None not in seen else None
MIDDLE = (1, 3) picks the second and fourth reading. One more: if the robot
drives 4 cm at a "thing" and it comes no closer, it was the floor (the robot is tipped forward
a bit), and that cell ignores it from then on.
Both at 10: a wall, the two rules agree. Only one at 6: a chair leg, or a reflection. "Closest" stops; "both" drives on. We picked smooth driving over catching chair legs. That is a trade-off.
In remote_control.py,
SLOW_CM = 12 and BUMPER_CM = 8 set where it slows and stops, and
SURE = 3 how sure it must be. Keep SLOW_CM under where your floor shows,
or it will slow down for the floor. Lesson 3 says how to change a file on the robot.