๐Ÿ“š Alvik lessons

Lesson 2 of 9 ยท about 20 minutes

๐Ÿ•น๏ธ Drive it

Drive the robot over Bluetooth, then see what the page sends: five bytes at a time.

๐Ÿงฐ You need

๐Ÿค– Open the remote ๐ŸŽฎ No robot: use the pretend one

โ–ถ๏ธ Do it

  1. On the robot, pick purple and press โœ“. Yellow lights = waiting.
  2. Press Connect and pick Alvik.
  3. Drag the joystick. A little = slow, a lot = fast.
  4. Try ๐Ÿ’ก Lights, ๐Ÿš€ Turbo and ๐Ÿชฉ Disco.
  5. Laptop: arrow keys or WASD, and 1โ€“4 for buttons.

One remote at a time. While connected, nobody else can find the robot.

๐Ÿ” How it works

Every message is a packet of five bytes (numbers 0 to 255):

!startBbutton3which one11 down, 0 up8checksum
!startJjoystickx-100 to 100y-100 to 100?checksum

The last byte is a checksum: add the first four, flip the bits. If the robot's sum doesn't match, the packet got garbled and it is thrown away.

Make a packet

The check on the robot, in remote_control.py:

pkt = buf[i:i + 5]
if (~sum(pkt[:4])) & 0xFF != pkt[4]:
    buf = buf[i + 1:]                  # damaged: look for the next '!'
    continue

๐Ÿงช Try this