Lesson 5 of 9 ยท about 20 minutes
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.
No. With nothing ahead the blocks sit about 17 cm away. The sensor sees the floor there.
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.
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.