Abstract
Pixhawk is a widely adopted open-source flight control system. This research provides a theoretical analysis of the attitude control algorithms utilized by Pixhawk for multi-rotor aircraft, supplemented by simulations and flight experiments. Our findings demonstrate that the combination of a rotation vector-based attitude error algorithm and a cascade PID controller enables stable hovering and precise execution of complex maneuvers.
Introduction
In recent years, Unmanned Aerial Vehicles (UAVs), particularly small-scale multi-rotors, have seen a surge in popularity. As the core of these systems, flight controllers like Pixhawk have gained significant attention due to their reliable hardware and sophisticated software. However, the specific mathematical implementations of Pixhawk's control algorithms are often under-researched and treated as "black boxes" by the user community.
Conventional flight controllers typically calculate attitude error by subtracting current Euler angles (roll, pitch, yaw) from target values. This approach can be inefficient and prone to mathematical singularities during aggressive maneuvers. This paper aims to demystify Pixhawk's approach, focusing on its unique method for calculating attitude error and its robust control loop architecture.
Methodology
Hybrid Angle Error Calculation
Pixhawk avoids the limitations of simple Euler angle subtraction by employing a hybrid rotation vector approach. This method dynamically adjusts based on the magnitude of the deviation:
- Small Deviations: When the current and target attitudes are close, the algorithm first calculates the rotation required to align the $z$-axes. It then determines a separate "yaw error" to align the $x$ and $y$ axes. This decoupling prioritizes vertical alignment, which is critical for stability.
- Large Deviations: For significant errors, the system transitions to a quaternion-based representation. Quaternions provide a singularity-free way to represent any orientation in 3D space.
- Smoothing: A weighting factor ($direct\_w$) blends these two methods, ensuring a continuous and smooth error signal across all flight regimes.
Cascade PID Controller
The core of the control logic is a nested, or cascade, PID structure. This architecture separates the control of "slow" variables (attitude angles) from "fast" variables (angular rates).
- Outer Loop: This loop processes the calculated attitude angle error and generates a target angular rate.
- Inner Loop: This loop compares the target angular rate from the outer loop with real-time gyroscope data to produce the final motor commands. This high-frequency feedback loop is essential for rejecting disturbances and maintaining precise control.
Experimental Verification and Results
The proposed analysis was validated through both numerical simulations and physical flight tests using a quadrotor running Pixhawk firmware.
Simulation Performance
Step-response tests were conducted for both small (5°) and large (50°) target attitude changes. The results indicated rapid convergence with minimal oscillation, showcasing the efficiency of the rotation vector approach.
Flight Accuracy and Maneuverability
Outdoor flight experiments confirmed the simulation findings. Under normal operating conditions, the deviation between the target and actual attitude remained consistently below 3°. Furthermore, the system demonstrated robust tracking during large-angle movements, proving that the rotation vector method effectively finds the "shortest path" for attitude regulation.
Conclusion
This study confirms that Pixhawk's use of rotation vectors for error calculation, combined with a cascade PID controller, provides superior stability and maneuverability compared to traditional Euler-based methods. While the current weighting function effectively bridges different error regimes, future work could focus on optimizing these transitions and developing more automated methods for tuning the underlying PID gains.
Summary updated