ECE 484 Principles of Safe Autonomy · UIUC · Fall 2026

Crazyflie: MPCC and a Distilled Neural Tracker for Drone Racing

1University of Illinois Urbana-Champaign 2Zhejiang University
Team ZJUI Meta

Our MPCC flies a 43 g Crazyflie through gate courses at up to 2.8 m/s. The light-blue curve is the reference path; the orange dots are the 1 s trajectory the contouring MPC plans and re-solves every 10 ms.

Abstract

We race a Crazyflie 2.1 quadrotor through gate courses in the crazyflow MuJoCo simulator. The drone may only send attitude and collective-thrust commands at 100 Hz. It sees the true pose of a gate only when it is within 0.7 m of it, and it has to finish five laps without touching anything. We turned every challenge listed in the course README into a reproducible stress test: a randomized start pose, shifted gates, obstacles on the racing line, wind and gusts, collision impulses, battery sag, a weak motor, a shorter sensor range, all of them at once, and the environment's own random layouts.

Our first controller adapts Model Predictive Contouring Control (MPCC) [1] to this interface. Instead of tracking a timed reference, the optimizer chooses its own progress along an arc-length path and trades speed against a gate-aware contouring error. It uses the system-identified closed-loop attitude model of the drone, a soft safe corridor around gate frames and obstacles, two disturbance observers, and replanning in about 1 ms whenever a gate is revealed. Solved with acados [2] in 0.95 ms per control step (median), it finishes 324 of 330 stress-test races on the three provided tracks and 171 of 176 on held-out random tracks.

Our second controller distills the MPCC optimizer into a small neural network. The planner is kept unchanged; only the solver is replaced. The network (144-128-128-3, 35k parameters) is trained only on randomly generated tracks with randomly combined stress tests, first with behaviour cloning and then with seven DAgger iterations, with the MPCC as expert and safety pilot. With speed command 0.8 it finishes 312 of 330 races on the provided tracks, which it never saw in training, and 156 of 176 on random tracks, at 0.36 ms per control step with numpy only.

324/330MPCC races finished on the 3 provided tracks × 11 stress conditions × 10 seeds
312/330Distilled network, same races, on tracks never seen in training
17.1 sMean time for 5 laps of the U-turn track (MPCC, no extra stress)
0.36 msNetwork control step, vs. 0.95 ms for MPCC (median, whole step, one core)

The Task

Each track is a sequence of square gates (0.72 m frame, 0.40 m opening, at 0.7 m or 1.2 m height) plus thin vertical obstacle poles. Gates must be crossed in order and along their local \(+x\) axis, five laps in a row. Touching a gate, a pole or the floor, or leaving the flight volume, ends the race. The provided tracks are a circle (4 gates), a U-turn with 180° hairpins (4 gates) and a figure-eight lemniscate (6 gates).

  • Interface. At 100 Hz the controller receives position, attitude, velocity and body rates, and returns \([\phi_c, \vartheta_c, \psi_c, f_c]\): roll, pitch and yaw angles in radians, then the collective thrust in newtons. Thrust comes last, as in the environment's action space and the hardware driver (the course README listed it first). The Crazyflie's onboard attitude loop does the rest. Physics runs at 500 Hz.
  • Partial observability. Gate and obstacle poses are reported at their nominal values until the drone comes within the sensor range (0.7 m). The hardware environment masks motion-capture poses in exactly the same way.
  • Default disturbances. Every run has action noise, random force noise of ±0.1 N, ±5 g mass and inertia randomization and a random start pose.

The README stress tests

The course README lists the challenges the hidden evaluation tracks may contain. We turned each of them into a test condition, added on top of the default disturbances:

Condition Setting
base only the configs' default disturbances
start start pose ±0.4 m in \(x/y\), any yaw
shift gates ±0.15 m / ±0.15 rad, obstacles ±0.15 m, true pose revealed within 0.7 m
obstacle two extra poles on the nominal racing line
wind 1.5 m/s steady wind (random direction) and 1.0 m/s gusts
impulse 0.4 N pushes of 50 ms every 3 s, pseudo-random directions
battery thrust loss growing linearly to 15 % at 30 s
motor one (random) motor 10 % weaker
shift+sensor shifted gates with the sensor range reduced to 0.4 m
all all of the above at once
envrandom the environment's own random layout ([env.track] randomize = true): a different track
Tight turns are covered by the U-turn track and the random tracks. Each condition is run with 10 seeds on each provided track (5 laps) and on 16 held-out random tracks (3 laps): 330 + 176 = 506 races per controller.

Method I: Model Predictive Contouring Control

The path is replanned (in about 1 ms) whenever the true pose of a gate or obstacle is revealed.

Contouring instead of tracking

A classical pipeline fixes a timed reference \(\mathbf{p}_{\mathrm{ref}}(t)\) and tracks it. If the drone falls behind, it chases a reference point that may no longer be reachable. MPCC drops the time. The reference is a purely geometric path \(\mathbf{p}_d(\theta)\), parameterized by arc length, and the progress \(\theta\) becomes a state of the optimizer, with \(\dot\theta = v_\theta\). The tracking error \(\mathbf{e} = \mathbf{p} - \mathbf{p}_d(\theta)\) is split along the unit tangent \(\mathbf{t}(\theta)\) into a lag part and a contour part:

\[ \mathbf{e}^l = (\mathbf{t}^\top \mathbf{e})\,\mathbf{t}, \qquad \mathbf{e}^c = \mathbf{e} - \mathbf{e}^l . \]

Every 10 ms we solve, over a 1 s horizon of 25 stages,

\[ \min_{\mathbf{u}_{0:N-1}} \; \sum_{k=0}^{N} \Big( q_l \|\mathbf{e}^l_k\|^2 + q_c(\theta_k)\,\|\mathbf{e}^c_k\|^2 + \|\mathbf{u}_k\|^2_{R} - \mu\, v_{\theta,k} \Big) \quad \text{s.t. dynamics, input and corridor constraints.} \]

The progress reward \(\mu v_\theta\) pushes the drone forward. The contour weight keeps it on the racing line. Because the speed profile is the result of the optimization, the drone slows down for tight turns and gates and speeds up on straights, and it may cut corners between gates.

Adapting the paper to our Crazyflie drone

Romero et al. [1] control a 0.85 kg racing quadrotor through its four rotor thrusts. Our Crazyflie weighs 43 g and only accepts attitude and collective-thrust commands, so we use the model the simulator integrates, which is a system-identified model of the closed loop “Crazyflie + onboard attitude controller”:

\[ \begin{aligned} \dot{\mathbf{v}} &= \tfrac{1}{m} R(\boldsymbol\eta)\,[\,0,\ 0,\ c_f f\,]^\top + \mathbf{g} + \tfrac{1}{m} R D R^\top \mathbf{v} + \hat{\mathbf{d}}, \\[6pt] \ddot{\boldsymbol\eta} &= \mathbf{a}_\eta \odot \boldsymbol\eta + \mathbf{b}_\eta \odot \dot{\boldsymbol\eta} + \mathbf{c}_\eta \odot \boldsymbol\eta_c + \hat{\mathbf{b}}, \\[6pt] \dot f &= \tfrac{1}{\tau_f}(f_c - f). \end{aligned} \]

Each Euler angle responds like a damped spring to its command (roll/pitch: 13.7 rad/s, damping 0.46, steady-state gain 0.73), and the thrust lags its command by 80 ms. As in the paper, the optimizer chooses the rates of the commands, which keeps them smooth and bounded. The state has 18 dimensions: position, angles, velocity, angle rates, thrust, the three commands, \(\theta\) and \(v_\theta\). The solver tutorial walks from a QP through SQP and RTI to how acados solves this problem.

What we added for safety

  • Gate-aware contour weight. A sum of Gaussians centred on the gates \(\mathbf{g}_j\), \[ q_c(\theta) = q_{\mathrm{nom}} + q_{\mathrm{gate}} \textstyle\sum_j \exp\!\big(-\|\mathbf{p}_d(\theta) - \mathbf{g}_j\|^2 / 2\sigma^2\big), \] is small between gates and large inside them. The drone may cut corners, but it threads the gates precisely.
  • Soft safe corridor. At every stage the contour error must stay below the clearance to the nearest frame, pole or obstacle minus the drone's radius (0.13 m: the collision box's 0.099 m half-diagonal plus 3 cm), and poles get soft keep-out cylinders, larger while their pose is not revealed yet.
  • Disturbance observer. A first-order observer estimates the unmodelled acceleration (wind, mass error, battery sag) from the difference between the measured and the predicted acceleration, \[ \hat{\mathbf{d}} \leftarrow (1-\alpha)\,\hat{\mathbf{d}} + \alpha\Big(\tfrac{\mathbf{v}_t - \mathbf{v}_{t-1}}{\delta} - \mathbf{a}_{\mathrm{model}}\Big), \quad \alpha = 0.04 \;(\approx 0.25\ \mathrm{s}), \] and feeds it into the model (offset-free MPC). When it is large, the controller slows down.
  • Attitude bias observer. A 10 % weak motor tilts the drone by about 0.08 rad at a level command. In the identified attitude model this is a constant angular-acceleration bias \(\hat{\mathbf{b}}\), estimated from the one-step prediction error of the exactly discretized model, so MPCC simply commands the tilt that compensates it.
  • Caution near unrevealed objects. Progress speed is capped at 1.5 m/s near gates and poles whose true pose is not known yet, scaled with the sensor range. When the pose is revealed, the path is replanned.
  • Yaw alignment and frame-aware crossings. The square collision box needs 0.099 m of half-width through a gate rotated by 45°, so MPCC yaws with the next gate. Crossings are also checked against neighbouring frames, and the planner routes detours around poles on the racing line.
  • Hard layouts. The environment's own random layouts often put gates face to face or next to a wall. Their reference is planned with curvature-bounded, clearance-aware Hybrid A* routes and a curvature speed limit.

Simulation

acados SQP-RTI at 100 Hz; the orange dots are the 25-stage, 1 s prediction.

Real-World Deployment

MPCC flying a real Crazyflie 2.1 through the lab's ring gates.

Method II: Distilling MPCC into a Neural Tracker

Only the outlined orange block is learned. Everything else is shared with the MPCC controller.

Distill only the optimizer

We distill the MPCC solver into a network by imitation learning: behaviour cloning, followed by DAgger. The planning half of MPCC is cheap and has nothing to learn, so we keep it exactly and let the network replace only the nonlinear program. The network is a path tracker. It sees 20 samples of the path ahead, 0.14 m apart (2.8 m, as far as MPCC's horizon reaches at top speed), the contour weight, corridor radius and speed cap at those samples, the drone state, the previous command, both disturbance estimates and the two nearest obstacles (with a flag for whether each is still unrevealed). All of these are expressed in a heading frame centred on the drone, so the network cannot memorize where on the map it is. It outputs the change of the roll, pitch and thrust commands, which is MPCC's first optimal input. That makes its commands as smooth and bounded as MPCC's by construction; yaw is commanded 0.

Speed command. The speed enters only through the speed-cap features: the teacher flies with a random speed_scale \(\in\{0.6, \dots, 1.0\}\) per training episode, its caps shrink accordingly, and the network sees the same caps. At deployment the same knob trades lap time for safety margin without retraining.

Random tracks, random stress, DAgger, and an expert-in-the-loop safety pilot

To show that the tracker works for any path, we train only on procedurally generated tracks (3–6 gates, random headings and heights, 0–3 obstacles placed near the path). Every training episode switches each README stress test on at random (shift 60 %, start, obstacle, wind, impulse and battery 30 % each, motor 25 %, short sensor range 20 %) at 0.6, 1.0 or 1.25 times the README magnitude. The three provided tracks are held out for testing.

Behaviour cloning alone suffers from distribution shift: small errors compound into states the expert never visited [6]. With DAgger [3], the student flies and MPCC labels every visited state in shadow mode. If the student leaves the corridor by more than 2 cm, MPCC takes over for 1 s, still labelling, which yields exactly the recovery data the student needs. A fifth of the episodes are MPCC flights with correlated command noise (DART [4]). Behaviour cloning on 600 episodes plus seven DAgger iterations of 400 episodes give 3.7 M samples in 78 minutes on one laptop CPU.

Fix the teacher first. A student cannot beat its teacher, so before training we ran MPCC through every stress test and fixed what failed: the weak motor (attitude bias observer), late reveals with a short sensor range (speed cap scaled with the range), poles on the racing line (detour waypoints), impulses at gates (the speed command), and later the remaining gate-frame contacts (yaw alignment, frame-aware crossings). An earlier fix of the same kind: the corridor used to reserve only \(r_{\mathrm{drone}} = 0.10\) m for a 0.099 m half-diagonal, 1 mm of margin inside a gate.

What did not pay off

PPO fine-tuning [5] of an earlier version did not improve it (two runs of about 1M steps): rare near-misses at gate frames are too noisy a signal at that budget. An ensemble of five 128×128 networks was better on validation tracks at full speed but not on the test at speed 0.8, so the single network is the default. In the earlier version, an ensemble of five 64×64 networks (67k parameters) had finished 88 of 90 races with shifted gates and wind only.

Simulation

Recorded with the earlier version (an ensemble of five 64×64 networks); the green curve is the 2.8 m of path the network sees.

Results

Top views of five-lap flights on the circle, U-turn and lemniscate tracks; the MPCC and network trajectories nearly coincide Top views of five-lap flights on the circle, U-turn and lemniscate tracks; the MPCC and network trajectories nearly coincide
Five laps on each provided track (top view, same seed, default disturbances). Blue: MPCC at full speed. Orange: the distilled network at speed 0.8, which has never seen these tracks. Gate frames are drawn with the crossing direction as an arrow; × marks an obstacle.

README stress tests

Condition Provided tracks (of 30) Random test tracks (of 16)
MPCC Network MPCC Network
base 30 30 16 16
start 30 30 16 16
shift 30 29 15 12
obstacle 30 30 16 16
wind 30 30 16 15
impulse 28 29 15 15
battery 30 30 16 15
motor 30 30 16 16
shift+sensor 30 29 15 12
all 26 24 14 9
envrandom 30 21 16 14
total 324/330 312/330 171/176 156/176
Races finished without any contact. Provided tracks: 3 tracks × 10 seeds, 5 laps; random: 16 held-out tracks, 3 laps. MPCC at full speed, network at speed 0.8.

Lap times and computation

Controller Params Circle [s] U-turn [s] Lemniscate [s] Step [ms]
median / p99 / max
Gate offset [m]
MPCC — 25.60 ± 0.40 17.10 ± 0.18 25.87 ± 0.45 0.95 / 1.85 / 2.31 0.129
Network (ours) 35k 26.56 ± 0.39 19.94 ± 0.13 29.59 ± 0.28 0.36 / 0.62 / 0.84 0.136
Lap time: mean ± std of the 5-lap time over 10 base runs. Step: the whole compute_control call on one core. Gate offset: maximum distance to the gate centre when passing a gate (opening half-width 0.2 m).
  • Every MPCC failure on the provided tracks followed a collision impulse. All six crashes (two impulse races on the circle, four all races on the lemniscate) happen 0.13–0.48 s after a 0.4 N push that arrives just before a gate at 1.8–2.7 m/s; the push changes the velocity by about 0.47 m/s and the drone grazes an inner plate of the opening (1.5–7.5 mm penetration). With 13 cm of margin and a few tenths of a second left, a nominal MPC cannot recover; every other single README condition is 30/30.
  • The network is almost as safe on unseen tracks. On the provided tracks it passes every single README condition at least 29 of 30 times; it loses ground with all stresses at once (24/30) and on the environment's random layouts (21/30), a kind of reference it was never trained on. On random tracks its failures concentrate on a few tight layouts with shifted gates revealed late.
  • Cost and speed. The network needs 2.6× less time per step than MPCC and no solver; no step of either controller came close to the 3 ms budget we set ourselves (worst: 2.3 ms for MPCC, 0.8 ms for the network). At its default speed command 0.8 its laps are 4–17 % slower; at full speed it is clearly less safe than MPCC, so we trade lap time for margin.

BibTeX

@misc{zheng2026crazyflie,
  title  = {Crazyflie: MPCC and a Distilled Neural Tracker for Drone Racing},
  author = {Zheng, Hanbin and Wang, Shengrui and Wang, Siyuan and Li, Xiang},
  note   = {ECE 484 Final Project, University of Illinois Urbana-Champaign},
  year   = {2026},
  url    = {https://hanbinzheng.github.io/project/crazyflie/}
}

References

  1. A. Romero, S. Sun, P. Foehn, D. Scaramuzza. Model Predictive Contouring Control for Time-Optimal Quadrotor Flight. IEEE Transactions on Robotics, 2022.
  2. R. Verschueren et al. acados: a modular open-source framework for fast embedded optimal control. Mathematical Programming Computation, 2022.
  3. S. Ross, G. Gordon, D. Bagnell. A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning. AISTATS, 2011.
  4. M. Laskey, J. Lee, R. Fox, A. Dragan, K. Goldberg. DART: Noise Injection for Robust Imitation Learning. CoRL, 2017.
  5. J. Schulman, F. Wolski, P. Dhariwal, A. Radford, O. Klimov. Proximal Policy Optimization Algorithms. arXiv:1707.06347, 2017.
  6. S. Levine. CS 285: Deep Reinforcement Learning. Lecture course, University of California, Berkeley. Lecture 2 (behaviour cloning, distribution shift, DAgger).
  7. ECE 484 Fall 2026 Quadrotor Project, University of Illinois Urbana-Champaign. Official team page: ZJUI Meta.