2D UAV Modelling & PID Control Simulation
System Design & ApplicationsModelling and Control of Dynamical Systems using Linear and Nonlinear Differential Equations · Leuphana Universität Lüneburg
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
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
Post-Run Statistics
- —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