Skip to content

About

Two micro:bit robots play cat and mouse under an overhead camera (ArUco markers), driven from a web page. One-evening POC.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

Repository files navigation

micro:brawl

Two small robots, a camera on the ceiling, and a game of cat and mouse you play from a web page.

A one-evening proof of concept: two Kitronik :MOVE mini buggies driven by BBC micro:bit V1.5 boards over Bluetooth Low Energy, a Raspberry Pi 4 that runs the whole show, and ArUco markers glued on the robots so an overhead camera knows where each one is and which way it faces. Visitors join a queue, get a robot, and drive it with the arrow keys; alone, you play against an AI.

Shared as is, for information. It is a POC, not a product. The story of the evening, with diagrams: Two micro:bit robots play cat and mouse, built in one evening.

The micro:brawl interface mid-match: the sky view with both markers tracked, each robot's telemetry on either side, the ground track, the log and the Pi's status

In real life

The two :MOVE mini robots, each with its ArUco marker laid flat like a roof above the micro:bit The stand camera at table level: both robots on the white arena during an AI vs AI match

The setup: a webcam at the end of a plank above the white table, the Raspberry Pi's screen below

The robots wear their marker as a flat roof (print/mounting.svg). The overhead camera only needs to see each marker whole; the side cameras are for the show and the slow-motion replays.

How it fits together

micro:bit (MakeCode firmware) ──BLE UART 20 Hz──┐
micro:bit (MakeCode firmware) ──────────────────┤
                                                ▼
overhead camera (USB or phone MJPEG) ──►  Raspberry Pi 4  ──WebSocket + MJPEG──►  browser
side cameras (MJPEG, on demand)  ──────►  FastAPI server                         (telemetry UI)
  • firmware/ (MakeCode, TypeScript): BLE UART link, raw servo speeds, accelerometer and temperature telemetry, a 400 ms watchdog that stops the wheels. Unused BLE services are disabled: with them, a V1 micro:bit runs out of RAM (panic 020).
  • server/microbrawl/robots.py: one BLE link per robot (bleak), reconnects by itself, maps (left, right) to calibrated servo speeds.
  • server/microbrawl/vision.py: ArUco detection (OpenCV, DICT_4X4_50, ids 1 and 2), homography from four clicked corners of the table to centimetres, position, heading and speed of each robot.
  • server/microbrawl/game.py: cat and mouse referee (tag distance, roles, rounds, robots driving back to their start spots), edge guard, pause when a robot is flipped, off the table, unseen or disconnected, and a simple chase / flee AI.
  • server/microbrawl/replay.py: every camera keeps its last seconds in memory; each tag is replayed in slow motion.
  • web/: SpaceX-style telemetry page, English and French.
  • edgecam/: a tiny on-demand MJPEG streamer for an old laptop's webcam.
  • print/: the markers (A4, print at 100 %) and how to mount them as a flat roof on each robot.

Running it

  1. Build the firmware with MakeCode (cd firmware && mkc build), then scripts/flash.sh copies it to each micro:bit plugged in over USB.
  2. On the Pi: a Python venv with fastapi uvicorn bleak opencv-contrib-python-headless numpy (tested with OpenCV 5.0, bleak 3.1), then scripts/deploy.sh (set PI=user@host in an untracked local.env).
  3. Optional settings in ~/microbrawl/microbrawl.env on the Pi: MICROBRAWL_SKY (camera index or MJPEG URL), MICROBRAWL_CAMS (extra views), MICROBRAWL_ADMIN_KEY.
  4. Open http://<pi>:8080/?admin, calibrate the table by clicking its four corners, switch the robots on.

About

Two micro:bit robots play cat and mouse under an overhead camera (ArUco markers), driven from a web page. One-evening POC.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages