In recent years, the quadrotor unmanned aerial vehicle (UAV) has emerged as a versatile platform in fields such as agriculture, logistics, and environmental monitoring due to its vertical take-off and landing, hovering capabilities, and high maneuverability. As a nonlinear, multi-channel coupled, and multi-input multi-output system, designing an effective control system for a quadrotor requires addressing both attitude and position control. This paper presents a comprehensive study on the control system of a quadrotor, utilizing a software-in-the-loop (SITL) simulation framework. The simulation integrates the PX4 flight control system based on the NuttX operating system, the Gazebo simulator for modeling, and the QGroundControl (QGC) ground station for mission planning. By employing the MAVLink communication protocol and introducing white noise to mimic real-world conditions, we validate the hardware feasibility of the control system through experiments including hovering, yaw maneuvers, and trajectory planning. The results demonstrate minimal error between Gazebo experimental data and QGC theoretical data, with rapid quadrotor response, confirming the system’s efficacy.
The quadrotor’s dynamics are inherently complex, necessitating a robust mathematical model for control design. In this work, we derive the dynamics and kinematics models using Newton-Euler equations, assuming the quadrotor as a symmetric rigid body with coincident center of gravity and geometric center. The control strategy employs a cascaded PID approach, with an inner loop for attitude control and an outer loop for position control. The simulation environment is built on Ubuntu 20.04 with ROS Melodic, leveraging tools like Gazebo for 3D simulation and PX4 for flight control. Key components such as MAVLink for communication and uORB for message handling are detailed, followed by experimental validation of the control system’s performance in various flight scenarios.

To model the quadrotor, we define two coordinate systems: the Earth-fixed frame and the body-fixed frame. The dynamics model describes the motion under forces and moments, while the kinematics model relates velocities to positions and attitudes. The control inputs are the thrust and moments generated by the rotors, with the quadrotor structure configured in an “X” pattern where rotors 1 and 3 rotate counterclockwise and rotors 2 and 4 rotate clockwise. The dynamics equation based on Newton’s second law is given by:
$$ m \dot{\mathbf{v}}^e = \mathbf{G}^e – \mathbf{f}^b $$
where \( \mathbf{v}^e \) is the velocity vector in the Earth frame, \( \mathbf{G}^e \) is the gravity vector, and \( \mathbf{f}^b \) is the thrust force in the body frame. By applying the rotation matrix \( R_b^e \) and simplifying, we obtain the acceleration components in the Earth frame:
$$ \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} $$
Here, \( \phi \), \( \theta \), and \( \psi \) represent the roll, pitch, and yaw angles, respectively, \( f \) is the total thrust, \( m \) is the mass, and \( g \) is gravitational acceleration. The position kinematics are described by \( \dot{\mathbf{p}}^e = \mathbf{v}^e \), where \( \mathbf{p}^e = [x, y, z]^T \). For attitude kinematics, the relationship between Euler angles and angular velocities is expressed as:
$$ \dot{\boldsymbol{\theta}} = \mathbf{W} \cdot \boldsymbol{\omega}^b $$
with \( \boldsymbol{\theta} = [\phi, \theta, \psi]^T \) and \( \boldsymbol{\omega}^b = [p, q, r]^T \) being the angular velocities in the body frame. The matrix \( \mathbf{W} \) is defined as:
$$ \mathbf{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} $$
For small perturbations, this simplifies to \( \dot{\boldsymbol{\theta}} \approx \boldsymbol{\omega}^b \), facilitating controller design. The quadrotor model parameters used in simulation are summarized in Table 1, which includes mass, inertia, and control gains.
| Parameter | Symbol | Value | Unit |
|---|---|---|---|
| Mass | \( m \) | 1.5 | kg |
| Moment of Inertia (X) | \( I_{xx} \) | 0.03 | kg·m² |
| Moment of Inertia (Y) | \( I_{yy} \) | 0.03 | kg·m² |
| Moment of Inertia (Z) | \( I_{zz} \) | 0.04 | kg·m² |
| Gravity | \( g \) | 9.81 | m/s² |
| Thrust Coefficient | \( c_t \) | 1.2e-5 | N·s² |
| Drag Coefficient | \( c_d \) | 1.8e-7 | N·m·s² |
The simulation environment leverages the Robot Operating System (ROS) Melodic framework on Ubuntu 20.04, integrating Gazebo for 3D physics simulation, PX4 for flight control, and QGC for ground station operations. The MAV system architecture, as illustrated in the context, involves Gazebo simulating the quadrotor’s physical model, including sensors like IMU and GPS, with added white noise to emulate real-world imperfections. The PX4 flight stack, built on the NuttX real-time operating system, handles flight control algorithms, while uORB (micro Object Request Broker) manages inter-process communication through a publish-subscribe mechanism. MAVLink, a lightweight messaging protocol, facilitates communication between PX4, Gazebo, and QGC using UDP for SITL simulation. Key MAVLink messages include HIL_ACTUATOR_CONTROLS for actuator commands and sensor feedback for state estimation.
In Gazebo, the quadrotor model is defined using an SDF (Simulation Description Format) file, specifying geometric properties, joints, and sensors. For instance, the IMU sensor provides attitude data, while the GPS module offers position updates. The communication setup involves initializing PX4 with Gazebo via SITL, where PX4 sends control signals to Gazebo and receives simulated sensor data. QGC connects to PX4 for mission planning and monitoring, enabling tasks such as waypoint navigation and real-time parameter tuning. The integration ensures that the quadrotor responds accurately to control inputs, with data consistency across platforms.
The controller design for the quadrotor employs a cascaded structure, with an outer loop for position control and an inner loop for attitude control. This approach decouples the nonlinear dynamics, allowing for simpler PID implementations. The position controller regulates the quadrotor’s coordinates \( (x, y, z) \) in the Earth frame. Define the position errors as \( e_x = x – x_r \), \( e_y = y – y_r \), and \( e_z = z – z_r \), where \( x_r, y_r, z_r \) are reference positions. From the dynamics model, the acceleration equations 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 \( U_1 \) is the total thrust input, and \( c_4 \) is a control gain. Using PID control, the virtual control inputs \( U_x, U_y, U_z \) are constructed as:
$$ \begin{aligned}
U_x &= -K_{pu} e_x – K_{du} \dot{e}_x \\
U_y &= -K_{pv} e_y – K_{dv} \dot{e}_y \\
U_z &= -K_{pz} e_z – K_{dz} \dot{e}_z
\end{aligned} $$
These are then mapped to desired attitudes and thrust. The attitude controller uses a dual-loop design: the outer loop controls Euler angles \( \phi, \theta, \psi \), and the inner loop controls angular rates \( p, q, r \). For the outer loop, define the angle errors \( e_\phi = \phi – \phi_r \), \( e_\theta = \theta – \theta_r \), and \( e_\psi = \psi – \psi_r \). The control law ensures exponential convergence:
$$ \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 \( k_1, k_2, k_3 > 0 \). For the inner loop, the angular rate errors are \( e_p = p – p_r \), \( e_q = q – q_r \), and \( e_r = r – r_r \), with control:
$$ \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} $$
and \( k_4, k_5, k_6 > 0 \). The control gains are tuned empirically in simulation, as listed in Table 2, to achieve stable performance. This cascaded control structure enables the quadrotor to track desired trajectories while maintaining stability.
| Control Loop | Gain Type | Symbol | Value |
|---|---|---|---|
| Position Control | Proportional | \( K_{pu} \) | 1.2 |
| Derivative | \( K_{du} \) | 0.8 | |
| Proportional | \( K_{pz} \) | 2.0 | |
| Attitude Outer Loop | Gain | \( k_1 \) | 5.0 |
| Gain | \( k_2 \) | 5.0 | |
| Gain | \( k_3 \) | 3.0 | |
| Attitude Inner Loop | Gain | \( k_4 \) | 10.0 |
| Gain | \( k_5 \) | 10.0 | |
| Gain | \( k_6 \) | 8.0 |
Simulation experiments are conducted to validate the quadrotor control system, focusing on hovering, yaw maneuvers, and trajectory planning. The SITL setup involves running PX4 alongside Gazebo, with MAVLink enabling data exchange. In Gazebo, the quadrotor model is configured with sensor noise, such as GPS noise activated via SDF parameters. QGC is used to set waypoints and monitor flight data. For hovering tests, the quadrotor is commanded to maintain a fixed position, and the altitude data from Gazebo and QGC are compared. The results show minimal deviation, with position errors less than 0.1 m, demonstrating effective position control. The thrust input during hovering can be derived from the dynamics:
$$ U_1 = \frac{m g}{c_4 \cos \phi \cos \theta} $$
which maintains equilibrium against gravity.
For yaw and roll-pitch maneuvers, the quadrotor is tasked with following a predefined path with multiple waypoints. In QGC, a mission is planned with take-off, waypoints (e.g., points 2, 3, 4, 5), and landing. The quadrotor’s response in Gazebo shows rapid attitude adjustments, with Euler angles converging to desired values within seconds. The angular rate responses adhere to the inner loop control law, with errors decaying exponentially. Trajectory planning experiments involve complex paths, such as square or circular patterns, to test the position controller. The quadrotor successfully tracks these trajectories, with data from Gazebo aligning closely with QGC references. The trajectory error is quantified using the root mean square error (RMSE), calculated as:
$$ \text{RMSE} = \sqrt{\frac{1}{N} \sum_{i=1}^{N} ((\Delta x_i)^2 + (\Delta y_i)^2 + (\Delta z_i)^2)} $$
where \( \Delta x_i, \Delta y_i, \Delta z_i \) are position errors at each time step, and \( N \) is the number of samples. In our simulations, RMSE values are below 0.15 m, indicating high tracking accuracy. Table 3 summarizes the performance metrics for different flight tests, highlighting the system’s robustness.
| Test Scenario | Max Position Error (m) | RMSE (m) | Settling Time (s) |
|---|---|---|---|
| Hovering | 0.08 | 0.05 | 2.0 |
| Yaw Maneuver | 0.12 | 0.07 | 1.5 |
| Trajectory Tracking | 0.15 | 0.10 | 3.0 |
The simulation framework also allows for testing under disturbances, such as wind gusts modeled as white noise. The control system compensates effectively, with attitude deviations remaining within 5 degrees. This validates the cascaded PID design for real-world applications. Overall, the experiments confirm that the quadrotor control system achieves precise control and rapid response, enabling autonomous operations in dynamic environments.
In conclusion, this research demonstrates a successful implementation of a quadrotor control system using SITL simulation with ROS, Gazebo, PX4, and QGC. The mathematical models provide a foundation for control design, while the cascaded PID controller ensures stable attitude and position tracking. Simulation results show minimal errors and fast responses, verifying the system’s feasibility for hardware deployment. Future work could explore advanced control techniques, such as model predictive control, to enhance performance in noisy environments. This study underscores the potential of simulation-based development for complex quadrotor systems, reducing costs and risks in real-world testing.
