← Back to Projects

2D UAV Modelling & PID Control Simulation

System Design & Applications

Modelling and Control of Dynamical Systems using Linear and Nonlinear Differential Equations · Leuphana Universität Lüneburg

UAV chasing a target balloon in simulation
Live simulation — UAV autonomously navigates to sequential balloon targets using cascaded PID control and physics-based equations of motion

Overview

A physics-based 2D drone simulation where a UAV autonomously chases a target balloon using equations of motion derived from first principles and a cascaded PID controller. The UAV starts at centre, a balloon spawns at a random position, and the drone navigates to n=3 sequential targets before stabilising to rest. PID gains were tuned in MATLAB Simulink then ported to C++/SFML for real-time rendering.

Physics Model

Three forces act on the rigid body per frame: T_left and T_right (propeller thrusts upward) and gravity downward. When the drone tilts by angle θ:

s̈_x = −(T_left + T_right) · sin(θ) / m

s̈_y = −(T_left + T_right) · cos(θ) / m + g

θ̈ = ARM · (T_right − T_left) / m

Velocity and position are integrated each frame using v = u + at and s = vt.

PID Control — Simulink Model

MATLAB Simulink PID model
MATLAB Simulink model — two cascaded PID loops for altitude control (top) and attitude control (bottom), with integrator chains modelling the physics

Two cascaded PID loops, tuned in Simulink and ported to C++:

  • Altitude control — Y error → velocity setpoint → thrust magnitude
  • Attitude control — X error → angle setpoint → thrust differential

Simulink Convergence Plots

Simulink X direction convergence
X distance — overshoots then settles at ~2 (expected second-order response)
Simulink Y direction convergence
Y distance — clean first-order response, settles at ~5 with minimal overshoot

Post-Run Statistics

Position, velocity and acceleration plots from stats.py
stats.py output — position, velocity, and acceleration in x and y directions logged to output.csv and plotted after simulation run
  • Position ramps to target in ~3.5s
  • Velocity peaks then decays — consistent with expected PID response
  • Acceleration becomes erratic near target as PID corrects rapidly — normal second-order behaviour

Stack

C++ / SFML MATLAB Simulink PID Control Differential Equations Rigid Body Physics Python CMake