PROJ·004 · UAV QUADCOPTER · MILAN · DEC 2021

Design of a Small Quadrotor UAV
and Modeling of an MPC-Based GNC Simulator

Role
Thesis Author · R&D Engineer
Organisation
Politecnico di Torino · ALTEN Italia
Period
9 monthsApr – Dec 2021
Status
COMPLETED
The Problem

GPS-denied environments, warehouses, tunnels, indoor inspection sites, make conventional UAV navigation impossible. The challenge was to design a complete quadrotor platform from commercial off-the-shelf components and develop a full GNC stack capable of attitude control, position tracking and reactive obstacle avoidance with no GNSS signal and no pre-mapped environment.

M.Sc. thesis at Politecnico di Torino, Space Engineering, in collaboration with ALTEN Italia, Milan. Covered the full stack: hardware assembly, 6-DOF quadrotor dynamics modelling, controller synthesis, and validation through both Model-in-the-Loop (MIL) and Software-in-the-Loop (SITL) pipelines.

What I Built
01 · Hardware Platform

A complete COTS quadrotor assembled for indoor GPS-denied operations. The indoor positioning solution, Marvelmind ultrasonic beacons, delivers ±2 cm position accuracy over 50 m using Time-of-Flight triangulation, replacing GPS entirely. Companion computing splits work between a Raspberry Pi 3 (mission logic) and a STM32 Nucleo (sensor parsing, NMEA over SERIAL to the Pixhawk GPS port).

> Frame Holybro X500 · 500 mm wheelbase · 470 g · full carbon fibre
> Flight ctrl Pixhawk 4 Mini · ARM Cortex-M7 @ 216 MHz · PX4 firmware
> Positioning Marvelmind HW v4.9-NIA · ±2 cm · 50 m range · ToF triangulation · 433 MHz
> Companion Raspberry Pi 3 · STM32 Nucleo (NMEA / ASHTEC to GPS1)
02 · GNC Architecture — Cascade MPC

The quadrotor dynamics were linearised around the hover equilibrium point in NED (North-East-Down) coordinates using Euler angles (φ, θ, ψ) and discretised via MATLAB's c2dm. Two cascaded architectures were designed and compared head-to-head.

The winning architecture, Solution 2, pairs an MPC outer loop acting on 10 states (horizontal position, body velocity, attitude, angular rates) with a PID inner loop on altitude. The MPC QP is solved at each timestep by a custom infeasible interior-point method (Wright, 1997) with a prediction horizon of Hp = 30 steps and hard state/input constraints.

WAYPOINTS → MPC OUTER LOOP x, y, u, v φ, θ, ψ, p, q, r Hp = 30 · QP: IIP (Wright 1997) 10 states · 6 inputs (F, τ) PID ALTITUDE z, w KP = 35.6 KI = 12.18 · KD = 0.005 QUADROTOR MODEL NED · Euler angles m = 1.5 kg · linearised hover equilibrium x* = 0 MARVELMIND ±2 cm — STATE FEEDBACK
03 · Simulation Validation — 4 Trajectory Patterns

Four trajectories of increasing complexity were designed to stress the controller across different manoeuvre regimes, from gentle square loops to a tight 1 m snail pattern with only 5 s per waypoint segment. All patterns were run in MATLAB/Simulink 2021b with Unreal Engine co-simulation for 3D visualisation, and independently replicated in AirSim + MAVLink/PX4 SITL.

Square
7 wpts · 60 s · ±3 m · NED
Butterfly
7 wpts · 60 s · ±3 m · NED
Snake
11 wpts · 100 s · ±3 m · NED
Snail — most demanding
9 wpts · 45 s · 5 s/wpt · ±1 m
HIGH AGILITY

Solution 2, MPC outer + PID altitude outperformed Solution 1 (PD outer + MPC inner) across all four patterns. The MPC produced clean waypoint-to-waypoint paths and smooth velocity references; the PD baseline showed visible overshoots at direction reversals.

PD outer + MPC inner
  • Overshoots at waypoint transitions
  • Slower settling at direction reversals
  • Less accurate velocity reference tracking
  • Altitude handled by MPC, consistent
MPC outer + PID altitude ✓
  • Near-optimal waypoint-to-waypoint path
  • Minimal overshoot on square and butterfly
  • Clean velocity reference tracking
  • Altitude: minor fluctuations, faster response
Solution 1 — PD outer + MPC inner
Simulation: Solution 1 — PD outer loop with MPC inner loop. Shows overshoots at waypoint transitions.
Solution 2 — MPC outer + PID altitude ✓
Simulation: Solution 2 — MPC outer loop with PID altitude. Shows clean waypoint-to-waypoint paths.
04 · Obstacle Avoidance — Modified APF

A modified Artificial Potential Field (APF) algorithm provides reactive collision avoidance. The standard APF is augmented with a virtual force term to escape local minima, a failure mode of classical APF that causes the vehicle to stall in saddle-point configurations. When an obstacle is detected, the APF generates corrected reference velocities that override the nominal trajectory commands before reaching the MPC controller, keeping the avoidance logic decoupled from the core control loop.

Validated across multiple trajectory patterns with 3 obstacles per run, achieving 100% avoidance success in all cases. Unreal Engine 3D visual co-simulation confirmed correct avoidance geometry at each obstacle. On longer patterns the vehicle does not complete every waypoint within the allotted window due to detour time, demonstrating genuine real-time path adaptation rather than pre-planned routing.

Key Decision

Cascade architecture over a single unified MPC. A unified MPC handling all 12 states, horizontal position, velocity, attitude, angular rates, altitude, is the theoretically cleaner solution, but solving a 12-state QP at control frequency on embedded hardware is computationally expensive and numerically sensitive to tuning. The cascade split, MPC outer loop on 10 states, PID inner loop on altitude, kept the QP tractable and gave altitude control a fast, independent tuning handle without retuning the full prediction horizon.

The cost was coupling: the altitude loop can't anticipate the MPC's horizontal trajectory, so vertical disturbances don't feed into the optimal horizontal plan. On the tested trajectories this was acceptable. On longer-range trajectories with significant altitude variation, it becomes a real limitation.

The Hardest Problem

The classical APF formulation caused the vehicle to stall at saddle-point configurations between obstacles, a known failure mode where the attractive and repulsive forces cancel, leaving the vehicle with zero net guidance. Standard goal-directed augmentation didn't generalise to dynamic replanning scenarios where the vehicle needs to adapt mid-trajectory.

The fix was a virtual escape force term that activates when velocity drops below a threshold near an obstacle, introducing a perturbation orthogonal to the stall axis. This allowed the vehicle to break out of saddle points and resume trajectory tracking without pre-planned routing, validated at 100% avoidance success across all simulation runs with 3 obstacles at varying distances.

Outcomes
±2 cm
Indoor positioning, Marvelmind ToF ultrasonic, full GPS replacement
MIL + SITL
Two independent validation pipelines, Simulink/Unreal Engine and AirSim/PX4 SITL, run on all 4 trajectory patterns
100%
Obstacle avoidance success, modified APF across all simulation runs, 3 obstacles
4 patterns
From gentle square loops to 5 s/waypoint snail, all trajectories validated end-to-end
What I'd Do Differently

I would spend less time studying the PID controller already embedded in the Pixhawk 4 autopilot and instead bypass it earlier, implementing a simple PID from scratch directly on the quadrotor. The goal was always to extract a dynamic model and inertia values for MPC, and a clean from-scratch implementation makes the system dynamics far more transparent than reverse-engineering PX4's source code. In practice, I spent a significant amount of time studying the Pixhawk's internal PID implementation before realising it added no useful information for the control law I was building. Starting from a minimal, self-owned controller from day one would have made the path to MPC shorter and the dynamics understanding deeper.

Skills Gained
Transferable beyond the UAV domain
AirSim + Unreal Engine 4: closed-loop simulation for 6-DOF rigid body dynamics
MATLAB / Simulink: control law synthesis and MIL/SIL validation pipeline
MPC with QP solver: receding-horizon optimisation with hard state and input constraints
Pixhawk 4 Mini + PX4: autopilot integration for autonomous platforms
Raspberry Pi 3 + STM32: companion computing and sensor parsing on constrained hardware
Marvelmind ultrasonic: ToF indoor localisation ±2 cm without GNSS
MAVLink: autopilot communication protocol over serial and UDP telemetry
Artificial Potential Fields: reactive obstacle avoidance with saddle-point escape for mobile autonomous agents
BLDC + ESC: motor and power electronics integration
PID cascade: inner/outer loop tuning on physical hardware