How Does a Drone Hold Its Attitude with a Control Loop?
- Intermediate
- Article
- Ages 16+
- 7 min read

A drone holds attitude through nested feedback loops: sensors measure motion, an estimator infers state, and controllers compare that state with a target before continually adjusting motor commands. The outer angle loop turns attitude error into a desired rotation rate; the inner rate loop compares it with the gyro measurement and computes torque to reduce the error.
Contents
- Attitude measurement
- Controller calculating corrections
- Drone responding to actuation
What you will learn
- Trace information from sensors through to motor correction.
- Distinguish an angle-holding loop from an angular-rate loop.
- Understand why actuator limits and measurement noise prevent instant correction.
Before you start
You do not need to tune a PID controller. It is enough to know that error is the gap between a desired value and the currently estimated value.
What does the feedback loop measure?
An IMU is an inertial measurement unit; its gyroscope measures how fast the body rotates around its axes. An estimator combines sensor data to produce an estimated attitude, while the gyro supplies angular rate for the fast inner loop. Measurement and estimate are different: a gyro does not directly report absolute angle, and every signal can contain noise, delay or sensor bias.
PX4 describes a cascaded multicopter architecture in which estimated states feed the controllers. This is a digital system, so it samples, filters and updates continuously. Filtering reduces high-frequency noise but can add delay; if the controller reacts to an old attitude sample, its correction may arrive late.
How does the angle loop create a rate target?
When the pilot requests a body angle, the attitude loop compares the target with estimated attitude. A large error requests a faster rotation toward the target; as the error shrinks, the requested rate falls. In PX4's architecture, the attitude controller produces an angular-rate setpoint for the inner loop. It is the outer loop because it cares about body orientation rather than directly setting motor signals.
For example, if a disturbance tilts the drone left while the target is level, attitude error requests rotation back in the other direction. As the drone approaches level, the outer loop reduces the rate request. With an angle loop alone, motor response can lag before the body changes orientation; the inner rate loop helps track the changing request more quickly.
How does the rate loop turn error into torque?
The angular-rate loop compares desired rotation rate with the gyro measurement. The error enters a PID controller: the proportional term responds to current error, the integral term accumulates persistent error, and the derivative term responds to the trend in change. Together they contribute to a torque command; in PX4, the control output then passes through control allocation to become actuator commands for motors or servos.
Trace one small disturbance through the chain: wind rotates the body; the gyro senses the rate; the rate loop sees a difference from its setpoint; torque output makes the allocator change rotor forces; the body rotates back; the next measurement shows less error. That is feedback: the physical output returns as measured input, closing the loop rather than issuing a one-way command.
PID is a control structure, not a promise that the drone will stay still. Gains that are too strong can drive overshoot or oscillation; gains that are too weak can recover slowly. The integral term can keep accumulating while motors are already saturated and error remains, a condition called windup; real systems therefore limit the integral and the output. Noise, vibration and delay also make measurements imperfect.
How do the loops work together to hold attitude?
In the PX4 diagram, the angle loop produces a rate setpoint, the rate loop produces torque and thrust outputs, and the allocator distributes those outputs to actuators. A requested command can exceed the capacity of a motor or the whole frame. The allocator may then saturate or prioritize axes according to its configuration; the remaining error cannot be fixed by a PID loop that keeps increasing its output without bound.
Attitude is also different from position. Stabilized mode follows stick-based attitude commands but does not itself hold altitude or coordinates. After the sticks are released, the body may return near level while the drone continues drifting. Position hold requires an outer layer using estimated position and velocity to create acceleration or attitude targets; that layer adds the information needed to counter drift.
Walk through a disturbance in simulation
Proposed illustrative design; not a run result. In a simulator, set a level attitude target and apply a brief disturbance that tilts the model. Record, on one timeline, target attitude, estimated attitude, gyro rate, rate setpoint, torque output and actuator command. A working feedback chain should show the measurement respond to the disturbance, an error appear, a corrective command follow, and then the error shrink. Comparing two runs with different gains could illustrate the trade-off between slow recovery and oscillation, but it would not establish safe settings for a real drone.
If the angle plot looks delayed, check time alignment and sensor delay before blaming PID. If actuator output reaches its limit, the controller may not have enough authority to track the target. If gyro data vibrates unusually, filtering, mounting and mechanical vibration are all worth examining in simulation or recorded data; this article does not give flight-tuning instructions.
Common misunderstandings
The gyro knows the drone's angle by itself. A gyro measures angular rate; attitude is an estimated state formed from sensor information. Stronger PID is always better. Higher gains make response more aggressive but can increase overshoot and oscillation; actuator limits and noise remain.
Frequently asked questions
Why use both attitude and rate loops?
The outer loop decides how quickly to rotate to correct angle; the inner loop tracks that rate using gyro measurements and torque output.
Does the controller stop when the target angle is reached?
No. It continues reading state and correcting for disturbances, error or a changing target.
Why can delay make a drone oscillate?
A command calculated from old state may arrive after the drone has moved further, causing an excessive or out-of-phase correction.
Does Stabilized mode hold position?
Not by itself. Holding body angle does not provide the position loop needed to counter wind and drift velocity.
Summary
The IMU and estimator provide feedback; the attitude loop turns angle error into a desired rate; the rate loop compares that target with gyro data and computes torque; allocation turns its output into actuator commands. Noise, delay, saturation and estimate quality determine how well the closed loop actually tracks its target.
Terms in this article
English and Vietnamese terms, with the meanings used here. Hover, tap or Tab to a term with a dotted underline for an explanation as you read.
- attitudetư thế
- The drone’s estimated orientation and tilt relative to a reference frame.
- rate controllerbộ điều khiển tốc độ góc
- The inner loop that uses desired and gyro-measured rotation rates to produce corrective output.
- IMU
- An inertial measurement unit providing motion measurements such as angular rate and acceleration.
- PID
- A controller combining proportional, integral and derivative responses to an error signal.
This article is not marked as viewed
Spotted something wrong or unsafe?
Tell the administrator by email. The message already has the article title and address.
You may also like
IntermediateHow Do Drone Failsafes and Return-to-Home Work?
Trace Hold, Return, home requirements and fallback branches when positioning data is unavailable.
Robotics6 min read
IntermediateHow Can a Human Pilot Always Override Voice and AI Commands?
Explore a proposed priority architecture, handover confirmation and the difference between cancelling AI, Return and motor stop.
Robotics6 min read
IntermediateHow Does a Drone Detect and Avoid Obstacles?
Explains the path from range observations to stopping or avoidance, stale-data handling and geofence limits.
Robotics7 min read
AdvancedHow Does Visual Servoing Guide a Drone?
Explains how image-feature error maps to drone velocity, closes the feedback loop and compares with world-coordinate control.
Robotics8 min read
Sources
These sources are written for older readers. If they feel hard, read them with an adult.
- Control Allocation(opens in a new tab)
PX4Tier C: other sourcesRead on October 30, 2026
- Flight Modes (Multicopter)(opens in a new tab)
PX4Tier C: other sourcesRead on October 30, 2026
- Controller Diagrams(opens in a new tab)
PX4Tier C: other sourcesRead on October 30, 2026
- Multicopter PID Tuning Guide(opens in a new tab)
PX4Tier C: other sourcesRead on October 30, 2026
