Design of an X-Type Quadrotor Drone Based on STM32 Microcontrollers

In recent years, the development of unmanned aerial vehicles (UAVs), particularly quadrotor drones, has garnered significant attention due to their versatility in military and civilian applications. As a researcher focused on mechatronic systems and optimization, I have been involved in designing an X-type quadrotor drone that addresses key challenges in flight attitude control, such as measurement interference, computational errors, and control output inaccuracies. This paper presents a comprehensive design based on STM32 series microcontrollers, incorporating a dual-processor and dual-sensor hardware architecture to enhance stability and precision. The quadrotor drone utilizes a quaternion-based complementary filter for attitude estimation and a cascade PID control algorithm for robust flight management. Through experimental validation, this design demonstrates improved performance in attitude measurement and control, paving the way for advanced flight control systems. The term “quadrotor drone” will be frequently referenced throughout this discussion to emphasize its centrality in UAV technology.

The quadrotor drone operates as an underactuated system with six degrees of freedom, involving linear and angular motions along three axes. Its flight principles rely on varying the speeds of four rotors to generate lift and torque, enabling maneuvers like vertical takeoff, hovering, and yaw rotation. The X-type configuration, where the nose points between two rotors, offers greater agility and stability compared to the plus-type, making it ideal for extensions like payload integration. However, achieving precise flight control requires accurate real-time attitude data, which is often compromised by external disturbances such as magnetic fields or turbulent winds. To mitigate this, our design employs a robust hardware and software framework, ensuring the quadrotor drone can maintain stable flight even under adverse conditions.

The core of our quadrotor drone lies in its flight control system, which integrates multiple modules for sensing, processing, and actuation. We selected STM32 microcontrollers for their high performance and versatility, coupled with dual gyroscopes and accelerometers to reduce measurement noise. This approach not only enhances the reliability of the quadrotor drone but also supports complex algorithms for attitude computation. In the following sections, I will detail the hardware components, software algorithms, and experimental results, using tables and formulas to summarize key aspects. The goal is to provide a thorough analysis that underscores the effectiveness of this design for quadrotor drone applications, with a focus on achieving attitude stability through innovative engineering solutions.

Hardware Architecture of the Quadrotor Drone

The hardware design of our X-type quadrotor drone is modular, encompassing a main controller, sensor arrays, drive systems, power management, and communication interfaces. This structure ensures scalability and fault tolerance, critical for the quadrotor drone’s operation in dynamic environments. At the heart of the system, we utilize dual STM32 processors: an STM32F427 as the main controller and an STM32F103 as a co-processor for safety backup. The STM32F427, based on the ARM Cortex-M4 core, operates at 168 MHz, enabling rapid data processing for real-time control of the quadrotor drone. It features multiple communication interfaces like I2C, SPI, and UART, facilitating seamless interaction with sensors and actuators. The co-processor monitors system health and takes over in case of main controller failure, enhancing the quadrotor drone’s robustness.

Sensor modules are pivotal for capturing the quadrotor drone’s attitude and position. We implement a dual-sensor strategy with two gyroscopes and two accelerometers to improve measurement accuracy. The primary sensor is the MPU6000, a six-axis unit combining a three-axis gyroscope and a three-axis accelerometer. The gyroscope offers selectable ranges up to ±2000°/s, while the accelerometer covers up to ±16g, suitable for tracking both slow and fast motions of the quadrotor drone. To complement this, we add the L3GD20 three-axis gyroscope and the LSM303D three-axis accelerometer/magnetometer. The LSM303D operates at 800 Hz, providing an alternative data source to avoid resonance issues that may affect the MPU6000 at 1 kHz. This dual setup reduces noise and error accumulation, as shown in Table 1, which compares sensor specifications.

Sensor Type Range Sampling Frequency Purpose in Quadrotor Drone
MPU6000 Gyroscope/Accelerometer ±2000°/s, ±16g 1 kHz Primary attitude measurement
L3GD20 Gyroscope ±250 to ±2000°/s Configurable Backup gyroscope for averaging
LSM303D Accelerometer/Magnetometer ±2 to ±16g, ±1.3 to ±8.1 Gauss 800 Hz Redundant acceleration and heading data
MS5611 Barometric Altimeter 10 cm resolution SPI interface Height measurement for quadrotor drone
NEO-7M GPS Module 2.5 m accuracy 10 Hz update Horizontal positioning

For position sensing, the quadrotor drone incorporates a MS5611 barometric altimeter for height detection with 10 cm resolution, and a NEO-7M GPS module for horizontal localization with 2.5 m accuracy. These sensors enable outdoor flight operations like altitude hold and waypoint navigation. The drive module consists of four brushless DC motors (Langyu X2216, 880 kV) paired with 30A electronic speed controllers (ESCs) that adjust motor speeds via PWM signals. We use 11-inch propellers with 47 mm pitch to generate lift, powered by a 5300 mAh, 30C lithium polymer battery providing 11.1V output. This battery ensures sufficient discharge capability for the quadrotor drone’s thrust requirements. Communication is handled by a 3DR wireless telemetry module for real-time data transmission to a ground station, and a WFT09 II nine-channel remote control with a PPM encoder for manual piloting. The entire hardware ecosystem is designed to support the quadrotor drone’s flight stability, with redundancy in critical components to mitigate single points of failure.

Software Framework for Quadrotor Drone Control

The software design of the quadrotor drone focuses on attitude estimation and control, implemented through algorithms that fuse sensor data and generate control outputs. Upon system initialization, the main controller reads sensor inputs, computes the current attitude using a quaternion-based complementary filter, and applies a cascade PID controller to adjust motor speeds. This process ensures the quadrotor drone maintains desired flight paths despite disturbances. The software architecture is outlined in a flowchart that emphasizes real-time processing, with interrupt-driven tasks for sensor polling and control updates. Key to this is the attitude estimation algorithm, which addresses the limitations of individual sensors: gyroscopes drift over time, accelerometers are noisy at high frequencies, and magnetometers are susceptible to magnetic interference. By combining these, we achieve accurate orientation data for the quadrotor drone.

Attitude estimation begins with defining coordinate systems: the Earth frame \( O_E-x_E y_E z_E \) as a fixed reference and the body frame \( O_B-x_B y_B z_B \) attached to the quadrotor drone. Initially aligned, these frames separate as the quadrotor drone moves. We use quaternions for representation due to their computational efficiency and avoidance of gimbal lock. A quaternion \( Q \) is expressed as:

$$ Q = q_0 + q_1 i + q_2 j + q_3 k = \cos \frac{\alpha}{2} + \mu \sin \frac{\alpha}{2} $$

where \( \mu \) is the unit vector of the rotation axis and \( \alpha \) is the rotation angle. The transformation matrix from the body frame to the Earth frame using quaternions is:

$$ C_E^B = \begin{bmatrix} q_0^2 + q_1^2 – q_2^2 – q_3^2 & 2(q_1 q_2 – q_0 q_3) & 2(q_1 q_3 + q_0 q_2) \\ 2(q_1 q_2 + q_0 q_3) & q_0^2 – q_1^2 + q_2^2 – q_3^2 & 2(q_2 q_3 – q_0 q_1) \\ 2(q_1 q_3 – q_0 q_2) & 2(q_2 q_3 + q_0 q_1) & q_0^2 – q_1^2 – q_2^2 + q_3^2 \end{bmatrix} $$

For practical interpretation, we convert quaternions to Euler angles—roll (\( \phi \)), pitch (\( \theta \)), and yaw (\( \psi \))—using the following equations derived from equating \( C_E^B \) with the rotation matrix \( R_E^B \):

$$ \phi = \arctan \left( \frac{2(q_2 q_3 + q_0 q_1)}{q_0^2 – q_1^2 – q_2^2 + q_3^2} \right) $$

$$ \theta = \arcsin \left( -2(q_1 q_3 – q_0 q_2) \right) $$

$$ \psi = \arctan \left( \frac{2(q_1 q_2 + q_0 q_3)}{q_0^2 + q_1^2 – q_2^2 – q_3^2} \right) $$

The complementary filter merges gyroscope, accelerometer, and magnetometer data by applying high-pass filtering to gyroscope outputs and low-pass filtering to accelerometer and magnetometer outputs. This fusion corrects gyroscope drift with low-frequency data from other sensors, yielding a stable attitude estimate for the quadrotor drone. The filter gain is tuned to balance response speed and noise rejection, crucial for the quadrotor drone’s dynamic maneuvers.

For attitude control, we employ a cascade PID strategy with outer angle loops and inner angular rate loops. This enhances the quadrotor drone’s disturbance rejection and adaptability. The outer PID takes the error between desired and estimated angles, outputting a desired angular rate. The inner PID then processes the error between this desired rate and the measured gyroscope rate, producing PWM signals for the ESCs. The control law for each axis can be expressed as:

$$ \text{Output}_{\text{outer}} = K_{p,\text{outer}} e_{\text{angle}} + K_{i,\text{outer}} \int e_{\text{angle}} \, dt + K_{d,\text{outer}} \frac{de_{\text{angle}}}{dt} $$

$$ \text{Output}_{\text{inner}} = K_{p,\text{inner}} e_{\text{rate}} + K_{i,\text{inner}} \int e_{\text{rate}} \, dt + K_{d,\text{inner}} \frac{de_{\text{rate}}}{dt} $$

where \( e_{\text{angle}} \) and \( e_{\text{rate}} \) are errors in angle and angular rate, respectively. The parameters are tuned experimentally to optimize the quadrotor drone’s response. Table 2 summarizes the PID gains used in our quadrotor drone for roll, pitch, and yaw control, derived from iterative testing to ensure stability.

Control Loop Parameter Roll Pitch Yaw
Outer Angle PID \( K_p \) 3.500 3.200 3.400
\( K_i \) 0.000 0.000 0.000
\( K_d \) 0.000 0.000 0.000
Inner Rate PID \( K_p \) 0.163 0.173 0.155
\( K_i \) 0.200 0.150 0.258
\( K_d \) 0.006 0.007 0.000

The software runs on FreeRTOS for task scheduling, ensuring timely execution of control loops at 500 Hz. This high update rate is essential for the quadrotor drone to react quickly to changes. Additionally, data logging via wireless telemetry allows for real-time monitoring and post-flight analysis, aiding in further refinement of the quadrotor drone’s performance.

Experimental Validation and Performance Analysis

To evaluate the quadrotor drone’s design, we conducted experiments focusing on sensor accuracy and control system tuning. The quadrotor drone was secured with safety tethers during initial tests to prevent damage. First, we compared single versus dual sensor measurements under small-angle perturbations. The X-axis angular velocity and acceleration were recorded using both configurations, with target values near zero due to minimal disturbance. Results indicated that the dual-sensor setup significantly reduced errors: for angular velocity, maximum error decreased from ±0.3°/s to ±0.1°/s; for acceleration, it dropped from ±3 m/s² to ±1 m/s². This confirms that dual gyroscopes and accelerometers enhance measurement precision for the quadrotor drone, mitigating noise and improving attitude estimation.

Next, we tuned the cascade PID parameters through iterative flight tests. The quadrotor drone’s response to step inputs in roll, pitch, and yaw was observed, adjusting gains to minimize overshoot and settling time. The final parameters, listed in Table 2, yielded stable hover and smooth transitions. We then performed free-flight tests in an open outdoor area with low wind, logging attitude angles for analysis. Figure 1 shows the comparison between desired and actual angles for the quadrotor drone during a maneuver sequence. The roll angle error remained within ±2°, pitch within ±1.5°, and yaw within ±1°, demonstrating effective control. These errors are acceptable for most quadrotor drone applications, such as aerial photography or surveillance.

The quadrotor drone’s power consumption was also measured, with an average draw of 15A during hover, giving a flight time of approximately 15 minutes with the 5300 mAh battery. This endurance is suitable for short-range missions. Additionally, we tested the wireless telemetry range, achieving stable data links up to 800 meters, which exceeds typical operational needs for this quadrotor drone. To quantify performance, we calculated the root mean square error (RMSE) for attitude angles over a 60-second flight:

$$ \text{RMSE} = \sqrt{\frac{1}{n} \sum_{i=1}^n (\theta_{\text{desired},i} – \theta_{\text{actual},i})^2 } $$

where \( n \) is the number of samples. For our quadrotor drone, the RMSE values were 0.8° for roll, 0.7° for pitch, and 0.5° for yaw, indicating high control accuracy. These results underscore the effectiveness of the dual-hardware and cascade PID approach in maintaining the quadrotor drone’s stability.

Further experiments involved introducing external disturbances, such as brief gusts of wind, to test the quadrotor drone’s robustness. The control system quickly compensated, with attitude deviations recovering within 0.5 seconds. This resilience is attributed to the inner rate PID loop, which dampens sudden changes. We also validated the fail-safe mechanism by simulating a main processor fault; the co-processor successfully maintained basic stability, allowing for a safe landing of the quadrotor drone. These tests collectively affirm that our design meets the objectives of reliable and precise flight control for quadrotor drones.

Mathematical Modeling and Simulation Insights

To deepen the analysis of the quadrotor drone’s dynamics, we developed a mathematical model based on Newton-Euler equations. The quadrotor drone is treated as a rigid body with mass \( m \) and inertia matrix \( I \). The forces include gravity \( mg \) and thrust \( T_i \) from each rotor, while moments arise from thrust differences and aerodynamic drag. The equations of motion in the body frame are:

$$ m \begin{bmatrix} \ddot{x} \\ \ddot{y} \\ \ddot{z} \end{bmatrix} = R_E^B \begin{bmatrix} 0 \\ 0 \\ \sum T_i \end{bmatrix} – \begin{bmatrix} 0 \\ 0 \\ mg \end{bmatrix} – K_d \begin{bmatrix} \dot{x} \\ \dot{y} \\ \dot{z} \end{bmatrix} $$

$$ I \begin{bmatrix} \dot{p} \\ \dot{q} \\ \dot{r} \end{bmatrix} = \begin{bmatrix} L(T_2 – T_4) \\ L(T_3 – T_1) \\ M_1 – M_2 + M_3 – M_4 \end{bmatrix} – \begin{bmatrix} p \\ q \\ r \end{bmatrix} \times I \begin{bmatrix} p \\ q \\ r \end{bmatrix} $$

where \( (x, y, z) \) are positions, \( (p, q, r) \) are angular rates, \( L \) is the arm length, \( K_d \) is drag coefficient, and \( M_i \) are rotor moments. This model was simulated in MATLAB/Simulink to predict the quadrotor drone’s behavior before real-world tests. The simulation incorporated sensor noise and wind gusts, allowing us to refine the complementary filter and PID gains. Results showed that the dual-sensor configuration reduced attitude error by 40% compared to a single-sensor setup, validating its utility for the quadrotor drone.

The quaternion update equation used in the filter is derived from the gyroscope data:

$$ \dot{Q} = \frac{1}{2} Q \otimes \begin{bmatrix} 0 \\ p \\ q \\ r \end{bmatrix} $$

where \( \otimes \) denotes quaternion multiplication. This is discretized for implementation on the STM32, with a Runge-Kutta method ensuring numerical stability. The complementary filter then corrects \( Q \) using accelerometer and magnetometer data via a gradient descent algorithm, minimizing the error between predicted and measured vectors. For the quadrotor drone, this process runs at 1 kHz, keeping computational latency below 1 ms.

We also analyzed the control system’s frequency response. The cascade PID introduces two poles and zeros that can be tuned for desired bandwidth. The transfer function from angle error to motor output for one axis approximates:

$$ G(s) = \frac{K_p s + K_i}{s^2 + K_d s + K_p} \cdot \frac{1}{s} $$

where the inner loop is simplified as a first-order system. Bode plots confirmed a phase margin above 45°, ensuring stability for the quadrotor drone across operational frequencies. These theoretical insights complement the empirical data, providing a holistic view of the quadrotor drone’s design.

Discussion on Quadrotor Drone Applications and Future Work

The X-type quadrotor drone presented here serves as a platform for various applications, from environmental monitoring to payload delivery. Its dual-processor architecture enhances reliability for critical tasks, while the precise attitude control enables smooth footage in aerial videography. The use of STM32 microcontrollers offers flexibility for integrating additional sensors, such as lidar or thermal cameras, expanding the quadrotor drone’s capabilities. Moreover, the open-source software framework allows researchers to experiment with advanced algorithms like model predictive control or neural networks, further optimizing the quadrotor drone’s performance.

Future work will focus on autonomous navigation for the quadrotor drone, leveraging GPS and computer vision for obstacle avoidance. We plan to implement simultaneous localization and mapping (SLAM) using the onboard sensors, enabling the quadrotor drone to operate in GPS-denied environments. Energy efficiency is another area for improvement; by optimizing propeller design and using regenerative braking, flight time could be extended. Additionally, swarm coordination of multiple quadrotor drones could be explored, utilizing the wireless telemetry for inter-drone communication. These advancements will build upon the stable foundation established in this design, pushing the boundaries of quadrotor drone technology.

In conclusion, the design of an X-type quadrotor drone based on STM32 microcontrollers demonstrates significant improvements in attitude measurement and control. The dual-hardware approach reduces sensor errors, while the quaternion complementary filter and cascade PID algorithm ensure robust flight management. Experimental results validate the quadrotor drone’s stability, with attitude errors within acceptable limits. This work contributes to the broader field of UAVs, offering insights that can guide future developments in quadrotor drone systems. As the demand for versatile aerial platforms grows, such designs will play a crucial role in enabling safe and efficient operations for quadrotor drones across diverse sectors.

Scroll to Top