Return to system

Project

Fixed-Wing 6-DOF Flight Dynamics & Robust Control Simulator

Nonlinear Flight Dynamics · Autonomous Control · State Estimation · Robustness

Built a nonlinear fixed-wing UAV simulation from the rigid-body equations upward, then designed PID and nonlinear dynamic-inversion flight controllers and tested them with realistic actuators, noisy sensors, EKF state estimation, wind and Dryden turbulence.

Python6-DOF DynamicsFlight ControlEKFNDIDryden TurbulenceNumerical Modelling
Architecture

Closed-loop simulator

Each layer is a separate system, validated on its own, then closed into one loop. The controller only ever sees estimated state — never simulator truth — when the EKF is active.

Environment
Aircraft Dynamics
Sensors
EKF
Controller
Actuators
01 — Aircraft Model

Nonlinear rigid-body model

A full nonlinear rigid-body fixed-wing model in a 13-state quaternion representation, integrated with a fixed-step RK4 solver at 500 Hz (dt = 0.002 s).

State (13)
  • 3D position
  • Body-frame velocity
  • Quaternion attitude
  • Body angular rates
Dynamics
  • Translational motion
  • Rotational motion
  • Coriolis coupling
  • Full inertia tensor
  • Gyroscopic coupling
  • Gravity transformation
  • Quaternion kinematics
02 — Aerodynamics & Propulsion

Forces and moments from air-relative flow

Aerodynamic forces and moments are computed from angle of attack, sideslip, body rates and control-surface deflections, using an Aerosonde coefficient set and a parabolic drag polar. Forces use air-relative velocity, so atmospheric wind actually changes the aerodynamics.

CD = CD0 + CL² / (π · e · AR)
Inputs
  • Angle of Attack
  • Sideslip
  • Body Rates
  • Aileron
  • Elevator
  • Rudder
Outputs
  • Lift
  • Drag
  • Side Force
  • Roll Moment
  • Pitch Moment
  • Yaw Moment
ISA AtmospherePropeller ThrustDynamic PressureWind → Body Frame Transformations

Thrust acts through the CG. Propeller reaction torque, p-factor and propeller gyroscopic effects are intentionally omitted — not modelled and not claimed.

03 — Trim Solver

Numerical steady-flight trim

Given airspeed, altitude and flight-path angle, a numerical solver finds the angle of attack, elevator and throttle required for steady flight. Accepted trim residuals are below 1 × 10⁻¹⁰.

Validated airspeeds
  • 18 m/s
  • 25 m/s
  • 35 m/s
Flight-path angles
  • −2°
  • 0°
  • +5°

Unreachable operating points are reported as unreachable rather than moving the benchmark to make the solver pass.

Trim envelope across the validated airspeed / flight-path grid.
Trim envelope across the validated airspeed / flight-path grid.
04 — Linearisation & Modes

Linear model and flight modes

The nonlinear model is linearised around trim with central finite differences, then split into longitudinal and lateral-directional dynamics with automatic mode identification.

δẋ = A·δx + B·δu
Identified modes
  • Short Period
  • Phugoid
  • Dutch Roll
  • Roll Subsidence
  • Spiral Mode
Per-mode quantities
  • Eigenvalue
  • Natural Frequency
  • Damping Ratio
  • Period
  • Time to Half
Root locus of the identified longitudinal and lateral modes.
Root locus of the identified longitudinal and lateral modes.
05 — Model Validation

Linear vs nonlinear

The linear model is checked against the full nonlinear simulator — matching for small perturbations and deliberately diverging for large ones. The point is to show the A/B matrices were validated, not assumed.

Small perturbation — linear ≈ nonlinear.
Small perturbation — linear ≈ nonlinear.
Large perturbation — linear model diverges from the plant.
Large perturbation — linear model diverges from the plant.
06 — Baseline Autopilot

Cascaded PID architecture

Altitude / Airspeed / Heading
Outer Loop10 Hz
Roll / Pitch Commands
Attitude Loop50 Hz
p / q / r Commands
Body-Rate Loop200 Hz
Aileron · Elevator · Rudder · Throttle
Derivative-on-MeasurementDerivative FilteringIntegral ActionSaturationBack-Calculation Anti-Windup
07 — TECS-Lite

Coupled altitude / airspeed control

The outer loop uses a simplified Total Energy Control System: throttle controls total energy while pitch controls how energy is distributed between altitude and airspeed, so the two work together rather than as independent loops. Heading changes add coordinated-turn yaw-rate feed-forward.

08 — Perfect-World Baseline

Ideal-model performance

The baseline controller flies the committed ideal-model scenarios — Mission A (climb / turn / cruise), step responses and disturbance rejection — with no envelope violations and no surface saturation.

Disturbance · Altitude RMSE1.32 m
Disturbance · Airspeed RMSE0.32 m/s
Mission A · Altitude RMSE11.27 m
Mission A · Airspeed RMSE2.91 m/s
Mission A — climb / turn / cruise.
Mission A — climb / turn / cruise.
Step responses.
Step responses.
Disturbance rejection.
Disturbance rejection.
09 — Making It Realistic

Replacing ideal assumptions

Perfect Aircraft
Actuator DynamicsNoisy SensorsState EstimationSteady WindDryden Turbulence
Realistic Closed Loop
10 — Actuators

Surfaces do not move instantly

First-Order LagRate LimitPosition Limit
±25° travel286°/s rate limit0.05 s time constantSlower throttle dynamics
11 — Sensors

Simulated sensor suite

GyroscopeAccelerometerGPS PositionGPS VelocityPitotBarometerMagnetometer
Each sensor can include
  • Sampling Rate
  • White Noise
  • Random-Walk Bias
  • Zero-Order Hold
Typical rates
  • IMU — 200 Hz
  • GPS — 5 Hz
  • Pitot / Barometer / Magnetometer — 50 Hz
12 — Extended Kalman Filter

15-error-state navigation EKF

A 15-error-state navigation EKF tracks position, velocity, quaternion attitude and gyro / accelerometer biases, fusing IMU, GPS, barometer, pitot and magnetometer at their own rates.

Tracks
  • Position
  • Velocity
  • Quaternion Attitude
  • Gyroscope Bias
  • Accelerometer Bias
Mechanics
  • Predict / Update
  • Sensor Fusion
  • Bias Estimation
  • Joseph Covariance Update
  • Multi-Rate Measurements

Accelerometer attitude corrections reject strongly dynamic specific-force measurements, so manoeuvre acceleration and turbulence are not mistaken for gravity.

13 — Wind & Turbulence

Steady wind and Dryden turbulence

The environment adds steady wind with optional altitude shear, and Dryden turbulence via shaping filters at light / moderate / severe levels. The realistic benchmark uses 5 m/s steady wind at 45° with moderate Dryden turbulence.

Steady wind + shearDryden shaping filtersLightModerateSevere
14 — Degradation Study

Which realism actually hurts control?

An ablation study isolates which realism mechanisms degrade tracking, scored by Altitude RMSE + 4 × Airspeed RMSE. Overall it rose from 16.008 → 37.937 between the perfect (C0) and fully realistic (C5) configurations.

Actuators
-0.1%
Sensors + EKF
+177.5%
Steady Wind
+0.8%
Turbulence
+25.3%
Full Realistic Model
+137%

The sensor / estimator chain produced the largest isolated degradation (+177.5%) — not the wind or actuator model.

Isolated contribution of each realism mechanism.
Isolated contribution of each realism mechanism.
15 — Nonlinear Dynamic Inversion

A model-based rate controller

An alternative angular-rate controller using Nonlinear Dynamic Inversion. It computes the angular acceleration it wants, then approximately inverts the aircraft's angular dynamics for the required surface commands.

ω̇ = f(x, air) + g(air)·δ
Terms
  • f = uncontrolled angular dynamics
  • g = control-surface effectiveness
  • δ = aileron / elevator / rudder
16 — Control Allocation

Distributing demand across surfaces

NDI does not command each surface independently. Multivariable allocation redistributes the achievable demand across the free surfaces when one control reaches its limit.

Weighted Least SquaresPseudo-Inverse AllocationSurface LimitsSaturation DetectionDemand Redistribution
17 — Robustness Guards

Not naïve textbook inversion

Dynamic-Pressure FloorCondition-Number MonitoringMinimum Singular-Value MonitoringDamped Pseudo-InverseVirtual Acceleration LimitsLow-Speed PID BlendingSurface Saturation HandlingMultivariable Anti-Windup

The controller logs its numerical health so poor conditioning or allocation failure can be investigated after a run.

18 — Partial Inversion

An engineering decision from testing

Full aerodynamic cancellation was too sensitive to estimated air-angle errors. The screened operational candidate used only partial cancellation blended with the baseline PID.

Static aero cancellation10%
NDI blend30%
Baseline PID blend70%
Filter0.08 s
19 — PID vs NDI

A negative result, kept

Hypothesis → implementation → fair test → result. In the sensor-aware screening test (lower is better):

PID reference10.031
vs
Best screened NDI / PID12.627

The current NDI candidate did not beat the competent PID baseline strongly enough to pass the project gate. A separate provisional realistic 36-flight comparison gave NDI mean tracking 35.96 and PID 37.94 — but both achieved 0% success under the frozen strict mission criteria, and the repository marks this result as provisional.

NDI is not claimed to be superior. The negative result is reported as it stands.

20 — Fair Comparison

Same conditions for both controllers

PID and NDI are compared under identical conditions; neither sees simulator truth while the EKF is active.

Same EstimatorSame ActuatorsSame WindSame TurbulenceSame ScenarioSame Random SeedSame MetricsSame Aircraft Configuration
21 — Model-Mismatch Testing

NDI sensitivity to model error

A resumable framework sweeps errors in the NDI internal aircraft model with paired PID comparisons.

CmαCmδeClδaIyyMass

The full large-mismatch campaign is not finished — the project deliberately blocks the expensive campaign until a nominal NDI pilot first outperforms PID.

22 — Reproducible Research

Frozen benchmarks, recorded provenance

Version-controlled
  • Reference Frames
  • Control Signs
  • Aircraft Parameters
  • Integration Settings
  • Success Criteria
  • Scenario Definitions
Recorded per result
  • Git Commit
  • Config Hash
  • Random Seed
  • Controller Version
  • Dirty / Clean Worktree State

Seeded random streams let stochastic comparisons be reproduced and controllers compared on identical disturbances.

23 — Testing

Validation gates, not eyeballed plots

Quaternion MathematicsRigid-Body DynamicsMomentum / Energy BehaviourAerodynamic SignsAir DataPropulsionTrimLinearisationAircraft ModesPIDAutopilot LoopsActuatorsSensorsWindEKFNDIControl Allocation

The project advances through validation gates rather than accepting “the plot looks right” as proof.

Roadmap

Planned next stages

Not yet implemented — future phases, not current results:

CMA-ES controller optimisationGaussian Process / ML residual modelling10,000-case Monte Carlo campaignFinal statistical robustness probability
Skills Developed

What the project built up

Flight Dynamics

Nonlinear 6-DOF ModellingRigid-Body DynamicsQuaternion KinematicsAircraft TrimLinearisationFlight Mode IdentificationStability Analysis

Aerodynamics

Aerodynamic DerivativesForce & Moment ModellingAir-Data ModellingWind-Relative Flight

Control

Cascaded PIDAnti-WindupTECSRate ControlAttitude ControlNonlinear Dynamic InversionControl Allocation

Estimation

Extended Kalman FilteringSensor FusionBias EstimationMulti-Rate Sensors

Numerical Methods

RK4Nonlinear Least SquaresFinite-Difference LinearisationEigenvalue AnalysisSVDPseudo-Inverse Methods

Robustness / Experimentation

Ablation StudiesDryden TurbulenceModel MismatchPaired ExperimentsReproducible SimulationStochastic Testing

Software

PythonNumPySciPypytestPydanticYAMLMatplotlibParallel Simulation