How IMUs and Kalman Filters Stabilize Multirotor Drones
Multirotor drones are inherently unstable aircraft that require constant, millisecond-level adjustments to stay in the air. This article provides an overview of how drone flight controllers achieve stable flight using a six-axis Inertial Measurement Unit (IMU) and Kalman filter sensor-fusion algorithms. By combining raw physical data from accelerometers and gyroscopes, the onboard electronics filters out mechanical noise and sensor drift to calculate the exact attitude of the drone, allowing the flight controller to adjust motor speeds in real time and keep the aircraft level.
The Role of the Six-Axis IMU
A six-axis Inertial Measurement Unit (IMU) is a micro-electromechanical system (MEMS) chip soldered directly onto the drone's flight controller circuit board. It consists of two distinct sensors: a three-axis gyroscope and a three-axis accelerometer. Together, they measure six degrees of freedom across the roll, pitch, and yaw axes.
- Three-Axis Gyroscope: This sensor measures angular velocity, or how fast the drone is rotating around its three axes, measured in degrees per second.
- Three-Axis Accelerometer: This sensor measures linear acceleration, including the constant pull of Earth's gravity, along the X, Y, and Z axes. By detecting which way gravity is pulling, it can theoretically determine which way is "down."
The Flaws of Raw Sensor Data
While both sensors inside the IMU could theoretically calculate the drone's attitude (orientation in space) on their own, both suffer from critical physical limitations when subjected to the flight environment of a multirotor.
The gyroscope is highly accurate over short bursts of time and responds instantly to movement. However, to find the drone's current angle, the flight controller must integrate the angular velocity over time. Small imperfections and temperature changes cause the gyroscope to suffer from "gyro drift." Over several seconds, these tiny errors accumulate, causing the flight controller to think the drone is level when it is actually tilted.
Conversely, the accelerometer does not drift over time because gravity is a constant reference vector. However, accelerometers are extremely sensitive to high-frequency mechanical vibrations caused by spinning propellers and brushless motors. In flight, raw accelerometer data is too noisy to use directly, as the vibrations mask the true direction of gravity.
How the Kalman Filter Fuses the Data
To solve the problems of gyro drift and accelerometer noise, the flight controller runs a sensor-fusion algorithm, most commonly a Kalman filter (or an Extended Kalman Filter for non-linear drone dynamics). The Kalman filter is a recursive mathematical algorithm that estimates the true state of the drone by blending the strengths of both sensors while canceling out their weaknesses.
The Kalman filter operates in a continuous two-step loop running hundreds or thousands of times per second:
- The Prediction Step: The algorithm takes the high-speed data from the gyroscope to predict the drone's new attitude based on its previous state. Because the gyroscope is immune to vibration over very short intervals, this prediction is initially very accurate.
- The Update (Correction) Step: The algorithm then looks at the accelerometer data. It applies a statistical weighting system—called the Kalman Gain—to determine how much to trust the accelerometer versus the gyroscope. It filters out the high-frequency vibration noise from the accelerometer and uses the remaining long-term gravity vector to correct the slow drift accumulating in the gyroscope's prediction.
By trusting the gyroscope in the short term and the accelerometer in the long term, the Kalman filter outputs a single, clean, and accurate quaternion or Euler angle representing the drone's true roll and pitch.
Closing the Loop: Flight Controller Stabilization
Once the Kalman filter calculates the true attitude of the multirotor, it feeds this data into the flight controller's PID (Proportional-Integral-Derivative) control loop.
The PID controller compares the drone's actual attitude (provided by the Kalman filter) with the desired attitude (commanded by the pilot's remote control sticks). If the pilot commands the drone to hover completely flat at 0 degrees, and a gust of wind pushes the drone to a 5-degree roll angle, the IMU detects the motion, the Kalman filter verifies the exact 5-degree tilt, and the PID controller calculates the error.
Within milliseconds, the flight controller sends updated digital signals to the Electronic Speed Controllers (ESCs). The ESCs instantly increase power to the motors on the tilted side and decrease power on the opposite side, pushing the multirotor back to a level attitude before the human eye can even perceive the dip.