Feedback control
UAT 314 Automation, Robotics and Intelligent Control Systems
Lesson
By the end of this module you will be able to
- Build a first-order or double-integrator model and write its differential equation and transfer function
- Compare open-loop and closed-loop control
- Explain the role of the P, I and D terms and their effect on the response
- Calculate the steady-state error of proportional control
- Tune a PID controller initially with the Ziegler–Nichols method and state its limits
- Explain PX4's cascaded multicopter control and the tuning order
- Write a state-space model, check controllability and place poles with state feedback
Why this matters
A multirotor is not inherently stable. Without a controller adjusting motor speeds hundreds of times per second, it would flip over in a fraction of a second. The controller behind almost every system, from drones and robots to air conditioners, is feedback control, and the most widely used form is PID.
Feedback control is like keeping a car in the middle of its lane. You see how far the car has drifted (the error) and turn the wheel to correct it; the bigger the drift, the more you turn. If a crosswind keeps pushing, you gradually hold the wheel over. If you see the car drifting fast, you correct in advance. These three behaviours are P, I and D.
Open loop versus closed loop
- Open loop acts on a plan without measuring the result, such as running motors at fixed power from a table. If wind or load changes, the result drifts and nothing corrects it
- Closed loop measures the real output with a sensor, compares it with the setpoint, and adjusts the command using the error
Modelling a system: differential equations and transfer functions
Before designing a controller we need a mathematical model of the plant: an equation that says how the output responds to the input over time. Åström and Murray (2021, Chapter 3) and Nise (2019, Chapters 2–3) build models the same way: write the physical laws for each part (Newton’s laws, Kirchhoff’s laws, energy balance), keep the effects that matter at the speeds of interest, and check the model against measurements.
Two models cover most drone control loops:
- A first-order system stores energy in one place. A motor with its propeller speeds up quickly at first and then levels off. With time constant (seconds) and steady-state gain it obeys the differential equation . After a step of size the output is : it reaches 63.2% of its final value at and about 95% at . Quan (2017) models a multicopter motor and propeller this way
- A double integrator is what Newton’s law gives for position. Vertical motion of a drone follows . If we treat the net acceleration as the input, then : acceleration is integrated once to give speed and again to give height
The transfer function is a compact way to write a linear model. Taking the Laplace transform with zero initial conditions turns into multiplication by , so the differential equation becomes algebra. The first-order system gives , and
Transfer functions multiply along a chain of blocks, which is why block diagrams such as Figure 1 are drawn with them. The poles (roots of the denominator) set the speed and shape of the response: the pole at decays faster when is small, while the two poles at of the double integrator mean the height drifts away unless a controller acts.
Example 1 A motor model from a step test
On a thrust stand, the motor command is stepped from 0 to 0.5 (half of full scale). The speed settles at 12,000 rpm and passes 7,585 rpm (63.2% of 12,000) at s. The values are assumed for practice.
- Steady-state gain rpm per unit of command
- Time constant s, the time to reach 63.2%
- Model: , so
- Prediction at s: rpm
- It reaches 95% (about 11,400 rpm) after s
Checking the prediction against a second measured point, such as the speed at 0.1 s, is how we decide whether a first-order model is good enough. If the motor shows an obvious delay or overshoot, a higher-order model is needed.
The PID controller
| Term | Responds to | Effect of increasing it | Caution |
|---|---|---|---|
| P (proportional) | The present error | Faster response | Too much causes oscillation; alone it usually leaves a residual error |
| I (integral) | Accumulated past error | Removes residual error | Too much causes oscillation and overshoot; needs anti-windup |
| D (derivative) | Rate of change of error | Damps oscillation | Amplifies noise; needs filtering |
Integrator windup happens when the actuator is saturated, for example motors at full power, while the I term keeps accumulating. When the error reverses, the controller responds very slowly, so the I term must be limited (anti-windup). PX4 does this by clamping in its velocity loop.
Example 2 Why P alone does not reach the target
A first-order plant has steady-state gain and a P controller with . For a step setpoint:
The system settles about 14.3% short of the target. Raising shrinks the error but never removes it, and a real system with delay starts to oscillate. Adding an I term removes the residual error.
Ziegler–Nichols tuning
Ziegler and Nichols (1942) proposed finding initial PID values by experiment. In one method, raise gradually (with I and D off) until the system oscillates steadily; record that gain as and the oscillation period as , then use the table (Åström & Murray, Table 11.1):
| Controller | |||
|---|---|---|---|
| P | – | – | |
| PI | – | ||
| PID |
Example 3 Calculating PID gains from an experiment
On a motor test rig, the system oscillates steadily at with period s.
- s, so
- s, so
Åström and Murray warn that the Ziegler–Nichols rules use too little process information and often give closed loops that lack robustness. These values are only a starting point, and never drive a real drone to sustained oscillation; do it only on a test rig or in simulation.
Cascaded control in multirotors
PX4 uses a cascaded control architecture, a mix of P and PID controllers in layers.
| Loop | Type | Output | Example PX4 parameters |
|---|---|---|---|
| Position | P | Velocity setpoint | MPC_XY_P, MPC_Z_P |
| Velocity | PID | Acceleration setpoint | MPC_XY_VEL_P_ACC, MPC_XY_VEL_I_ACC, MPC_XY_VEL_D_ACC |
| Attitude | P on quaternion | Rate setpoint | MC_ROLL_P, MC_PITCH_P, MC_YAW_P |
| Angular rate | PID | Torque to the mixer | MC_ROLLRATE_P/I/D, MC_PITCHRATE_P/I/D |
Inner loops run faster than outer loops. The rate loop takes filtered gyro data, and the gyro publication rate is set by IMU_GYRO_RATEMAX. The PX4 tuning guide stresses tuning the rate controller first, because it affects all flight modes; the attitude loop is then much easier. It suggests raising gains by 20–30% per iteration, then 5–10% for fine tuning, testing with fast step inputs in hover.
State-space models and state feedback
A transfer function describes only the path from one input to one output. Modern control, developed from around 1960, describes the whole internal state of the system instead: the smallest set of variables that, together with the future inputs, fixes the future behaviour. For vertical flight the state is height and vertical speed, . The model is written as first-order matrix equations (Åström & Murray, 2021, Chapters 3 and 7; Nise, 2019, Chapter 3):
For the double integrator, , and . The two views are linked by , which gives back . State space has three practical advantages: it handles several inputs and outputs at once (a drone has four inputs and six degrees of freedom), it works directly in the time domain where a computer simulates it step by step, and it is the language of the Kalman filter and MPC in module 4, which use exactly this model.
Controllability asks whether the input can drive the state anywhere. For two states it holds when the matrix has rank 2 (Åström and Murray call this reachability). If it holds, state feedback can place the closed-loop eigenvalues (the poles of ) wherever we choose, so we design by picking the response we want. For a second-order response we pick a damping ratio and a natural frequency , and match the characteristic polynomial .
Example 4 Altitude hold by pole placement
A 1.5 kg drone (assumed) uses the double-integrator model, with the acceleration command as input. With the closed loop is , whose characteristic polynomial is .
- Controllability: has determinant , so the input can move both states
- Choose and rad/s, then match coefficients: and
- For zero steady-state error on a height step, and must give , so
- Expected response: eigenvalues , overshoot , settling within 2% in roughly s
- At the moment a 1 m step is commanded, m/s², so the thrust command is N, compared with 14.7 N to hover. Check that the motors can deliver it, or the actuator saturates
import numpy as np
A = np.array([[0.0, 1.0], [0.0, 0.0]]) # state x = [altitude z, vertical speed w]
B = np.array([[0.0], [1.0]]) # input u = acceleration command (m/s²)
Wc = np.hstack([B, A @ B]) # controllability matrix [B, AB]
print("rank of [B, AB]:", np.linalg.matrix_rank(Wc))
K = np.array([[4.0, 2.8]]) # k1, k2 from zeta = 0.7, omega0 = 2 rad/s
print("closed-loop eigenvalues:", np.round(np.linalg.eigvals(A - B @ K), 3))
dt, r, x, z_log = 0.001, 1.0, np.zeros((2, 1)), []
for _ in range(int(6 / dt)):
u = (-K @ x + K[0, 0] * r).item() # u = -Kx + kf r with kf = k1
x = x + dt * (A @ x + B * u)
z_log.append(x[0, 0])
z_log = np.array(z_log)
settle = dt * (np.nonzero(np.abs(z_log - r) > 0.02 * r)[0][-1] + 1)
print(f"peak {z_log.max():.3f} m (overshoot {100 * (z_log.max() - r):.1f}%), within 2% after {settle:.2f} s")
rank of [B, AB]: 2
closed-loop eigenvalues: [-1.4+1.428j -1.4-1.428j]
peak 1.046 m (overshoot 4.6%), within 2% after 2.99 s
The simulation agrees with the hand calculation: 4.6% overshoot, and settling in about 3 s (the rule of thumb is only approximate). State feedback here needs both height and vertical speed; in practice the speed comes from a state estimator such as the Kalman filter in module 4. Choosing the gains by minimising a cost instead of placing poles by hand leads to the linear quadratic regulator (LQR), and adding constraints and prediction leads to MPC.
Class activity
Activity: Simulating an altitude controller
- Write a Python simulation of a discrete first-order plant with P, PI and PID controllers.
- Compare rise time, overshoot and residual error for each.
- Add an actuator limit and observe integrator windup, then add anti-windup.
- If available, read a PX4 SITL tuning log and identify which loop was tuned first.
Common mistakes
Watch out
- Tuning outer loops before inner loops, fixing the wrong problem
- Raising D without filtering, so motors vibrate and heat up
- No anti-windup when actuators saturate
- Treating Ziegler–Nichols values as final without checking robustness
- Driving a real drone to its stability limit during tests
- Trusting a model that was never checked against a second measurement
Summary
- A model is a differential equation; a first-order plant is and vertical flight is a double integrator
- A closed loop measures the output and corrects using the error
- P reacts to the present error, I removes residual error, D damps oscillation
- P control of a first-order plant leaves
- Ziegler–Nichols PID: , , , only a starting point
- PX4 cascades P → PID → P → PID; tune the rate loop first
- State space describes the whole state; if has full rank, state feedback can place the poles
Check your understanding
- Which PID term removes residual error?
- A first-order plant with uses P control with . What is the steady-state error?
- An experiment gives and s. Calculate PID , and by Ziegler–Nichols.
- A motor settles at 10,000 rpm after a command step of 0.5 and reaches 6,320 rpm at 0.05 s. Write its transfer function.
- Why tune the rate loop before the others?
Answers
- The I (integral) term
- , about 11%
- ; s so ; s so
- rpm per unit and s, so
- Every outer loop acts through the rate loop; if the inner loop is poor, the outer loops cannot be tuned well, and it affects all flight modes
Key formulas
| First-order system | |
| State-space model | |
| State feedback | |
| PID controller | |
| Steady-state error (first-order plant, P control) | |
| Ziegler–Nichols ultimate-gain PID | |
| Converting to gains |
Key references
- Åström, K. J., & Murray, R. M. (2021). Feedback systems: An introduction for scientists and engineers (2nd ed.). Princeton University Press. link
- Nise, N. S. (2019). Control systems engineering (8th ed.). Wiley. link
- Ziegler, J. G., & Nichols, N. B. (1942). Optimum settings for automatic controllers. Transactions of the ASME, 64(8), 759–765. link
- PX4 Autopilot. Controller diagrams; Multicopter PID tuning guide. PX4 user guide (main). link
- Beard, R. W., & McLain, T. W. (2012). Small unmanned aircraft: Theory and practice. Princeton University Press. link
- Quan, Q. (2017). Introduction to multicopter design and control. Springer Singapore. link
Further reading
Study the assigned knowledge units in advance, review media and take the module quiz
การควบคุมป้อนกลับและตัวควบคุม PID
การควบคุมแบบ cascade และการปรับจูน flight controller
In class / field
Lecture, case discussion and in-class problem solving
Learning evidence: Quiz results and submitted exercises