In recent years, quadrotor drones have become increasingly prominent in various fields such as agriculture, construction, logistics, and environmental monitoring due to their ability to perform vertical take-off and landing, aerial hovering, and high maneuverability. As a typical nonlinear, multi-channel coupled, and multi-input multi-output system, designing an effective control system for a quadrotor drone requires careful consideration of both attitude and position control. In this paper, I present a comprehensive study on the control system of a quadrotor drone, focusing on mathematical modeling, controller design, and simulation using software-in-the-loop (SITL) techniques. The simulation environment is built on ROS melodic, Gazebo, PX4 flight control, and QGroundControl (QGC), with MAVLink facilitating communication. Through extensive experiments, including hovering, yaw maneuvers, and trajectory planning, I validate the hardware feasibility of the proposed control system and demonstrate its performance in a simulated real-world environment with introduced noise.
The core of this research lies in developing a robust control framework for quadrotor drones. A quadrotor drone is inherently unstable and requires precise control of its four rotors to achieve desired flight behaviors. I begin by establishing a simplified physical model of the quadrotor drone based on Newton-Euler equations. To facilitate analysis, I assume the quadrotor drone is a rigid body with uniform symmetry, constant mass and moment of inertia, coincident geometric and gravity centers, and influenced only by gravity and propeller thrust. The propellers are arranged in an “X” configuration, with two rotating clockwise and two counterclockwise to balance torque.
The dynamics and kinematics of the quadrotor drone are derived in Earth and body coordinate systems. Let $m$ denote the mass, $g$ the gravitational acceleration, and $f$ the total thrust generated by the propellers. The position vector in Earth frame is $\mathbf{p}^e = [x, y, z]^T$, and the velocity vector is $\mathbf{v}^e = [v_x, v_y, v_z]^T$. The attitude is represented by Euler angles $\boldsymbol{\theta} = [\phi, \theta, \psi]^T$ (roll, pitch, yaw), and the angular velocity in body frame is $\boldsymbol{\omega}^b = [p, q, r]^T$. The rotation matrix from body to Earth frame, $R_b^e$, is given by:
$$ R_b^e = \begin{bmatrix}
\cos\theta \cos\psi & \sin\phi \sin\theta \cos\psi – \cos\phi \sin\psi & \cos\phi \sin\theta \cos\psi + \sin\phi \sin\psi \\
\cos\theta \sin\psi & \sin\phi \sin\theta \sin\psi + \cos\phi \cos\psi & \cos\phi \sin\theta \sin\psi – \sin\phi \cos\psi \\
-\sin\theta & \sin\phi \cos\theta & \cos\phi \cos\theta
\end{bmatrix} $$
Using Newton’s second law, the translational dynamics are:
$$ m \dot{\mathbf{v}}^e = \mathbf{G}^e – \mathbf{f}^b $$
where $\mathbf{G}^e = [0, 0, mg]^T$ and $\mathbf{f}^b = [0, 0, f]^T$. Transforming to Earth frame:
$$ \dot{\mathbf{v}}^e = g \mathbf{e}_3 – \frac{f}{m} R_b^e \mathbf{e}_3 $$
with $\mathbf{e}_3 = [0, 0, 1]^T$. Expanding this yields:
$$ \begin{aligned}
\dot{v}_x &= -\frac{f}{m} (\cos\psi \sin\theta \cos\phi + \sin\psi \sin\phi) \\
\dot{v}_y &= -\frac{f}{m} (\sin\psi \sin\theta \cos\phi – \cos\psi \sin\phi) \\
\dot{v}_z &= g – \frac{f}{m} \cos\phi \cos\theta
\end{aligned} $$
The kinematic equations for position and attitude are:
$$ \dot{\mathbf{p}}^e = \mathbf{v}^e $$
and
$$ \dot{\boldsymbol{\theta}} = W \boldsymbol{\omega}^b $$
where $W$ is the transformation matrix:
$$ W = \begin{bmatrix}
1 & \tan\theta \sin\phi & \tan\theta \cos\phi \\
0 & \cos\phi & -\sin\phi \\
0 & \frac{\sin\phi}{\cos\theta} & \frac{\cos\phi}{\cos\theta}
\end{bmatrix} $$
Thus,
$$ \begin{bmatrix} \dot{\phi} \\ \dot{\theta} \\ \dot{\psi} \end{bmatrix} = \begin{bmatrix}
1 & \tan\theta \sin\phi & \tan\theta \cos\phi \\
0 & \cos\phi & -\sin\phi \\
0 & \frac{\sin\phi}{\cos\theta} & \frac{\cos\phi}{\cos\theta}
\end{bmatrix} \begin{bmatrix} p \\ q \\ r \end{bmatrix} $$
For small disturbances, this simplifies to $\dot{\boldsymbol{\theta}} \approx \boldsymbol{\omega}^b$. This mathematical model forms the basis for controller design.

To simulate the quadrotor drone control system, I set up a comprehensive SITL environment. The system architecture integrates several components: the Gazebo simulator for 3D visualization and physics, PX4 flight control stack for real-time control algorithms, QGroundControl for ground station operations, and ROS melodic for middleware communication. MAVLink protocol is employed to establish communication between PX4, QGC, and Gazebo. This lightweight messaging protocol uses a publish-subscribe model with point-to-point features, ensuring reliable data exchange for commands and sensor feedback. Each MAVLink packet includes a header, message type, length, parameters, and CRC for error checking, with the polynomial $x^{16} + x^{15} + x^{13} + 1$.
In Gazebo, I created a quadrotor drone model using SDF files, defining geometric shapes, joints, and sensors such as IMU and GPS. Noise was added to sensor outputs to mimic real-world conditions. The PX4 system runs on NuttX RTOS, utilizing uORB for inter-process communication via topics. This allows modules like attitude estimator and controller to publish and subscribe to data efficiently. QGC provides a user interface for manual control and mission planning. The integration is achieved through UDP sockets, with PX4 sending control messages to Gazebo and receiving simulated sensor data in return.
The controller design employs a cascade structure with inner loops for attitude control and outer loops for position control. This approach decouples the complex dynamics of the quadrotor drone. For position control, let the desired position be $\mathbf{p}_r^e = [x_r, y_r, z_r]^T$ and errors be $e_x = x – x_r$, $e_y = y – y_r$, $e_z = z – z_r$. From the dynamics, the accelerations are:
$$ \begin{aligned}
\ddot{e}_x &= c_4 U_1 (\cos\psi \sin\theta \cos\phi + \sin\psi \sin\phi) \\
\ddot{e}_y &= c_4 U_1 (\sin\psi \sin\theta \cos\phi – \cos\psi \sin\phi) \\
\ddot{e}_z &= c_4 U_1 \cos\theta \cos\phi – g
\end{aligned} $$
where $c_4 = -\frac{1}{m}$ and $U_1$ is the thrust control input. PID controllers are designed as:
$$ \begin{aligned}
\ddot{e}_x &= U_x = -K_{pu} u – K_{du} \dot{u} – K_{px} e_x \\
\ddot{e}_y &= U_y = -K_{pv} v – K_{dv} \dot{v} – K_{py} e_y \\
\ddot{e}_z &= U_z = -K_{pz} e_z – K_{dz} \dot{e}_z
\end{aligned} $$
Here, $u$ and $v$ are intermediate velocity terms. The gains are tuned to ensure stability and performance.
For attitude control, double-loop controllers are used. The outer loop controls Euler angles with error dynamics:
$$ \begin{aligned}
\dot{e}_\phi &= -k_1 e_\phi \\
\dot{e}_\theta &= -k_2 e_\theta \\
\dot{e}_\psi &= -k_3 e_\psi
\end{aligned} $$
where $e_\phi = \phi – \phi_r$, etc. For $k_1, k_2, k_3 > 0$, errors converge to zero. The inner loop controls angular rates with errors $e_p = p – p_r$, $e_q = q – q_r$, $e_r = r – r_r$:
$$ \begin{aligned}
\dot{e}_p &= -k_4 e_p \\
\dot{e}_q &= -k_5 e_q \\
\dot{e}_r &= -k_6 e_r
\end{aligned} $$
with $k_4, k_5, k_6 > 0$. This cascade structure enables precise tracking of desired attitudes.
To summarize the controller parameters, I use the following table:
| Control Loop | Parameter | Symbol | Typical Value Range |
|---|---|---|---|
| Position (X,Y) | Proportional Gain | $K_{px}$, $K_{py}$ | 0.5 – 2.0 |
| Derivative Gain | $K_{dx}$, $K_{dy}$ | 0.1 – 0.5 | |
| Integral Gain | $K_{ix}$, $K_{iy}$ | 0.01 – 0.1 | |
| Position (Z) | Proportional Gain | $K_{pz}$ | 1.0 – 3.0 |
| Derivative Gain | $K_{dz}$ | 0.2 – 0.8 | |
| Integral Gain | $K_{iz}$ | 0.05 – 0.2 | |
| Attitude (Outer) | Roll Gain | $k_1$ | 5 – 15 |
| Pitch Gain | $k_2$ | 5 – 15 | |
| Yaw Gain | $k_3$ | 2 – 8 | |
| Attitude (Inner) | Roll Rate Gain | $k_4$ | 0.1 – 0.5 |
| Pitch Rate Gain | $k_5$ | 0.1 – 0.5 | |
| Yaw Rate Gain | $k_6$ | 0.05 – 0.3 |
Simulation experiments were conducted to validate the control system. After establishing communication between PX4, Gazebo, and QGC, I configured the quadrotor drone model with noise enabled for GPS and IMU. The SITL simulation was initiated by running PX4 with Gazebo, and QGC was connected for monitoring and control. The quadrotor drone was armed and takeoff commands were issued.
In the hovering test, the quadrotor drone was commanded to maintain a fixed position at $z = 5$ meters. The Gazebo simulation showed stable hovering, and sensor data from QGC indicated minimal deviation. The following table compares desired and actual positions over a 10-second interval:
| Time (s) | Desired Z (m) | Actual Z (m) in Gazebo | Error (m) |
|---|---|---|---|
| 0 | 5.00 | 5.00 | 0.00 |
| 2 | 5.00 | 4.98 | 0.02 |
| 4 | 5.00 | 5.01 | 0.01 |
| 6 | 5.00 | 4.99 | 0.01 |
| 8 | 5.00 | 5.02 | 0.02 |
| 10 | 5.00 | 5.00 | 0.00 |
The error remains within $\pm 0.02$ meters, demonstrating effective position control. This performance is crucial for applications where the quadrotor drone must remain stationary, such as aerial photography or surveillance.
For yaw and roll-pitch maneuvers, I designed a trajectory with waypoints in QGC. The quadrotor drone was tasked to take off, visit four waypoints at different altitudes and orientations, and return to home for landing. The waypoints were set as: Waypoint 2 at $(x=5, y=0, z=5)$ with yaw $90^\circ$, Waypoint 3 at $(x=5, y=5, z=7)$ with roll $10^\circ$, Waypoint 4 at $(x=0, y=5, z=5)$ with pitch $-5^\circ$, and Waypoint 5 at $(x=0, y=0, z=3)$. The Gazebo simulation showed smooth transitions, with the quadrotor drone quickly responding to attitude changes. The attitude tracking performance is summarized below:
| Maneuver | Desired Angle (deg) | Actual Angle (deg) | Rise Time (s) | Overshoot (%) |
|---|---|---|---|---|
| Yaw to 90° | 90.0 | 89.5 | 1.2 | 2.5 |
| Roll to 10° | 10.0 | 9.8 | 0.8 | 1.0 |
| Pitch to -5° | -5.0 | -4.9 | 0.9 | 1.5 |
The quadrotor drone achieved the desired angles with minimal error and fast response, validating the attitude controller. The cascade structure effectively decouples the axes, allowing independent control despite inherent couplings.
Trajectory planning experiments involved complex paths to test the integrated system. Using QGC, I uploaded a square trajectory with side length 10 meters at a constant altitude of 5 meters. The quadrotor drone successfully followed the path, with position errors logged in Gazebo. The root-mean-square error (RMSE) for $x$ and $y$ positions was calculated as:
$$ \text{RMSE}_x = \sqrt{\frac{1}{N} \sum_{i=1}^N (x_i – x_{r,i})^2 } $$
and similarly for $y$. Over 100 data points, $\text{RMSE}_x = 0.15$ m and $\text{RMSE}_y = 0.18$ m. These small errors indicate that the quadrotor drone can accurately track planned trajectories, which is essential for autonomous missions.
To further analyze performance, I introduced white noise with standard deviation $\sigma = 0.1$ for position sensors and $\sigma = 0.05$ rad for attitude sensors. The controllers maintained stability, with errors increasing slightly but remaining within acceptable bounds. For example, during hovering with noise, the standard deviation of $z$ position was $0.05$ m, compared to $0.02$ m without noise. This robustness is critical for real-world deployments where sensor imperfections are common.
The communication between components was monitored using MAVLink message rates. PX4 sent actuator controls at 250 Hz, while Gazebo returned sensor data at 200 Hz. QGC displayed real-time telemetry at 10 Hz. No packet loss occurred, thanks to MAVLink’s reliability features. The uORB topics in PX4, such as actuator_outputs and vehicle_attitude, showed consistent data flow, ensuring timely control updates.
In terms of computational efficiency, the PX4 stack on NuttX RTOS utilized less than 70% of CPU resources during simulation, leaving headroom for additional tasks. This efficiency is beneficial for actual hardware implementation, where resource constraints exist. The quadrotor drone model in Gazebo included realistic physics parameters, such as motor time constants and drag coefficients, enhancing simulation fidelity.
Overall, the simulation results confirm the hardware feasibility of the proposed control system for quadrotor drones. The Gazebo data closely matches QGC theoretical data, with errors attributable to noise and discretization. The quadrotor drone responds swiftly to commands, achieving hovering, attitude changes, and trajectory following with high accuracy. This work provides a foundation for deploying such controllers on physical quadrotor drones, with potential extensions to obstacle avoidance, swarm coordination, and adaptive control.
Future work will focus on optimizing controller gains using machine learning techniques, integrating vision-based sensors for navigation, and testing on hardware platforms. The simulation framework developed here will serve as a valuable tool for rapid prototyping and validation of advanced algorithms for quadrotor drones.
In conclusion, this research demonstrates a comprehensive approach to quadrotor drone control system design and simulation. By leveraging ROS, Gazebo, PX4, and QGC, I have created a robust SITL environment that mimics real-world conditions. The cascade PID controllers effectively manage the nonlinear dynamics of the quadrotor drone, as evidenced by successful experiments. The insights gained from this study will contribute to the ongoing development of autonomous quadrotor drones for diverse applications.
