Quadrotor control: putting PID, LQR and PPO to the same test
I began this project expecting a learned controller to outperform the classical alternatives. Instead, the simplest of the three proved the most reliable in my experiments.
To test that expectation, I built a nonlinear quadrotor simulator, implemented cascaded PID and LQR controllers, and trained a PPO policy for approximately 100 million environment steps. I then evaluated all three on the same eight position-control tasks, using the same random seeds and no scenario-specific retuning. PID remained crash-free, rejected persistent wind disturbances more effectively, and reached the target faster in the calm scenarios.
Understanding why became the most interesting part of the project. It brought together rigid-body dynamics, rotation matrices, feedback design and reward engineering, while forcing me to think carefully about what a successful flight should mean in the evaluation.
Applied Mathematics research project · University of Cape Town · October 2026
Supervisor: Dr Malcolm Hillebrand
- Built: a custom 12-state nonlinear simulator and a common evaluation pipeline.
- Compared: cascaded PID, continuous-time LQR and a PPO actor-critic policy.
- Tested: eight scenarios, 20 seeds per scenario and a 50-second maximum episode.
- Learned: under this model and task distribution, integral action and a well-tuned classical baseline mattered more than controller complexity.
The question I wanted to answer
A quadrotor cannot accelerate horizontally without first tilting, so position and attitude are coupled. Its controller must manage that coupling while maintaining enough vertical thrust to remain airborne. Wind adds another demand: reaching a target once is not the same as holding position against a persistent force.
I wanted to understand how three different approaches handled that problem: PID uses an explicit feedback structure, LQR uses a mathematical model linearised around hover, and PPO learns its actions through interaction with the nonlinear environment. By building the simulator myself, I could control its assumptions and trace unexpected behaviour back to the equations rather than treat the environment as a black box.
This comparison concerns simulation. My physical quadrotor build is a connected engineering project, but transferring these research controllers to that aircraft remains a separate sim-to-real task.
Building the nonlinear model
State, inputs and reference frames
I represent the vehicle with the twelve-dimensional state
\[ \vec{x}= \begin{bmatrix} x&y&z&v_x&v_y&v_z&\phi&\theta&\psi&\omega_x&\omega_y&\omega_z \end{bmatrix}^{T}. \]
Position and linear velocity are measured in a fixed global frame, with positive \(z\) pointing upward. I use the Euler angles \(\phi\), \(\theta\) and \(\psi\) for roll, pitch and yaw, while the angular velocities \(\omega_x\), \(\omega_y\) and \(\omega_z\) are measured about the body-fixed axes. That distinction matters because Euler-angle rates and body angular velocities are not interchangeable away from hover.
The generalised control input is
\[ \vec{u}=\begin{bmatrix}T&\tau_x&\tau_y&\tau_z\end{bmatrix}^{T}, \]
where \(T\) acts along the positive body \(z\)-axis and the three torques act about the body axes.
Translating thrust into the global frame
Using the \(Z\)-\(Y\)-\(X\) yaw-pitch-roll convention,
\[ R(\phi,\theta,\psi)=R_z(\psi)R_y(\theta)R_x(\phi). \]
With \(c_\alpha=\cos\alpha\) and \(s_\alpha=\sin\alpha\), the product is
\[ R= \begin{bmatrix} c_\psi c_\theta & c_\psi s_\theta s_\phi-s_\psi c_\phi & c_\psi s_\theta c_\phi+s_\psi s_\phi\\ s_\psi c_\theta & s_\psi s_\theta s_\phi+c_\psi c_\phi & s_\psi s_\theta c_\phi-c_\psi s_\phi\\ -s_\theta & c_\theta s_\phi & c_\theta c_\phi \end{bmatrix}. \]
Newton’s second law gives the nominal translational dynamics:
\[ m\dot{\vec v}=m\begin{bmatrix}0\\0\\-g\end{bmatrix} +R\begin{bmatrix}0\\0\\T\end{bmatrix}. \]
The position-attitude coupling is explicit here: the last column of \(R\) determines the direction in which thrust accelerates the vehicle.
All twelve state equations
The translational kinematics and dynamics are
\[ \begin{aligned} \dot x&=v_x,&\dot y&=v_y,&\dot z&=v_z,\\ \dot v_x&=\frac{T}{m}(\cos\psi\sin\theta\cos\phi+\sin\psi\sin\phi),\\ \dot v_y&=\frac{T}{m}(\sin\psi\sin\theta\cos\phi-\cos\psi\sin\phi),\\ \dot v_z&=-g+\frac{T}{m}\cos\theta\cos\phi. \end{aligned} \]
The rotational kinematics follow by expressing the yaw, pitch and roll rotation axes in the body frame and inverting the resulting transformation:
\[ \begin{bmatrix}\dot\phi\\\dot\theta\\\dot\psi\end{bmatrix} = \begin{bmatrix} 1&\sin\phi\tan\theta&\cos\phi\tan\theta\\ 0&\cos\phi&-\sin\phi\\ 0&\sin\phi/\cos\theta&\cos\phi/\cos\theta \end{bmatrix} \begin{bmatrix}\omega_x\\\omega_y\\\omega_z\end{bmatrix}. \]
For the rotational dynamics, I start with the Newton-Euler equation
\[ I\dot{\vec\omega}+\vec\omega\times(I\vec\omega)=\vec\tau, \qquad I=\operatorname{diag}(I_x,I_y,I_z). \]
Expanding the cross product gives
\[ \begin{aligned} \dot\omega_x&=\frac{\tau_x-(I_z-I_y)\omega_y\omega_z}{I_x},\\ \dot\omega_y&=\frac{\tau_y-(I_x-I_z)\omega_x\omega_z}{I_y},\\ \dot\omega_z&=\frac{\tau_z-(I_y-I_x)\omega_x\omega_y}{I_z}. \end{aligned} \]
Together, these equations define \(\dot{\vec x}=f(\vec x,\vec u)\), giving all three controllers the same nonlinear environment. I develop the model derivation in Section 2 and Appendix A of my paper.
From individual rotors to thrust and torque
For the X-configuration in the paper, the rotors are numbered front-right, front-left, rear-left and rear-right. Rotors 1 and 3 rotate counter-clockwise; 2 and 4 rotate clockwise. With individual thrusts \(f_i\geq0\) and arm length \(l\), the paper’s allocation convention is
\[ \begin{aligned} T&=f_1+f_2+f_3+f_4,\\ \tau_x&=\frac{l}{\sqrt2}(f_2+f_3-f_1-f_4),\\ \tau_y&=\frac{l}{\sqrt2}(f_3+f_4-f_1-f_2),\\ \tau_z&=k_d(f_2+f_4-f_1-f_3). \end{aligned} \]
The torque-to-thrust ratio follows from
\[ f_i=C_T\rho\left(\frac{\Omega_i}{2\pi}\right)^2D^4, \qquad q_i=C_Q\rho\left(\frac{\Omega_i}{2\pi}\right)^2D^5, \]
so \(k_d=q_i/f_i=C_QD/C_T\). This connects the generalised input to the rotor geometry without confusing a body torque command with an individual motor thrust.
Physical and numerical parameters
| Parameter | Symbol | Value used |
|---|---|---|
| Mass | \(m\) | \(1.0\,\mathrm{kg}\) |
| Gravity | \(g\) | \(9.81\,\mathrm{m\,s^{-2}}\) |
| Body \(x\) inertia | \(I_x\) | \(0.0083969\,\mathrm{kg\,m^2}\) |
| Body \(y\) inertia | \(I_y\) | \(0.0083969\,\mathrm{kg\,m^2}\) |
| Body \(z\) inertia | \(I_z\) | \(0.06395344\,\mathrm{kg\,m^2}\) |
| Arm length | \(l\) | \(0.225\,\mathrm{m}\) |
| Torque-to-thrust ratio | \(k_d\) | \(0.1\) |
| Integration time step | \(\Delta t\) | \(0.01\,\mathrm{s}\) |
These values come from Table B.1 and define the simulation; they are not measurements of the completed physical aircraft.
Testing the simulator before testing controllers
I integrated the system using fourth-order Runge-Kutta at a \(0.01\)-second time step. Before adding feedback, I checked it against simple inputs whose responses followed directly from the model:
- Hover: \(T=mg\) and zero torques should leave a level, stationary vehicle unchanged.
- Climb and descent: at level attitude, \(\ddot z=-g+T/m\). Constant thrust above or below \(mg\) should give linear vertical velocity and quadratic height.
- Periodic thrust: \(T(t)=mg+A\sin(\nu t)\) should give the corresponding oscillatory acceleration and integrated motion.
- Pure roll torque: with no initial pitch or yaw motion, \(\dot\omega_x=\tau_x/I_x\). Constant torque should give linear angular velocity and quadratic roll angle. I also tested pitch and yaw.
These tests let me check the dynamics independently of the controller. If an open-loop response was wrong, tuning feedback around it could have hidden the underlying problem rather than resolved it.
A disturbance that changes gradually
To represent wind that changes gradually, I used an AR(1) wind-force process rather than drawing an entirely new force independently at every time step:
\[ \vec F_t^w=\alpha\vec F_{t-1}^w+(1-\alpha)\vec F_{\mathrm{mean}}^w +kF_{\mathrm{mag}}\sqrt{1-\alpha^2}\,\vec\epsilon_t, \qquad \vec\epsilon_t\sim\mathcal N(\vec0,I_3). \]
The mean force is set by spherical coordinates,
\[ \vec F_{\mathrm{mean}}^w=F_{\mathrm{mag}} \begin{bmatrix} \cos\gamma_w\cos\beta_w\\ \cos\gamma_w\sin\beta_w\\ \sin\gamma_w \end{bmatrix}, \]
with \(\beta_w\sim U(0,2\pi)\) and \(\gamma_w\sim U(-\gamma_{\max},\gamma_{\max})\). The mean direction is fixed within each evaluation seed; the AR(1) innovations vary the force over time.
I used \(\alpha=0.98\), \(F_{\mathrm{mag}}=2\,\mathrm N\) and \(\gamma_{\max}=\pi/12\). The 2 N mean force is about one fifth of the simulated vehicle’s weight, representing a persistent, predominantly horizontal disturbance rather than extreme turbulence. Within this process, \(\sqrt{1-\alpha^2}\) scales the innovations as the temporal correlation changes, while \(k\) controls the variability around the mean force.
Three ways of closing the loop
Cascaded PID: position commands attitude
I used six PID subcontrollers: three for position and three for attitude. For an error \(e_k=r_k-y_k\), the discrete law is
\[ I_k=I_{k-1}+e_k\Delta t, \qquad C_k=K_pe_k+K_iI_k+K_d\frac{e_k-e_{k-1}}{\Delta t}. \]
I clipped the accumulated integral to \([-I_{\max},I_{\max}]\) to limit wind-up. Within this cascade, the outer loop generates desired roll and pitch and a thrust correction, while the inner loop tracks the commanded attitude and produces body torques. The thrust command must also include the hover term:
\[ T=mg+T_{\mathrm{corr}},\qquad \psi^*=0. \]
For horizontal motion, I map position error into attitude commands:
\[ \theta^*=K_p^{(x)}e_x+K_i^{(x)}I_x+K_d^{(x)}\frac{e_{x,k}-e_{x,k-1}}{\Delta t}, \]
\[ \phi^*=-\left(K_p^{(y)}e_y+K_i^{(y)}I_y+K_d^{(y)}\frac{e_{y,k}-e_{y,k-1}}{\Delta t}\right), \qquad e_y=y^*-y. \]
Here \(I_x\) and \(I_y\) denote the accumulated position errors in the PID loops, rather than the inertias used in the dynamics. The negative sign in the roll command matters: near hover, \(\ddot y\approx-g\phi\), so a positive \(y\)-position error requires a negative roll command. This is the mapping in my controller implementation.
This ensures that a zero height error does not produce zero total thrust. For the cascade to work, the inner loop must also respond quickly enough for the outer loop to make useful position corrections.
I tuned attitude first, followed by altitude and horizontal position. In each case, I increased proportional gain until the perturbed response oscillated, added derivative gain to damp it, and retained integral gain where it reduced the remaining offset. I then kept one fixed gain set throughout evaluation.
| Subcontroller | \(K_p\) | \(K_i\) | \(K_d\) | Integral limit |
|---|---|---|---|---|
| \(x\) position | 1.6 | 0.002 | 0.8 | 100.0 |
| \(y\) position | 1.6 | 0.002 | 0.8 | 100.0 |
| \(z\) position | 16.0 | 0.5 | 8.0 | 2.0 |
| Roll | 5.0 | 0.0 | 0.3 | 0.5 |
| Pitch | 5.0 | 0.0 | 0.3 | 0.5 |
| Yaw | 0.02 | 0.0 | 0.06 | 0.5 |
Before passing the thrust and torque outputs to the simulator, I applied saturation limits. The gains above are reproduced from Table C.1.
LQR: derive the feedback from a local model
For hover at \(\vec p^*\),
\[ \vec x^*=(x^*,y^*,z^*,0,0,0,0,0,0,0,0,0)^T, \qquad \vec u^*=(mg,0,0,0)^T. \]
I linearised in perturbation coordinates \(\tilde{\vec x}=\vec x-\vec x^*\) and \(\tilde{\vec u}=\vec u-\vec u^*\). Near level hover, the key coupling becomes
\[ \dot v_x=g\theta,\qquad \dot v_y=-g\phi,\qquad \dot v_z=\frac{\tilde T}{m}, \]
with \(\dot\phi=\omega_x\), \(\dot\theta=\omega_y\), \(\dot\psi=\omega_z\) and \(\dot\omega_i=\tau_i/I_i\).
This gives \(\dot{\tilde{\vec x}}=A\tilde{\vec x}+B\tilde{\vec u}\). In the stated state ordering, the nonzero entries are
\[ \begin{gathered} A_{1,4}=A_{2,5}=A_{3,6}=A_{7,10}=A_{8,11}=A_{9,12}=1,\\ A_{4,8}=g,\quad A_{5,7}=-g,\\ B_{6,1}=1/m,\quad B_{10,2}=1/I_x,\quad B_{11,3}=1/I_y,\quad B_{12,4}=1/I_z. \end{gathered} \]
These nonzero entries specify the same matrices as Appendix D, without reproducing a mostly empty \(12\times12\) matrix.
I minimised
\[ J=\int_0^\infty\left(\tilde{\vec x}^{T}Q\tilde{\vec x} +\tilde{\vec u}^{T}R\tilde{\vec u}\right)\,dt. \]
Taking a quadratic value function \(V(\tilde{\vec x})=\tilde{\vec x}^{T}P\tilde{\vec x}\), the control-dependent terms in the Hamilton-Jacobi-Bellman equation are
\[ \tilde{\vec u}^{T}R\tilde{\vec u}+2\tilde{\vec x}^{T}PB\tilde{\vec u}. \]
Differentiating with respect to the control gives
\[ 2R\tilde{\vec u}+2B^{T}P\tilde{\vec x}=0, \qquad K=R^{-1}B^{T}P. \]
The stabilising solution of the continuous algebraic Riccati equation
\[ A^{T}P+PA-PBR^{-1}B^{T}P+Q=0 \]
therefore yields the physical input
\[ \vec u=\vec u^*-K(\vec x-\vec x^*). \]
Although I derived the gain from a local linear model, I applied the saturated control to the full nonlinear dynamics. I initialised the weights using Bryson’s rule, then tuned the vertical response, attitude, horizontal motion and yaw, arriving at the following weights:
\[ \begin{aligned} Q&=\operatorname{diag}(1,1,25,3,3,35,60,33,30,4,4,1),\\ R&=\operatorname{diag}(0.25,6,6,4). \end{aligned} \]
This controller has no integral state, an important distinction under sustained wind. Even where a controller achieves stability, that alone does not imply zero position error; the evaluation below measures simulated performance rather than providing a formal stability proof.
PPO: the design decisions inside the learning problem
For PPO, the actor maps the twelve-dimensional observation to a distribution over four control inputs, while the critic estimates a scalar value. Both networks use two hidden layers of 128 neurons. Once training was complete, I fixed the actor for evaluation, with no online learning.
My base reward was
\[ \begin{aligned} r_t=0.1-\big(&\|\vec p_t-\vec p^*\|^2+0.5\|\vec v_t\|^2 +4\psi_t^2\\ &+2\|\vec\omega_t\|^2+0.25\|\vec u_t-\vec u_{\mathrm{hov}}\|^2\big), \end{aligned} \]
where \(\vec u_{\mathrm{hov}}=(mg,0,0,0)^T\). In the first two curriculum phases I also penalised roll and pitch, each with weight 2. I removed those terms in the later phases: penalising tilt while asking the aircraft to lean into wind would penalise the very behaviour needed to reject the disturbance.
PPO compares a sampled action’s probability under the new and previous policies,
\[ \rho_t(\vartheta)= \frac{\pi_\vartheta(\vec u_t\mid\vec x_t)}{\pi_{\vartheta_{\mathrm{old}}}(\vec u_t\mid\vec x_t)}, \]
and uses the clipped objective
\[ L^{\mathrm{CLIP}}(\vartheta)= \mathbb E_t\left[\min\left( \rho_t(\vartheta)A_t, \operatorname{clip}(\rho_t(\vartheta),1-\epsilon,1+\epsilon)A_t \right)\right]. \]
The paper introduces the advantage as \(A_t=G_t-V_\varphi(\vec x_t)\); the implementation uses Stable-Baselines3 PPO with the following settings.
| Setting | Value |
|---|---|
| Policy | MlpPolicy |
| Hidden layers | [128, 128] |
| Learning rate | \(3\times10^{-4}\) |
| Rollout length | 2048 |
| Mini-batch size | 64 |
| Epochs per rollout | 10 |
| Discount \(\gamma\) | 0.99 |
| GAE parameter | 0.95 |
| Clipping \(\epsilon\) | 0.2 |
| Entropy coefficient | 0.01 |
I trained progressively rather than begin with the most difficult task:
| Phase | Position-control task | Wind |
|---|---|---|
| 1 | Local position control | No |
| 2 | Displacements up to 1.5 m | No |
| 3 | Displacements up to 1.5 m | Yes |
| 4 | Displacements up to 5 m | No |
| 5 | Displacements up to 5 m | Yes |
Checkpoint selection exposed a revealing reward-design problem: a controller that stayed airborne far from the target could accumulate a large negative reward over a long episode, whereas one that crashed early could avoid much of that penalty. In phases 3–5, I therefore selected checkpoints using the highest mean reward per completed time step, \(\bar r=N^{-1}\sum_{t=1}^{N}r_t\), rather than total episode reward.
Training totalled approximately 100 million environment steps and roughly 35 hours on an Apple M3 MacBook Pro with 16 GB of memory. The paper’s implementation excerpt is:
model.learn(
total_timesteps=total_timesteps,
callback=eval_callback
)The training call sits within the curriculum and evaluation setup. Its behaviour depends as much on the reward, observations and checkpoint criterion as on the choice of optimiser.
Designing a comparison that reveals failure
I evaluated every scenario against the same target, \(\vec p^*=(0,0,1)^T\), using seeds 0–19 for each controller. Episodes ran for at most 5,000 steps, or 50 seconds, with PID and LQR retaining their fixed parameter sets and PPO its fixed trained policy.
| Scenario | Initial displacement | Initial speed | Wind |
|---|---|---|---|
local_calm |
Within 0.3 m | 0 m/s | No |
local_wind |
Within 0.3 m | 0 m/s | Yes |
longrange_calm |
5 m | 0 m/s | No |
longrange_wind |
5 m | 0 m/s | Yes |
longrange_approach_calm |
5 m | 2 m/s | No |
longrange_approach_wind |
5 m | 2 m/s | Yes |
takeoff_calm |
Ground-level origin | 0 m/s | No |
takeoff_wind |
Ground-level origin | 0 m/s | Yes |
In the approach scenarios, I randomised the velocity direction around the vertical axis and sampled its elevation uniformly in \([-\pi/4,\pi/4]\). This tested whether the controllers could arrest existing motion as well as correct position. The initial velocities placed these trials outside the PPO training distribution, and take-off was also not an explicit curriculum phase.
What counts as success?
I counted an episode as a crash if it terminated early through ground contact or roll/pitch exceeding \(\pi/3\). To count as settled, the vehicle had to meet a stricter requirement: its position error had to stay below 0.1 m for a continuous five-second window, or 500 consecutive steps.
With \(e_p(t)=\|\vec p_t-\vec p^*\|\), the final-window error was
\[ e_{\mathrm{ss}}=\frac{1}{500}\sum_{t=N-499}^{N}\|\vec p_t-\vec p^*\|. \]
I also measured peak position error and mean squared departure from the hover input:
\[ e_{\mathrm{peak}}=\max_t\|\vec p_t-\vec p^*\|, \qquad U_{\mathrm{eff}}=\frac1N\sum_{t=1}^{N}\|\vec u_t-\vec u_{\mathrm{hov}}\|^2. \]
I calculated crash and settling rates by dividing the corresponding episode counts by 20, and mean settling time only over episodes that settled. The rate and time therefore need to be read together: a short conditional settling time does not compensate for a poor success rate. Similarly, control effort is a simulation input metric, not a measurement of battery energy or flight endurance.
What the experiments showed
Robustness and settling are different questions
Across the evaluation suite, PID and LQR had no crashes and both settled in every calm scenario. PPO settled in 85% of longrange_approach_calm episodes, but crashed in 15% of episodes in each approach scenario and in 10% of longrange_wind episodes.
Under wind, none of the controllers met the strict five-second settling criterion. This does not mean that they all crashed: a vehicle can remain airborne near its target while repeatedly crossing the 10 cm tolerance boundary.
Position accuracy: the effect of integral action
The steady-state-error plot helps explain the difference between remaining airborne and holding position accurately. LQR stayed airborne but retained a substantial wind-induced offset. PID’s integral action continued to adjust the command in response to persistent error, whereas this LQR formulation had no equivalent accumulated-error state.
The local trajectories at the top of the page show what that offset looks like in space. The long-range example below extends the comparison to the transient path as the vehicle approaches the target.
Speed and effort: a controller has to make a trade-off
In the calm tasks, PID reduced the error quickly, while PPO took longer to satisfy the settling criterion and used less control effort in some scenarios. The reward’s control-effort penalty could help explain those less aggressive corrections, although I did not isolate that term in an ablation study.
To look beyond those summary measures, I also examined the time histories. They reveal transient overshoot, residual offsets and variation between seeds that a single number can conceal.
Explore the complete tracking-error comparison

What I would change next
The results changed how I think about choosing a controller. I started with an expectation about learning-based control, but the experiments drew my attention to disturbance rejection, training coverage and what it takes to obtain a dependable response.
For this task, PID gave the strongest balance of precision, recovery, settling speed and interpretability. That conclusion applies to the model, controller designs, reward and operating conditions I tested; it is not a claim that PID is universally superior to reinforcement learning.
My next comparison would be LQR against Linear Quadratic Integral control, giving the model-based controller an explicit way to remove persistent position error. For PPO, I would introduce nonzero-velocity starts, broaden disturbance training, and test observation histories or a recurrent policy. Each change addresses a failure mode visible in the results, rather than adding complexity without a clear purpose.
Taking this work to the physical aircraft introduces actuator dynamics, sensor noise, latency and model mismatch. My open-loop validation checks consistency with the chosen equations, but it does not validate every assumption against flight data. Moving from this simulator to hardware therefore requires a separate experimental programme.
Technical source
Adapted from my October 2026 paper, A Comparative Evaluation of PID, LQR, and Proximal Policy Optimisation for Nonlinear Quadrotor Position Control under Stochastic Disturbances, supervised by Dr Malcolm Hillebrand. Model: Section 2 and Appendix A; parameters: Appendix B; controllers: Section 3 and Appendices C–E; experiments: Section 4; results: Section 5 and Appendix F. Figures on this page are extracted from that paper, not regenerated simulations.