← Projects
Controls and autonomy [PRJ-02] · 02 / 04

Fault-tolerant quadrotor flight stack

Independent project 600-run failure MC · 3D replay

Quadrotor guidance, navigation, and control (GNC) stack that detects a failed rotor from IMU data and flies on three rotors, using a 390-line C nonlinear MPC solver to recover 567 of 600 random failures.

Launch 3D replay ↗

[PRJ-02]Replay of the agile race lap (14.0 m/s, 3.3 g) and mid-flight rotor failure recovery into a 26 rad/s relaxed-hover spin.

Summary

What I built

  1. 01What

    I built a quadrotor guidance, navigation, and control (GNC) stack from scratch that detects a failed rotor and lands safely on the remaining three.

  2. 02How

    An error-state Kalman filter (ESKF) feeds a 100 Hz real-time-iteration nonlinear model predictive controller (RTI-NMPC) backed by a hand-written 390-line C interior-point solver. An inertial measurement unit (IMU) residual detector isolates the failed rotor without motor RPM feedback in a 1 kHz nonlinear simulation with 33 ms motor lag, turbulence, and sensor latency.

  3. 03Outcome

    Recovered and landed 567 of 600 random rotor failures (94.5%), isolated the correct rotor in 600 of 600 cases at a 16 ms median delay, and logged 0 false alarms over 51 min of turbulent flight with a 0.22 ms mean solve time.

Results

[PRJ-02] Measured
Failures recovered
567 / 600
Mean NMPC solve
0.22 ms
Median FDI delay
16 ms
  • 8-gate race lap (EKF feedback, 14.0 m/s, 3.3 g): position RMSE7.5 cm (NMPC) vs 34.7 cm (geometric)
  • 100 Hz NMPC solve time (7,715 steps): mean / p99 / max0.22 ms / 0.55 ms / 6.07 ms
  • Rotor-failure Monte Carlo recovery and landing (600 failures)567 / 600 (94.5%); 459/463 < 8 m/s; 418/418 < 50° bank
  • Fault isolation without RPM feedback: accuracy and delay600 / 600 correct rotor · median 16 ms (p99 129 ms)
  • Fault detector false alarms (51 min turbulent, model-mismatched flight)0 false alarms
  • Hover rotor-failure demo: max deviation / altitude loss / touchdown14.6 cm / 1.1 cm / 0.32 m/s
  • Sampled-data margin analysis vs nonlinear sim instability onset40.2 ms predicted vs 40.2 ms sim (0.2% apart); 6 gain margins within 0.13 dB
  • ESKF statistical consistency (30 runs): NEES / NIS / position RMSENEES 14.5 (ideal 15) · NIS 3.02 / 3.00 (ideal 3) · 1.0 cm RMSE
System

Architecture

  1. 01eskf.py

    Quaternion-manifold error-state EKF fusing 1 kHz IMU, 100 Hz magnetometer, and 50 Hz position measurements with 20 ms latency compensation and covariance inflation on gyro saturation.

  2. 02trajectory/

    Minimum-snap QP trajectory generation, time allocation, and differential-flatness mapping for aggressive race and figure-eight profiles.

  3. 03nmpc/model.py + c/rti.c

    Direct rotor-speed NMPC (motor states inside the prediction horizon, no inner loop) with CasADi C-generated Gauss-Newton derivatives and a 390-line hand-written C Riccati interior-point QP solver checked against KKT conditions and IPOPT.

  4. 04fdi.py + failure.py

    IMU-residual fault detector isolating the failed rotor without ESC RPM feedback; computes the Mueller–D’Andrea relaxed-hover equilibrium at 26 rad/s inside ±34.9 rad/s gyro limits.

  5. 05analysis/margins.py

    Sampled-data closed-loop stability analysis computing gain, phase, and delay margins for the geometric SE(3) baseline, checked directly against nonlinear instability onset.

Design decisions

  1. D01

    Direct rotor-speed NMPC with motor dynamics inside the prediction state removes inner/outer loop bandwidth separation and lets one controller handle both 4-rotor racing and 3-rotor recovery.

  2. D02

    Exploiting optimal-control block-banded structure with input-box inequalities reduces every interior-point step to one Riccati recursion in 390 lines of portable C.

  3. D03

    A 26 rad/s relaxed-hover spin keeps steady recovery inside the ±34.9 rad/s gyro range while retaining lateral control authority.

  4. D04

    Every one of the 33 Monte Carlo losses was a ground strike 0.6–1.5 s after rotor failure at 56°–78° bank, 5.2–12.9 m/s, and 2–3 m AGL.

Evidence

Figures

6 plots and captures. Select any figure to view it at full resolution.

[Fig. 01] Agile race lap: NMPC vs geometric SE(3). 8-gate race trajectory reaching 14.0 m/s and 3.3 g under EKF feedback: 7.5 cm RMSE for NMPC versus 34.7 cm for the geometric baseline.
[Fig. 02] Hover rotor failure recovery. IMU-residual detection in 15 ms, reconfiguration into a 26 rad/s relaxed hover with 1.1 cm altitude loss, and controlled landing.
[Fig. 03] 600-run rotor failure Monte Carlo. Detection delay distribution and recovery outcome mapped against airspeed and bank angle (418 of 418 recovered below 50° bank).
[Fig. 04] Stability margin analysis vs nonlinear sim. Sampled-data predicted delay margin (40.2 ms) matches nonlinear instability onset within 0.2%; six gain margins match within 0.13 dB.
[Fig. 05] ESKF statistical consistency (NEES and NIS). Normalized Estimation Error Squared and Innovation Squared checked against chi-square confidence bounds.
[Fig. 06] Figure-eight benchmark (nominal, wind, mismatch). Tracking RMSE across speeds under nominal, turbulent wind, and parametric mismatch conditions.
Scope

Limits

What the model assumes and what this work does not show.

  1. L01

    Simulation-only validation: truth model omits ground effect, blade flapping moments, battery voltage sag, structural vibration modes, and identified airframe drag.

  2. L02

    Covers complete single-rotor loss only; partial loss of effectiveness, stuck motors, and dual-rotor faults are out of scope.

  3. L03

    High-speed recovery transients can briefly clip the ±34.9 rad/s gyro, requiring temporary attitude-covariance inflation and magnetometer recovery.

  4. L04

    Timing was profiled through a Python C-wrapper on a loaded desktop CPU (Apple M5 Pro), not an embedded flight MCU; rare OS preemption outliers are reported unclipped.

Run it

Reproduce

Run the tests and regenerate every figure from the repository.

$ make setup
$ make test
$ uv run ftquad fly --traj race --controller nmpc --condition wind
$ make all
Next project · 03 / 04

SmallSat flight software (C++20)