A Butterfly That Thinks in Spikes: Real-Time Neuromorphic Flight Control on a $5 Microcontroller

A 26 g flapping-wing robot achieves fully onboard state estimation and control using spiking neural networks on an ESP32.

The Maiden Flight

The robot weighed just 26 grams. Its wings were made from ultra-thin Mylar film stretched over carbon fiber spars, and its brain was an ESP32 microcontroller, a chip that costs roughly $5 at retail. When researchers at Tsinghua University’s Institute for AI Industry Research powered it on inside their indoor flight lab, the butterfly-shaped machine lifted off the ground, powered by spiking neural networks that processed sensory data and generated control commands entirely onboard. It tracked a pitch command, adjusted its heading, and flew untethered through the air. No external compute, no motion capture, no offboard correction.

This is the story of how a group of engineers brought neuromorphic computing out of simulation and onto one of the most constrained flying platforms ever built.

Why This Matters

This work is notable for three reasons. First, the entire control system runs onboard a $5 chip with no external compute. Second, it is a real-time SNN control deployment on a physical robot, not a simulation. Third, it sits at the intersection of machine learning, control theory, and embedded systems, a combination that has rarely been demonstrated in a fully closed-loop system. In short, this is not just a smaller controller. It is a different computational paradigm operating under real-world constraints.

Why Flapping Wings Make Everything Harder

Quadrotors have become the workhorses of aerial robotics for good reason. Their dynamics are well studied, their actuators respond predictably, and decades of control theory apply neatly to their four spinning rotors. Flapping wing micro aerial vehicles, or FWMAVs, exist in a different world altogether.

Where propellers produce relatively steady thrust, flapping-wings generate forces that vary dramatically within each stroke. At the small scales where these robots operate, the airflow around the wings is dominated by unsteady lift mechanisms that defy simple models. The body itself oscillates with every wingbeat, injecting periodic disturbances into every sensor reading. And because the butterfly-inspired platform developed by this research group has no tail and no auxiliary control surfaces, the entire burden of generating lift, thrust, and rotational moments falls on just two independently actuated wings. The vehicle is, in control theory terms, severely underactuated across its full six degrees of freedom, meaning it has fewer independent control inputs than motion variables to stabilize.

For years, researchers working on flapping-wing flight have turned to learning-based methods to cope with these complex dynamics. Reinforcement learning and imitation learning can sidestep the need for accurate aerodynamic models by letting neural networks learn control policies directly from data. Yet most of these approaches rely on conventional artificial neural networks, whose dense matrix multiplications demand compute cycles and energy that tiny microcontrollers simply cannot spare.

Enter the Spike

Spiking neural networks represent a fundamentally different approach to neural computation. Rather than passing continuous floating point values between layers, neurons in an SNN communicate through discrete binary events called spikes. A neuron accumulates input current over time, and only when its internal membrane potential crosses a threshold does it fire a spike to its downstream neighbors. Between spikes, the neuron is silent and requires no downstream computation. That difference is not just a nod to biology. It directly maps to fewer computations per control cycle.

This event-driven nature makes SNNs especially attractive for embedded systems where every microjoule counts. On dedicated neuromorphic hardware like Intel’s Loihi or IBM’s TrueNorth, the energy savings can be dramatic. Here is what makes the work from Rim El Filali, Chenrui Feng, Chao Gao, Weibin Gu, and their colleagues so compelling. They achieved meaningful computational benefits from spiking networks on a generic, off-the-shelf microcontroller with no specialized neuromorphic silicon in sight.

Two Networks, One Flying Robot

The researchers structured their onboard control system as a hierarchy of two lightweight SNNs, each responsible for a distinct function. At a high level, the system flows from IMU sensor data through the SNN estimator, into the SNN controller, through the CPG oscillator, and finally to the wing actuators.

The State Estimator

The first network takes in raw six-axis inertial measurement unit data (three axes of acceleration and three axes of angular velocity) and produces estimates of the robot’s roll angle, pitch angle, and yaw rate. This is the same job normally handled by a Madgwick filter, a well-known algorithm for sensor fusion. The SNN version uses 150 neurons in a feedforward spiking layer followed by 150 neurons in a recurrent spiking layer, with a linear readout producing the three output values.

Why estimate yaw rate instead of absolute yaw angle? Because the platform operates indoors without a magnetometer (magnetic disturbances would corrupt heading estimates), and without an external heading reference, absolute yaw is not observable from inertial sensors alone. The network learns to predict yaw rate, which is then integrated over time to reconstruct a heading estimate during flight.

The Controller

The second SNN receives the state estimates from the first network, combines them with gyroscope readings and desired attitude commands from a remote controller, and outputs corrective offsets. These offsets do not directly command the wing servos. Instead, they modulate a Central Pattern Generator, a compact sinusoidal oscillator that produces the rhythmic flapping motion for each wing.

This design choice is critical. The researchers tested two variants of the control network. The first, a CPG-agnostic controller, attempted to predict raw servo commands directly. While it could reproduce expert behavior near the nominal 3.25 Hz flapping frequency used during training, it fell apart at other frequencies, generating irregular and physically inconsistent wing motions. The second variant, the CPG-aware controller, only needed to learn small corrective offsets to the oscillator. By delegating the rhythmic flapping pattern to a deterministic oscillator and letting the SNN handle only the feedback correction, the authors reduced the learning problem to a manageable scope and gained robustness to conditions outside the training distribution. In essence, this is a model-based + learning hybrid, where a known physical structure (the oscillator) handles what it does well and a learned component fills in the rest. That framing resonates broadly across control and robotics.

Learning from an Expert

Neither SNN was trained from scratch through trial and error in the real-world. Instead, the researchers used behavioral cloning, a form of imitation learning where a neural network is trained to reproduce the outputs of an expert system given the same inputs. The dataset scale helps explain how this works in practice, with approximately 10 minutes of real flight data combined with roughly 150 minutes of synthetic trajectories.

The expert in this case was the robot’s existing onboard flight stack, consisting of a Madgwick filter for state estimation and a PID controller for attitude tracking. The authors collected the real flight data using this baseline system, recording IMU measurements, filter outputs, reference commands, and PID control signals at every timestep.

Because imitation learning only covers the portion of the state space visited during stable expert operation, the authors augmented their real flight data with synthetic sequences that included randomized attitude references, slow sweeps, tracking delays, transient recovery scenarios, and saturation cases. All synthetic data was processed through the same baseline estimation and control pipeline to generate consistent training labels. This hybrid dataset is what allows the system to generalize beyond a narrow flight regime.

Both networks were trained using backpropagation through time with surrogate gradients to handle the nondifferentiable nature of spike generation. The training objective combined a Huber loss (for robustness to outliers) with a Pearson correlation term (to preserve the temporal shape of the predicted signals).

From PyTorch to C in One Step

Training SNNs in PyTorch is one thing. Running them at 100 Hz on an ESP32 with 512 KB of on-chip SRAM and a 240 MHz dual-core processor is another matter entirely. That 100 Hz rate is fast enough to track the wingbeat dynamics and maintain closed-loop stability, but it leaves very little time per inference cycle.

To bridge this gap, the researchers developed Espikify, an open-source tool that converts PyTorch defined spiking neural networks into standalone C code ready for compilation on the ESP32. The tool exports all learned weights, neuron parameters, and the static network graph as compile-time header files. The resulting C artifacts use fixed-size buffers allocated at initialization, so no dynamic memory allocation occurs during flight. This is essential for deterministic real-time execution inside a FreeRTOS environment where the control loop must complete within each 10 millisecond interrupt cycle. In many ways, this closes one of the biggest gaps in neuromorphic research: the path from training to deployment.

Before deployment, the exported C code is validated offline by running recorded time-series inputs through both the PyTorch model and the C implementation and comparing outputs to confirm numerical agreement.

Taking Flight

Performance is modest but meaningful given the platform constraints. With both SNNs compiled and loaded onto the ESP32, the butterfly robot flew untethered indoors, tracking pitch and yaw commands in closed-loop. Free-flight data shows a pitch RMSE of 6.32° (±1.52°) and a yaw RMSE of 8.88° (±1.17°). The learned offset commands closely followed the corrective trends of the reconstructed PID baselines, and the state estimation SNN captured the dominant pitch, roll, and yaw dynamics needed for stable feedback control. These errors are comparable to early-stage flapping-wing controllers operating without any neuromorphic constraints.

Context matters here. This is a 26 gram tailless flapping-wing robot with only two actuators, severe aerodynamic coupling, and a microcontroller that costs less than a cup of coffee. The fact that neuromorphic state estimation and control work at all on this platform, let alone well enough for sustained untethered flight, is a statement about the maturity of spike-based computation for real-world robotics.

The Numbers on the Chip

Beyond flight performance, the researchers benchmarked the computational cost of their approach directly on the ESP32 hardware. Each 100 Hz IMU interrupt triggered one full inference step through the cascaded state estimation and control networks.

The hardware results are clear. The event-driven SNN implementation completed inference in approximately 680 microseconds, compared to 1059 microseconds for the equivalent ANN baseline. That is a 36 percent reduction in latency, and lower latency directly improves control responsiveness and stability margins. On the power side, the SNN added roughly 0.027 watts to the board’s baseline consumption during inference, compared to 0.033 watts for the ANN, an 18 percent reduction.

Interestingly, a naively implemented SNN (without the event-driven optimizations) performed only on par with the ANN. The gains came specifically from an event-driven sparse update strategy where spike mediated synaptic updates were computed only for neurons that actually fired, skipping the silent majority. On hardware without native support for sparse event processing, this optimization made the difference between SNNs being a theoretical curiosity and a practical advantage.

What Espikify Means for the Community

One of the more consequential contributions from this work may be the Espikify tool itself. Neuromorphic computing research has long been bottlenecked by the gap between training frameworks and deployment targets. Researchers train SNNs in Python on powerful workstations, but getting those networks onto embedded hardware often requires weeks of manual porting, memory optimization, and debugging.

Espikify compresses that process into a single conversion step. It targets the ESP32 family of microcontrollers, which are among the most widely used and cheaply available embedded platforms in the world. The ESP32 is effectively a common denominator platform, and that matters for adoption. By lowering the barrier to deployment, the tool opens neuromorphic control to a much broader community of roboticists and embedded systems engineers who may not have access to specialized neuromorphic chips.

The authors have released the tool as open-source, and the implications extend well beyond flapping-wing robots. Legged microrobots, smart sensors, always-on edge perception systems, and any other embedded control application running on an ESP32 that could benefit from low latency, energy aware neural inference are all potential use cases.

Where Things Stand and What Comes Next

The authors are candid about the current boundaries of their system. Yaw estimation relies on integrating the predicted yaw rate without any absolute heading reference, which means bias accumulates over time and long duration heading accuracy degrades. Future iterations could incorporate visual inertial feedback from an onboard camera or train the recurrent SNN to detect and compensate for gyroscope drift directly from IMU sequences.

There is also a memory tradeoff. The deployed SNN actually has a slightly larger memory footprint than the ANN baseline because it must store not only synaptic weights but also neuron states such as membrane potentials and spiking parameters. Shrinking this overhead will require either more compact SNN architectures with simpler neuron models or smaller network sizes, or a move to dedicated neuromorphic hardware that can fully exploit event-driven processing and in memory computation.

A natural next step is an end-to-end spike-based perception and control stack running on the same chip, where visual input from an onboard camera feeds directly into spiking layers that produce motor commands. Whether the latency and energy gains observed here persist as task complexity and network size grow remains an open question, and one that the broader neuromorphic community will need to answer.

A Broader Perspective

For decades, the neuromorphic computing community has argued that spike-based processing is a natural fit for real-time control in resource-constrained environments. The theoretical arguments are sound. The simulation results have been encouraging. But real-world, closed-loop, fully onboard deployments have remained scarce, particularly on platforms as constrained as a sub 30 gram flying robot.

What the researchers at Tsinghua have shown is that the gap between theory and practice is closing. Not through exotic hardware, but through careful co design of network architecture, training methodology, and deployment tooling on hardware that anyone can buy online for a few dollars. This suggests a path where neuromorphic methods compete not by replacing GPUs, but by enabling intelligence where GPUs cannot go.

The butterfly is small, imperfect, and constrained. Yet it closes a loop that has remained open for years: neuromorphic control, running fully onboard, in the real-world.


Citation:

El Filali, R., Feng, C., Gao, C., and Gu, W. (2026). “Neuromorphic Control of a Flapping-Wing Robot on Resource-Constrained Hardware.” arXiv:2605.19430v2 [cs.RO]. Institute for AI Industry Research (AIR), Tsinghua University and Xinchen Qihang Inc., Beijing, PR China.

Code: Espikify is available at https://anonymous.4open.science/r/Espikify-76E3/

Related Articles

PHP Code Snippets Powered By : XYZScripts.com
★

Track This Company

Create a free account to add companies to your watchlist and get notified when patents, funding, or key developments change.