fly-cartpole

GitHub: Curt-Park / fly-cartpole

The circuit a fruit fly uses to stay upright in flight, wired from the MaleCNS connectome, balances a pole as a reflex, holding its place against a landmark: no synapse changes. Every episode starts from a random state, and every neuron of the circuit is simulated live in your browser.

left wing
right wing
episode · step · steer
best · mean of last 10
relative gains: ocelli (angle) · halteres (rate) · HS (drift) · landmark position · landmark motion

The same moment seen as flight, from behind the fly. The pole's lean is the fly's roll; the halteres (amber) light on the side falling down; the ocelli (green) read the tilt; the ground flows past as the cart moves, read by the HS cells (blue, behind the eyes); and the push is the wing beating wider, driven by b1 and b2. The wingbeat is slowed from about 200 strokes a second.

5,459 neurons of the brain and ventral nerve cord on paths of at most three connections from the halteres, ocelli and HS cells to the wing steering motor neurons, drawn at their MaleCNS cell-body positions. Haltere afferents, whose cell bodies sit in the halteres, and the few other neurons without a recorded position are drawn at the mean cell-body position of the neurons they synapse onto. Brightness follows each neuron's activity. The push follows the difference between the right and left b1 and b2 motor neurons, which raise the wing's stroke amplitude. The fly also sees where the cart is against a landmark, a stripe above the track's centre, and how fast the stripe slides across its eye; both shift the tilt it holds: to slide back it first banks toward the stripe, and the slide damps the return. Only the ratios of the sensor gains matter, so they are shown with a geometric mean of 1. Nothing learns while you watch. With random pushes the circuit rests, which shows how quickly the pole falls without the fly. The linear controller steers with the circuit's settled linear map, the same signs and ratios without its dynamics, tuned the same way as the fly; LQR is an engineer's controller computed from CartPole's equations. The circuit rests for both. Drag to rotate.