๐Ÿ“š Alvik lessons

Lesson 6 of 9 ยท about 20 minutes

๐Ÿ›ก๏ธ The bumper

The robot stops before it hits a wall. The hard part: not stopping for the floor, a shiny table, or a blip.

๐Ÿงฐ You need

๐Ÿค– Open the remote ๐ŸŽฎ Pretend robot

โ–ถ๏ธ Do it

  1. Check ๐Ÿ›ก๏ธ Bumper says "on". Drive straight at a wall and keep pushing.
  2. At 12 cm it slows down: the lights blink red and the middle blocks on the screen turn yellow.
  3. At 8 cm it stops: the lights flash fast and the blocks turn red.
  4. Pull back. Reversing always works.
  5. Drive at a chair leg, a little to one side of the nose. The robot bumps into it. Why? Read on.

๐Ÿ” How it works

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:

  1. Not a blip. A cell has to see the thing in 3 new readings in a row. (The sensor makes new readings only every few trips round the loop; repeats don't count.)
  2. Both middle cells. The bumper asks the two cells in the middle: half left and half right. Both have to see the thing. One cell's stray reflection does nothing. (It does not ask the middle reading: that one is only half of each, so it says nothing new.)
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.

Closest, or both?

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.

๐Ÿงช Try this

โœ๏ธ Change it

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.