Quadcopter drones are ubiquitous today, used for everything from photography to package delivery. However, beneath their seemingly effortless flight lies a complex engineering challenge: they are inherently unstable systems. This project delves into the fascinating world of quadcopter dynamics and control, exploring how we can accurately model their behavior, understand their instability, and design intelligent controllers to achieve precise and stable flight.
We started this project by addressing the fundamental question: "How can we accurately model a quadcopter's complex, nonlinear dynamics?" We meticulously defined the drone's physical properties and its governing equations of motion. Subsequently, we applied linearization techniques to simplify these complex equations for analytical purposes. We then examined the drone's behavior without any active control (open-loop) to highlight its natural instability and compared the full nonlinear model to its linear approximation. To demonstrate basic stabilization, we implemented a Proportional-Integral-Derivative (PID) controller. A key part of this project involved quantitatively comparing the controller's performance, specifically by taking commands generated by the closed-loop nonlinear model and applying them to the linear model to assess how the simplified representation responded. This provided initial insights into the differences between nonlinear and linear system behavior under control.
Our quadcopter model consists of a central body with four rotors arranged in an 'X' configuration. Each rotor generates an upward thrust force and a small torque that contributes to yaw.
Key physical parameters defining our drone include:
Mass (m): The total mass of the quadcopter.
Inertia Matrix (I): Describes how the drone resists changes in its rotational motion around its body axes (roll, pitch, yaw).
Arm Length (L): The distance from the center of the drone to each rotor.
Thrust Coefficient (kF): Relates a motor's RPM (revolutions per minute) to the thrust force it produces.
Moment Coefficient (kM): Relates a motor's RPM to the drag torque it produces around the rotor axis (contributing to yaw).
Gravity (g): The constant acceleration due to gravity.
Aerodynamic Drag Coefficients (Cd_u, Cd_v, Cd_w): Represent the resistance the drone experiences as it moves through the air along its body axes.
Air Density (rho) and Reference Area (A): Used in the drag calculations.
Each motor has a maximum RPM limit, which ensures realistic thrust commands and prevents mechanical over-stressing.
The drone's behavior is governed by a set of 12 nonlinear differential equation; the Equations of Motion (EOM). These equations describe how the drone's state changes over time. The drone's "state" is a vector containing 12 variables:
Position (x, y, z): The drone's location in the inertial (world) frame.
Linear Velocities (u, v, w): The drone's translational velocities along its own body axes.
Euler Angles (phi, theta, psi): The drone's orientation in space (roll, pitch, yaw).
Angular Velocities (p, q, r): The drone's rotational velocities around its own body axes.
How the forces and torques influence the drone:
Change in Position (dpos/dt): This is determined by the drone's linear velocity in its body frame, rotated into the world frame by its current orientation.
Change in Linear Velocity (duvw/dt): The linear acceleration in the body frame is influenced by:
Motor Thrusts: The sum of the upward forces from all four motors.
Gravity: The force of gravity acting downwards, rotated into the drone's current body frame.
Aerodynamic Drag: Resistance from the air, which depends on the drone's velocity relative to the air (including wind). The drag is proportional to the square of the relative velocity and varies with different drag coefficients along each body axis.
Coriolis Forces: These are apparent forces that arise due to the rotation of the body frame.
Change in Angular Velocity (domega/dt): The angular acceleration in the body frame is governed by:
Motor Torques: Differences in thrust between opposing motors create roll and pitch torques. The drag forces from spinning rotors create yaw torques.
Gyroscopic Effects: These arise from the conservation of angular momentum when the drone rotates.
Change in Euler Angles (deul/dt): How the drone's orientation changes is directly related to its body angular velocities through a kinematic transformation.
Wind Effect: Wind is incorporated by calculating the drone's velocity relative to the air mass. This relative velocity then determines the aerodynamic drag forces acting on the drone, which affect its translational motion. For instance, a headwind in the X-direction creates a drag force that needs to be overcome for the drone to maintain its position.
Before we can analyze the drone or design controllers, it's crucial to find a "trim" point. A trim point is an equilibrium state where the drone can remain perfectly still (hover in our case) without any acceleration, given specific constant motor inputs.
Our trim point for linearization is defined as a hover at 5 meters altitude with all other states (velocities, angles, angular velocities) being zero. To achieve this, we calculate the exact motor RPMs needed to counteract gravity.
Result: Dynamics at Trim Point (Max Absolute Value): 1.1842e-15
Explanation: This incredibly small number (very close to zero) confirms that the calculated trim state is indeed a numerically perfect equilibrium for our drone model. This is fundamental for accurate linearization.
The full equations of motion are nonlinear, making them challenging to analyze directly and to design certain types of controllers for. Linearization is a technique to approximate these complex nonlinear equations with simpler linear ones, but this approximation is only valid around a specific operating point (our trim point).
Why Linearize? Linear systems are mathematically much easier to analyze for properties like stability and controllability. Many powerful control design techniques are developed for linear systems.
How it's Done (Numerical Jacobian): We use a numerical method called the Jacobian to find the A and B matrices.
The A matrix (system matrix) describes how small changes in the drone's state affect the rate of change of other states.
The B matrix (input matrix) describes how small changes in the motor inputs affect the rate of change of the drone's states.
These matrices are found by slightly perturbing each state and each input around the trim point and observing how the drone's dynamics change.
Eigenvalues of A Matrix (Open-Loop Stability):
0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 (Real)
Interpretation: The real parts of these eigenvalues are all zero or very slightly negative. This means that, for very small deviations from our perfect hover trim point, the linearized open-loop system is either very slightly stable or critically stable. This is a common characteristic of quadcopters when considering only small perturbations.
To truly understand the drone's inherent instability, we perform open-loop simulations. This means we run the drone without any active controller to correct its flight.
Setup: We start both the nonlinear and linear models exactly at the hover trim point and apply a small, constant perturbation: we increase only motor 1's RPM by 10. This seemingly small input creates a significant imbalance in thrust and torque.
Purpose: To demonstrate how an uncontrolled drone reacts to a simple, unbalanced input, and how the linear model approximates this behavior.
The nonlinear model exhibits dramatic instability:
Steady-State Offset (from trim): -127.3319 m (The drone falls significantly from its initial trim altitude).
Approx. Percent Overshoot: 100.00 % (Indicates a large, unrecoverable deviation).
Settling Time: Response re-enters/leaves tolerance band. Not clearly settled within 10s. (The drone does not stabilize; it continues to diverge or tumble).
When the linear model is subjected to the same unbalanced step input:
Behavior: Due to the slightly unstable or marginally stable eigenvalues of the A matrix, the linear system's response to a constant, unbalanced input will also lead to an unbounded (diverging) response over time, or at best, an oscillation that does not return to a stable equilibrium.
Steady-State Offset: Unbounded / Not Applicable (The system diverges).
Approx. Percent Overshoot: Unbounded / Not Applicable.
Settling Time: Never settles within the simulation time.
While the linear model might initially follow the nonlinear model for a brief moment, it quickly diverges as the drone enters regions far from the linearization point due to the large, uncontrolled motion. However, the linear model's divergence will often appear "smoother" or more predictable than the complex tumbling of the nonlinear model because it lacks the higher-order nonlinear couplings.
Since the open-loop drone is unstable, we need a controller. We use a Proportional-Integral-Derivative (PID) controller, which is a widely used and effective control strategy.
Problem Statement: The drone starts at an initial displaced position (x=2m, y=1m, z=0m) and needs to hover stably at a desired position (x=0m, y=0m, z=5m). We also introduce a constant headwind of 2 m/s in the X-direction to test robustness.
PID Controller Overview: Our PID controller uses a cascaded structure:
Outer Loop (Position Control): Takes the error between the desired position and the current position to calculate desired linear accelerations (ax_cmd, ay_cmd, az_cmd). These accelerations are then converted into desired roll (phi_des) and pitch (theta_des) angles, and total collective thrust.
Inner Loop (Attitude Control): Takes the error between these desired angles (and desired yaw psi_des) and the drone's current measured angles/angular velocities. It then calculates the necessary roll, pitch, and yaw torques (tau_phi_cmd, tau_theta_cmd, tau_psi_cmd).
Motor Mixing: Finally, these commanded torques and the total thrust are translated into individual RPM commands for each of the four motors.
Limiting Angles: Crucially, we limit the commanded desired roll and pitch angles (max_des_angle = 0.2 radians or ~11.5 degrees) to prevent the controller from commanding unrealistic or unsafe maneuvers.
Tuned PID Gains: We used previously optimized Kp, Ki, and Kd values for each axis (position: XY, Z; attitude: Roll, Pitch, Yaw) to ensure stable and responsive flight.
Simulation Strategy:
Nonlinear Closed-Loop: We run the full nonlinear drone model with the PID controller actively generating motor commands at each time step, reacting to the drone's current state.
Linear Closed-Loop (Approximation): To compare, we then run the linearized system by feeding it the exact same motor RPM commands that the nonlinear PID controller generated. This allows us to see how well the linear model approximates the complex behavior of the controlled nonlinear system.
Performance Metrics (Nonlinear Closed-Loop System)
The nonlinear model, under PID control, successfully reaches and maintains the desired hover:
Tracking RMSE (Root Mean Square Error):
Total Position: 1.244 m
x-axis: 1.025 m
y-axis: 0.182 m
z-axis: 0.681 m
XY-plane: 1.041 m
Max Deviation (from desired):
x-axis: 2.031 m (Matches initial offset)
y-axis: 1.000 m (Matches initial offset)
z-axis: 5.000 m (Matches initial offset for climb)
XY-plane: 2.248 m
Range (Max - Min position during simulation):
X: 1.546 m
Y: 1.303 m
Z: 5.365 m
Settling Time: The system successfully settles to the desired position within the simulation timeframe.
Overshoot: For tracking problems starting from an initial error, "Max Deviation" from the desired value effectively captures the maximum excursion. The drone achieves its target without significant overshoot in the traditional sense, as it moves from its initial position towards the setpoint.
Performance Metrics (Linear Closed-Loop System - Approximation)
The linear model, despite receiving the same control commands, exhibits a severe breakdown in prediction due to operating far outside its region of validity:
Tracking RMSE (Root Mean Square Error):
Total Position: 26690.244 m
x-axis: 26474.028 m
y-axis: 3353.760 m
z-axis: 497.238 m
XY-plane: 26685.612 m
Max Deviation (from desired):
x-axis: 70266.458 m
y-axis: 8880.585 m
z-axis: 863.706 m
XY-plane: 70825.418 m
Range (Max - Min position during simulation):
X: 70264.485 m
Y: 8881.585 m
Z: 858.713 m
Settling Time: Does not settle. The large RMSE and max deviations indicate that the linear model predicts an unbounded divergence.
Overshoot: Not applicable, as the system does not settle and diverges significantly.
Closed-Loop Plot Comparison
The nonlinear model gracefully converges to the desired position and maintain a stable hover. In contrast, the linear model, after an initial transient, will rapidly diverge due to its inability to capture the full range of nonlinear dynamics when the drone is actively maneuvering far from its trim hover and experiencing large changes in its state.
This project has provided a comprehensive look into quadcopter dynamics and control:
We successfully established a precise nonlinear model of the drone, incorporating essential physical properties and environmental effects like wind.
We accurately performed linearization around a hover trim point, providing a simplified model for analysis.
The open-loop simulations unequivocally demonstrated the inherent instability of the drone for both the nonlinear and linear models when subjected to an unbalanced input, highlighting the absolute necessity of active control.
The PID controller proved its immense value by effectively stabilizing the nonlinear drone, enabling it to perform complex maneuvers like climbing from an offset starting position to a precise hover, even in the presence of external wind, with excellent tracking performance.
Finally, the stark contrast between the nonlinear and linear closed-loop performance metrics underscored a fundamental principle: linear models are powerful tools for analysis around an operating point, but the full nonlinear dynamics are crucial for high-fidelity simulations of large-scale maneuvers and robust controller validation. The linear model accurately represented small deviations but failed to predict the behavior during significant maneuvers, even when given the correct control inputs.