การควบคุมป้อนกลับและตัวควบคุม PID

Stability, steady-state error and PID tuning

Last updated:

Overview: measure, then correct the error

Open-loop control follows a plan without checking the result, such as running a fan at full speed for ten minutes every time. Feedback or closed-loop control measures the actual output y, compares it with the desired value r to get the error e = r − y, and keeps adjusting the command based on e, like a driver watching the road and making small steering corrections.

Feedback makes a system tolerant of disturbances such as gusts, and of model uncertainty such as a changed payload. The most widely used feedback controller, in industry and in drones, is the PID. A flight controller runs several PIDs in nested loops to hold body rate, attitude, velocity and position.

The three PID terms

In parallel form, u(t) = Kp·e(t) + Ki·∫e dt + Kd·de/dt.

  • P (proportional) acts on the present error. A high Kp gives fast response; too high causes oscillation.
  • I (integral) accumulates error over time. As long as any error remains, the command keeps growing until the steady-state error is gone, for example from an offset centre of gravity or a steady wind.
  • D (derivative) acts on the rate of change of error, rather like a shock absorber. It reduces overshoot and ringing but amplifies high-frequency noise.

Another common form is the standard or ideal form, u = K(e + (1/Ti)∫e dt + Td·de/dt), with integral time Ti and derivative time Td. Convert with Kp = K, Ki = K/Ti and Kd = K·Td. Before borrowing gains from documentation or another aircraft, find out which form they are written in.

Stability and steady-state error

A closed loop is stable if, after a disturbance, it returns to the setpoint instead of oscillating with growing amplitude. Excessive gain and excessive delay are the main causes of instability. Engineers measure the distance from oscillation with phase margin and gain margin.

For a first-order plant G(s) = K/(τs + 1) under P-only control, the steady-state error to a step is ess = 1/(1 + KpK). Raising Kp shrinks it but never to zero, because a P controller needs some error to produce any output. The I term fixes this: its output keeps growing until the error is zero.

A PID that works on real hardware

The textbook formula is short, but a practical controller must handle three more things:

  1. Integral windup: when the command exceeds what the motors can deliver, the output saturates but the I term keeps accumulating. Once the target is reached, the stored integral drives the system far past it. Prevent this by stopping integration while saturated (clamping), by feeding the difference between commanded and saturated output back to reduce I (back-calculation), and by limiting the size of I.
  2. Derivative on measurement: if D acts on error, a step change in setpoint produces a momentary spike. Taking the derivative of the measurement instead avoids this, because the measurement does not jump with the command.
  3. Derivative filtering: replace Kds with Kds/(1 + sTf), where Tf = Td/N and N is typically 5 to 20.

On a computer the PID runs in cycles. Each interval Δt, the I term adds Ki·e·Δt and the D term uses the change in measurement divided by Δt. The interval must be regular; if cycle times vary while the code assumes a fixed Δt, the I and D terms are wrong.

Finding starting gains and tuning

  • Manual tuning: start with P, add D to damp oscillation, then add I to remove residual error. Test with small steps and change one gain at a time.
  • Ziegler–Nichols (1942): with P only, raise Kp until the loop oscillates steadily, record the ultimate gain Ku and period Tu, then set K = 0.6Ku, Ti = Tu/2, Td = Tu/8. The result is aggressive and oscillatory, so treat it only as a starting point, and never drive a real drone to sustained oscillation; do it in a model or SITL.
  • Automatic tuning: modern autopilots include autotune functions, which work well once the frame is stiff and vibration is low.

The PX4 guide always tunes the rate loop first, then the outer loops. Details are in the unit on cascade control.

Worked example: from a SITL oscillation to PID gains

Example: Ziegler–Nichols and the D filter

Assume a simulated pitch-rate loop under P-only control starts oscillating steadily at Ku = 0.25 with period Tu = 0.4 s. Values are assumed.

  1. Standard form: K = 0.6 × 0.25 = 0.15, Ti = 0.4/2 = 0.2 s, Td = 0.4/8 = 0.05 s.
  2. Parallel form: Kp = 0.15, Ki = 0.15/0.2 = 0.75, Kd = 0.15 × 0.05 = 0.0075.
  3. D filter with N = 10: Tf = 0.05/10 = 0.005 s, a cutoff of 1/(2π × 0.005) ≈ 31.8 Hz.
  4. Without the I term: for a plant gain K = 2, P-only steady-state error is 1/(1 + KpK). At Kp = 0.5, 2 and 5 this gives 50%, 20% and 9.1%. More gain helps but never removes the error, and raises the risk of oscillation.

These gains are a starting point. Reduce P slightly if overshoot is large, confirm in the log that actual follows desired, and watch motor temperature as D increases.

Common pitfalls

  • Entering standard-form gains into a parallel-form controller without converting them.
  • Raising Kp to chase steady-state error until the loop oscillates, instead of using I.
  • No anti-windup where the output can saturate.
  • Taking D from the error, so the motors twitch on every setpoint change.
  • Adding D without filtering until the motors overheat.
  • Running Ziegler–Nichols on a real drone until it oscillates at the limit.
  • Tuning outer loops before inner ones.

Continue in the lessons

Key references

  1. Åström, K. J., & Murray, R. M. (2021). Feedback systems: An introduction for scientists and engineers (2nd ed.). Princeton University Press. link
  2. Nise, N. S. (2019). Control systems engineering (8th ed.). Wiley. link
  3. Åström, K. J., & Hägglund, T. (2006). Advanced PID control. ISA–The Instrumentation, Systems, and Automation Society.
  4. Ziegler, J. G., & Nichols, N. B. (1942). Optimum settings for automatic controllers. Transactions of the ASME, 64(8), 759–765. link
  5. PX4 Autopilot. Multicopter PID tuning guide (manual/advanced). PX4 user guide (main). link

Used in courses

How to cite this page

Drone Institute, Rangsit University. (2026). การควบคุมป้อนกลับและตัวควบคุม PID. In UAS Technology Knowledge Hub (B.Tech.). https://rsu-uat.pk-research.work/en/kb/new/control-pid/