๐Ÿ“š Alvik lessons

Lesson 5 of 9 ยท about 20 minutes

๐Ÿ‘€ Seeing ahead

The distance sensor in the nose comes online as five blocks in front of the 3D robot. It sees a lot, and it is often wrong.

๐Ÿงฐ You need

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

โ–ถ๏ธ Do it

  1. Connect, with the robot facing a wall a little way off. Each block is one reading: it stands as far away as the sensor says. (Pretend robot: drive toward the box.)
  2. Move your hand toward the nose. The blocks come closer with it.
  3. Move your hand left to right. The sensor gives five readings side by side.
  4. Face open floor. Do the blocks go away?

No. With nothing ahead the blocks sit about 17 cm away. The sensor sees the floor there.

๐Ÿ” How it works

It is a time-of-flight sensor: it flashes invisible light and times the bounce. Five readings across the front, plus one up and one down:

left, half_left, middle, half_right, right = alvik.get_distance()
top = alvik.get_distance_top()
bottom = alvik.get_distance_bottom()

The five go to the page in an S packet. A block glides to each new reading, so a block that will not keep still means noise. Nothing past 40 cm gets a block.

The sensor has four cells side by side. middle is not a cell of its own: the robot makes it from the two beside it (half of each).

Two habits: it reads the floor at 16 to 18 cm when nothing is ahead, and a cell looking far away sometimes blips to the floor reading. Lesson 6 deals with both.

๐Ÿงช Try this

โœ๏ธ Peek with code

In Arduino Lab for MicroPython, connect, paste this, press Run, and wave your hand:

from arduino_alvik import ArduinoAlvik
from time import sleep_ms

alvik = ArduinoAlvik()
alvik.begin()

while True:
    print(alvik.get_distance())
    sleep_ms(200)

Press Stop, then restart the robot to get the menu back.