Inspiration

Drones, delivery robots and cars need to get out of the way of things coming at them. Most do it with cameras and large AI models, which cost a lot to run and can react too late. A fruit fly handles the same problem with a few thousand neurons, and it's gone before your swatter lands.

In 2024 the FlyWire project mapped every neuron in the fruit fly brain, including the circuit behind that escape. We wanted to know if that circuit, copied from the data, could work as a reflex in a machine. A game gave us the best test we could think of, because you get to swing at it yourself.

What it does

  • The fly runs on its real brain. 2,264 neurons from the fruit fly connectome decide in about 15 ms whether it flees and which way it goes.
  • It sees and hears. The swatter coming at it sets off the reflex, and so does breaking glass nearby.
  • It learns to ignore false alarms. Fake a few swings and its reaction weakens, like a real fly that stops flinching at threats that never land. Tire it out first and your real swing has a better chance.
  • You hunt it in your own room. Scan a room with a LiDAR iPhone and the game rebuilds it in Unity with the lights off. You track the fly by its buzz, a flashlight and a sonar ping.
  • You swing a real swatter. A motion sensor (ESP32-S3 + LSM6DSOX) inside it streams your swings to the game.
  • Misses cost money. Each smashed prop adds to a damage bill, and a Tiger Data leaderboard ranks the cleanest, fastest rounds.
  • You can change the setting to the original house, a medieval chamber or a space station.

How we built it

  • Fly brain (Python + NumPy). We pulled the escape circuit out of the FlyWire data and simulated it with the neuron models published by Shiu et al. in 2024. We gave each decision a 200 ms deadline, the way safety software works. If the brain misses two in a row, a backup takes over and the fly keeps reacting. We built it to run on a Raspberry Pi.
  • LiDAR pipeline (Python). Our scripts turn a Polycam scan into the room's mesh and a map of walls, furniture and landing spots.
  • Game (Unity 6, C#). We built the dark room in Unity, with failing lights, breakable props and synthesised sound.
  • Swatter. An ESP32 streams motion data to a hub that detects swings. We also wrote a tool to record swings and train a small model to recognise them.
  • Leaderboard. We log rounds and swings to Tiger Data and rank players from that table.

Challenges we ran into

  • The fly couldn't tell left from right. In the real wiring, both Giant Fibers (the neurons that fire the jump) respond more to the right side. We let three other escape neurons, which do respond by side, pick the direction.
  • One ear is much weaker than the other in the data. We raised its input until both sides reacted the same.
  • Our first version of false-alarm tuning made a fresh fly sluggish too. A short delay before the fatigue starts fixed it.
  • Windows slowed us down. Its timers added about 8 ms of lag to each decision until we asked the OS for 1 ms timing.

Accomplishments that we're proud of

  • We built a reflex from a published fly brain and got it running in real time.
  • We gave the fly hearing and its eye responses came out bit-for-bit the same.
  • You can crash the brain mid-game and the fly still dodges.
  • The game keeps running when the brain, the database or the internet goes down.

What we learned

  • A real brain circuit runs fine in plain Python if you check the data at each step.
  • Biology is lopsided. The weak ear and the side-blind Giant Fibers taught us more than the parts that worked first time.
  • A reflex has to answer on time each time. A fast average with late outliers fails the moment it matters.

What's next for Whack-A-Fly

  • Feed the brain real camera input in place of the game's simulated eyes, as a first step toward a reflex for small robots and drones.
  • Add wind from the swing and touch from a near miss.
  • Build a live view of the brain firing as the fly decides.

Built With

Share this project:

Updates

Submission history