November 26, 2026

How a Quadcopter Hovers: IMU Sensor Fusion, PID Loops and Drift

A small quadcopter hovering over a garage floor with a ribbon hanging from its landing gear showing slight drift.

A gyroscope chip that drones are built around, Bosch’s BMI088, lists a zero-rate offset of ±1 degree per second in its datasheet. That sounds like nothing. Left uncorrected, it means a flight controller that trusted the gyro alone would believe, one minute after takeoff, that the aircraft had rolled sixty degrees while it sat perfectly level over the lawn. A quadcopter that holds still in the air is not resting on anything. It is a machine arguing with its own sensors several hundred times a second and winning by a margin of a few tenths of a degree.

Video: Pratik Phadte on YouTube

The numbers in this post come from the BMI088 datasheet, open-source flight stack documentation (PX4 and ArduPilot), and a short Python simulation run on a test container. Nothing was flown. The simulation is there to put figures on the physics, and its assumptions are spelled out where they are used.

Four motors and no free lunch

Every move a quadcopter makes is a change in motor speed

A quadcopter has no ailerons, no rudder, no swashplate. It has four fixed-pitch propellers, and the only thing the flight controller can change is how fast each one turns. ArduPilot’s introduction to multicopters describes roll as “speeding up two motors on one side and slowing down the other two,” with pitch done the same way front to back.

Yaw is the clever one. Each motor spins “in the opposite direction from the two motors on either side of it,” per the same page, and Parallax’s multirotor physics course explains that this arrangement exists “to balance out the angular momentum.” Speed up the clockwise pair and slow the counter-clockwise pair, and the frame twists the other way. Total thrust stays roughly the same, so the aircraft turns without climbing or sinking.

The software step that turns “roll right a little, hold altitude, don’t yaw” into four separate motor commands is called mixing, or in PX4’s vocabulary, control allocation. PX4’s control allocation page says the flight stack “takes desired torque and thrust commands from the core controllers and translates them to actuator commands,” and that “the translation depends on the physical geometry of the airframe.” An X-frame and a plus-frame need different math to do the same maneuver. Wire one motor to the wrong output and the mixer pours correction into the wrong pipe, which is how a new build flips on the first throttle-up.

Close-up of a drone flight controller board with its small IMU sensor chip and rubber vibration dampers.

What the IMU actually measures

A gyroscope that drifts and an accelerometer that shakes

The inertial measurement unit is two sensors in one package. The gyroscope measures rotation rate. The accelerometer measures specific force, which at rest is gravity pointing down and in flight is gravity mixed with every bump, vibration and change of speed. ArduPilot’s page notes these are “small on-board MEMs gyroscopes and accelerometers (the same as those found in smart phones).” The BMI088 datasheet says the part targets “harsh vibration environments such as those encountered in drones and robotics applications.”

Neither sensor gives the answer the controller needs, which is the aircraft’s tilt. The gyro has to be integrated, rate times time, to become an angle, and Sebastian Madgwick’s 2010 orientation filter report puts the consequence plainly: “The integration of gyroscope measurement errors will lead to an accumulating error in the calculated orientation.” The accelerometer, by contrast, points toward gravity with no accumulating error at all, but the same report warns such sensors are “likely to be subject to high levels of noise,” because motion corrupts the measured direction of gravity.

The BMI088’s own specs show how far apart the two failure modes are:

Sensor Spec (datasheet, 25 °C) What it does if trusted alone
Gyroscope zero-rate offset ±1 °/s Tilt error grows without limit: 10° after 10 s, 60° after 60 s
Gyroscope output noise 0.1 °/s rms at 47 Hz bandwidth Small, but it integrates too
Accelerometer zero-g offset 20 mg Constant tilt or position error (see below)
Accelerometer noise density 160–190 µg/√Hz Jittery tilt reading, worse with prop vibration

One sensor is a slow leak and the other is a rattling gauge. Sensor fusion is the plumbing that takes the long-term truth from one and the short-term truth from the other.

Sensor fusion, tested in a simulation

Trust the gyro for a tenth of a second, the accelerometer for the long run

The simplest fusion scheme is the complementary filter. Each update, it advances the angle estimate with the gyro, then nudges it a small fraction of the way toward the accelerometer’s angle. The fraction, usually written alpha, sets a time constant: how long the filter believes the gyro before gravity pulls it back.

A Python simulation on a test container fed a filter running at an assumed 500 Hz with a gyro carrying the BMI088’s full 1 °/s offset plus 0.1 °/s noise, and an accelerometer tilt reading with 2° of random vibration noise (an assumption, chosen to be rough). The aircraft’s true tilt was zero the whole time. Averaged over five random seeds and the last 30 seconds of a 60-second run:

alpha=0.98:  theory bias err=0.098 deg | sim mean=0.090 deg, noise std=0.195 deg
alpha=0.995: theory bias err=0.398 deg | sim mean=0.389 deg, noise std=0.096 deg
alpha=0.999: theory bias err=1.998 deg | sim mean=1.989 deg, noise std=0.040 deg
gyro only, after 60 s:  59.9 deg

Lean on the gyro harder and the estimate gets smoother but sits further off, because the uncorrected offset has longer to push it before gravity corrects. Lean on the accelerometer and the bias shrinks, but the vibration noise comes through. There is no setting that removes both. That tradeoff is the whole reason more serious filters exist.

Madgwick’s filter, from the same 2010 report, needs “109 (IMU) or 277 (MARG) scalar arithmetic operations each filter update” and is “effective at low sampling rates; e.g. 10 Hz,” with reported accuracy of “< 0.6° static RMS error, < 0.8° dynamic RMS error.” PX4 goes further with an extended Kalman filter. Its EKF tuning guide states that “the EKF uses the IMU data for state prediction only,” and its state list includes “IMU gyro bias estimates” and “IMU accelerometer bias estimates.” The drifting offset becomes one more quantity the filter solves for and subtracts.

Four drone motors and propellers arranged in an X pattern on a workbench, with alternating propeller colors.

PID loops stacked like a boiler’s controls

The inner loop fights rotation, the outer loops fight everything else

With a tilt estimate in hand, the flight controller has to act on it. PX4 describes its multicopter design in its controller diagrams as “a standard cascaded control architecture,” loops nested inside loops. From the outside in: a position controller (a P controller) produces a velocity target; a velocity controller (PID) turns that into an acceleration target; that becomes a tilt and thrust target; an attitude controller (a quaternion P law) turns tilt error into a rotation-rate target; and an angular rate controller, a PID, finally drives the mixer. Each loop takes orders from the one outside it and gives orders to the one inside, like a thermostat telling a boiler controller what it wants, and the boiler controller working the gas valve.

The three letters do different jobs. P pushes in proportion to the error. D pushes against how fast the error is changing, which damps the wobble. I adds up error over time, and that is what keeps a drone from sagging.

The same Python container ran a one-dimensional altitude hold for a 1 kg craft with no hover-throttle feedforward, so the controller had to find the weight-cancelling thrust on its own:

Kp=20 Ki=0  Kd=8: altitude after 20 s = 0.510 m (target 1.000), predicted P-only sag=0.490 m
Kp=40 Ki=0  Kd=8: altitude after 20 s = 0.755 m (target 1.000), predicted P-only sag=0.245 m
Kp=20 Ki=10 Kd=8: altitude after 20 s = 1.000 m (target 1.000)

A proportional-only controller can only produce thrust when there is an error, so it settles at whatever error makes thrust equal weight: g divided by Kp. Doubling the gain halves the sag and never removes it. The integral term is what quietly winds up to carry the aircraft’s weight, which is why PX4’s rate controller limits “integral authority” to prevent windup. An integrator that keeps accumulating while the drone sits on the ground waiting to take off is a loaded spring.

Why a drone without GPS drifts

A tenth of a degree the sensors can’t see becomes a long walk sideways

Sideways motion on a quadcopter comes from tilting, and so does drift. To hold altitude at a tilt angle θ, total thrust has to rise so its vertical part still matches weight, and the horizontal part left over pushes the aircraft at g·tan θ. If the attitude estimate is off by a fraction of a degree, the controller holds what it thinks is level and the aircraft accelerates anyway:

tilt 0.1 deg: a=0.017 m/s^2, drift after 5s= 0.21 m, after 10s=  0.86 m
tilt 0.5 deg: a=0.086 m/s^2, drift after 5s= 1.07 m, after 10s=  4.28 m
tilt 1.0 deg: a=0.171 m/s^2, drift after 5s= 2.14 m, after 10s=  8.56 m
tilt 2.0 deg: a=0.342 m/s^2, drift after 5s= 4.28 m, after 10s= 17.12 m

Those figures assume the drift starts from a standstill and nothing else intervenes. A one-degree error, small enough to miss with a bubble level on a shaky bench, costs more than eight meters in ten seconds.

The IMU cannot catch this on its own. Measuring position from an accelerometer means integrating twice, and a 20 mg offset (the BMI088’s listed zero-g offset) double-integrated grows as half the offset times time squared:

t= 10s  position error =      9.8 m
t= 30s  position error =     88.3 m
t= 60s  position error =    353.0 m

Then there is the air itself. PX4’s Altitude mode documentation, describing “the safest non-GPS manual mode for new fliers,” says flatly: “If the wind blows the aircraft will drift in the direction of the wind.” An attitude-only controller holds an angle, and the wind is free to move the aircraft anywhere that angle allows.

GPS, or anything else that measures position or velocity against the ground, closes that outer loop. PX4’s optical flow page describes a downward camera plus distance sensor that “can be used to determine speed when navigating without GNSS.” Any honest outside reference will do. GPS just happens to be the one most aircraft carry.

A quadcopter hovering over a windy field, tilted slightly into the wind to hold its position.

Where people get burned

Calibration, vibration, air pressure and a compass near a power wire

The honest complication is that GPS does not end drift. ArduPilot’s Loiter mode page describes a GPS-locked copter that “circles (aka “toiletbowls”)” and says “this is normally caused by a compass problem,” usually magnetic interference from power cables under the autopilot. Position is right; heading is wrong; the corrections go in a slightly wrong direction, overshoot, and spiral. A good reference fed through a bad compass draws circles in the sky.

A small fixed mounting error does what the tilt table predicts. PX4’s level horizon calibration exists to “compensate for small misalignments in controller orientation” and is recommended when there is “constant drift during flight in not position-controlled flight modes.” A flight controller screwed down a degree off is a level that was never level.

Vibration is the other one. PX4’s vibration isolation guide says that “in extreme cases vibration may lead to sensor clipping/failures, possibly resulting in estimation failures and fly-aways.” A bent prop shakes the accelerometer, the accelerometer feeds the tilt estimate, and the tilt estimate feeds the motors.

Altitude has a quieter failure. ArduPilot’s AltHold mode page explains that the autopilot “uses a barometer which measures air pressure as the primary means for determining altitude,” and that when air pressure changes, “the copter will follow the air pressure change rather than actual altitude.” The same sensor family logs weather on a windowsill in the BME280 pressure logger project. On a drone, a gust or the prop wash near the ground moves that reading too. For anyone debugging an IMU on the bench, the bus traffic between sensor and flight controller is readable with a cheap analyzer, as in the I2C and SPI logic analyzer guide, and the rules for flying the finished aircraft outdoors are in the drone license explainer.

The strongest case against the tidy picture in this post is that the PID loops are rarely the problem. Most real hover trouble lives upstream, in what the loops are being told: a mounting angle, a magnet near a wire, a prop that shakes. The loop structure is written down in PX4’s and ArduPilot’s documentation. The sensors still lie a little, every flight, and the drone only hovers as well as the filter can catch them.

On a calm day a well-tuned quad looks nailed to the air. Hang a ribbon from the landing gear and it never quite stops moving. How far does a hobby quad wander in thirty seconds of hands-off hover with GPS switched off?

Sources

  • Bosch Sensortec BMI088 datasheet, rev 1.3 (2018): https://cdn.sparkfun.com/assets/c/c/e/4/7/BMI088_Datasheet.pdf
  • ArduPilot, What is a MultiCopter and How Does it Work: https://ardupilot.org/copter/docs/what-is-a-multicopter-and-how-does-it-work.html
  • Parallax, Understanding the Physics of Multirotor Flight, rotation and angular momentum lesson: https://learn.parallax.com/courses/understanding-the-physics-of-multirotor-flight/lessons/using-rotation-and-angular-momentum-to-control-movement
  • PX4, Control Allocation (Mixing): https://docs.px4.io/main/en/concept/control_allocation.html
  • Madgwick, S. O. H., An efficient orientation filter for inertial and inertial/magnetic sensor arrays (2010): https://forums.parallax.com/discussion/download/110975/madgwick_internal_report.pdf
  • PX4, Tuning the ECL EKF: https://docs.px4.io/main/en/advanced_config/tuning_the_ecl_ekf.html
  • PX4, Controller Diagrams: https://docs.px4.io/main/en/flight_stack/controller_diagrams.html
  • PX4, Altitude Mode (Multicopter): https://docs.px4.io/main/en/flight_modes_mc/altitude.html
  • PX4, Optical Flow: https://docs.px4.io/main/en/sensor/optical_flow.html
  • ArduPilot, Loiter Mode: https://ardupilot.org/copter/docs/loiter-mode.html
  • PX4, Level Horizon Calibration: https://docs.px4.io/main/en/config/level_horizon_calibration.html
  • PX4, Vibration Isolation: https://docs.px4.io/main/en/assembly/vibration_isolation.html
  • ArduPilot, AltHold Mode: https://ardupilot.org/copter/docs/altholdmode.html

489 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *