TExcelTAD
Home › Control Systems & Automation › State Observers and Output Feedback

State Observers and Output Feedback

The position servo of Pole Placement needs the angle, the speed and the current. The production version has only an encoder: no current shunt amplifier (it costs money and board space), and a speed obtained by differencing encoder counts, which at 10 kHz10\ \text{kHz} jumps in steps of 15.7 rad/s15.7\ \text{rad/s} because one count is 1.57 mrad1.57\ \text{mrad}. Feeding that into KK makes the motor buzz. The answer is to estimate the missing states with a model running in the controller, corrected continuously by the measurement: a state observer. It works when the plant is observable.

The idea: a model that is corrected by the error

Run a copy of the plant model in software, driven by the same input uu. Its output Cx^C\hat{x} should match the measured yy; when it does not, nudge the estimate in proportion to the difference:

x^˙=Ax^+Bu+L (y−Cx^)\dot{\hat{x}} = A\hat{x} + Bu + L\,(y - C\hat{x})

Subtract this from x˙=Ax+Bu\dot{x} = Ax + Bu and the estimation error x~=x−x^\tilde{x} = x - \hat{x} obeys

x~˙=(A−LC) x~\dot{\tilde{x}} = (A - LC)\,\tilde{x}

independent of uu and rr. Choose LL so that A−LCA - LC has fast, stable eigenvalues and the error dies away from any starting value. Without the correction (L=0L = 0) the error would follow AA itself: for a plant with an integrator (the motor angle) a wrong initial estimate would never decay.

Design by duality. The eigenvalues of A−LCA - LC equal those of AT−CTLTA^T - C^T L^T, which is a state-feedback problem for the pair (AT,CT)(A^T, C^T). So L = ct.place(A.T, C.T, observer_poles).T: the pole-placement tools design observers too.

Where to put the observer poles. A common rule is 2 to 5 times faster than the controller poles, so the estimate converges before the controller relies on it. Much faster makes LL large, and a large LL passes measurement noise straight into the estimate. The Kalman filter chooses LL from noise statistics instead of pole positions; ct.lqe computes its steady-state gain.

The separation principle

Feed the estimate back, u=−Kx^+Nru = -K\hat{x} + Nr. In the coordinates (x,x~)(x, \tilde{x}) the closed loop is

[x˙x~˙]=[A−BKBK0A−LC][xx~]+[BN0]r\begin{bmatrix} \dot{x} \\ \dot{\tilde{x}} \end{bmatrix} = \begin{bmatrix} A - BK & BK \\ 0 & A - LC \end{bmatrix} \begin{bmatrix} x \\ \tilde{x} \end{bmatrix} + \begin{bmatrix} BN \\ 0 \end{bmatrix} r

The matrix is block-triangular, so its eigenvalues are those of A−BKA - BK (the controller) together with those of A−LCA - LC (the observer). You can design KK and LL separately. Better still, the observer error is not excited by rr: with a correct initial estimate the step response is exactly the state-feedback response. The controller plus observer together form an ordinary dynamic compensator from yy to uu, of the same order as the plant.

Worked example: estimating speed and current from the encoder

Given: the motor position model (x=[ θ, ω, ia ]Tx = [\,\theta,\ \omega,\ i_a\,]^T, C=[ 1, 0, 0 ]C = [\,1,\ 0,\ 0\,]) and the state-feedback gain of the previous lesson (poles −105±j107-105 \pm j107, −2000-2000).

Find: LL for observer poles at −600-600, −700-700 and −2500 s−1-2500\ \text{s}^{-1}; the step response with the observer in the loop; the decay of an initial estimate error of 0.1 rad0.1\ \text{rad}.

Solve:

  • Observability: O=[1000100−0.510 000]\mathcal{O} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -0.5 & 10\,000 \end{bmatrix} has rank 3: the encoder alone reveals speed (its derivative) and current (through the torque).
  • The slowest observer pole, −600 s−1-600\ \text{s}^{-1}, is about 6 times faster than the controller's dominant pair, so any estimate error has decayed to e−6=0.25 %e^{-6} = 0.25\,\% after 10 ms10\ \text{ms}.
  • By separation, the closed-loop poles are the three controller poles plus the three observer poles, and the step response equals the state-feedback one (4.6 %4.6\,\% overshoot).

Check:

python · try it yourself
import numpy as np
import control as ct

Ra, La, k, J, b = 2.0, 1e-3, 0.02, 2e-6, 1e-6
A = np.array([[0, 1, 0], [0, -b / J, k / J], [0, -k / La, -Ra / La]])
B = np.array([[0], [0], [1 / La]])
C = np.array([[1, 0, 0]])
wd = 150 * np.sqrt(1 - 0.7**2)
K = ct.place(A, B, [complex(-105, wd), complex(-105, -wd), -2000.0])
N = -1.0 / (C @ np.linalg.solve(A - B @ K, B)).item()
L = ct.place(A.T, C.T, [-600.0, -700.0, -2500.0]).T
print("observable:", np.linalg.matrix_rank(ct.obsv(A, C)) == 3)
print("L =", ", ".join(f"{v:.4g}" for v in L.ravel()))

# Plant + observer, state z = [x, xhat]; u = -K xhat + N r
Acl = np.block([[A, -B @ K], [L @ C, A - B @ K - L @ C]])
Bcl = np.vstack([B * N, B * N])
print("closed-loop poles:", np.round(np.sort(np.linalg.eigvals(Acl).real), 1))
t = np.linspace(0, 0.1, 10001)
step = ct.step_info(ct.ss(Acl, Bcl, np.hstack([C, 0 * C]), 0), T=t)
print(f"step with observer: overshoot {step['Overshoot']:.1f} %, settling {1e3 * step['SettlingTime']:.1f} ms")

# Regulation from a wrong initial estimate: theta(0) = 0.1 rad, estimate 0
sys = ct.ss(Acl, Bcl, np.eye(6), 0)
z = ct.forced_response(sys, T=t, U=0 * t, X0=[0.1, 0, 0, 0, 0, 0]).outputs
for ms in (0, 2, 5, 10):
    i = ms * 100
    print(f"t = {ms:2d} ms: theta = {z[0, i]:7.4f} rad, estimate = {z[3, i]:7.4f} rad, "
          f"speed error = {z[1, i] - z[4, i]:8.2f} rad/s")
observable: True
L = 1799, -1.309e+05, 9.501e+04
closed-loop poles: [-2500. -2000.  -700.  -600.  -105.  -105.]
step with observer: overshoot 4.6 %, settling 40.4 ms
t =  0 ms: theta =  0.1000 rad, estimate =  0.0000 rad, speed error =     0.00 rad/s
t =  2 ms: theta =  0.0966 rad, estimate =  0.1004 rad, speed error =   -14.91 rad/s
t =  5 ms: theta =  0.0729 rad, estimate =  0.0778 rad, speed error =    -7.01 rad/s
t = 10 ms: theta =  0.0282 rad, estimate =  0.0287 rad, speed error =    -0.61 rad/s

The estimate catches the true angle within a few milliseconds, while the controller (slower) is only beginning to correct the position: the observer has done its job before it matters much.

Why not just differentiate the encoder?

At 10 kHz10\ \text{kHz} one encoder count (2π/4000=1.571 mrad2\pi/4000 = 1.571\ \text{mrad}) in one sample is 15.7 rad/s15.7\ \text{rad/s}, so a differenced speed jumps between levels 15.7 rad/s15.7\ \text{rad/s} apart. The observer integrates a model instead, and uses the encoder only through the slowly acting correction. The program runs the motor at 3 V3\ \text{V} (about 149 rad/s149\ \text{rad/s}), samples a quantised encoder, and compares the two speed estimates. The observer is discretised with a zero-order hold, as a microcontroller would run it (Sampled-Data Loops).

python · try it yourself
import numpy as np
import control as ct

Ra, La, k, J, b = 2.0, 1e-3, 0.02, 2e-6, 1e-6
A = np.array([[0, 1, 0], [0, -b / J, k / J], [0, -k / La, -Ra / La]])
B = np.array([[0], [0], [1 / La]])
C = np.array([[1, 0, 0]])
Ts, q = 1e-4, 2 * np.pi / 4000                    # 10 kHz, one encoder count in rad
L = ct.place(A.T, C.T, [-600.0, -700.0, -2500.0]).T
plant = ct.c2d(ct.ss(A, B, np.eye(3), 0), Ts)      # exact plant over one sample
obs = ct.c2d(ct.ss(A - L @ C, np.hstack([B, L]), np.eye(3), 0), Ts)

x = np.zeros(3); xh = np.zeros(3); th_prev = 0.0
w_true, w_diff, w_obs = [], [], []
for n in range(3000):                              # 0.3 s at 3 V
    y = np.floor(x[0] / q) * q                     # quantised encoder angle
    w_true.append(x[1]); w_diff.append((y - th_prev) / Ts); w_obs.append(xh[1])
    th_prev = y
    x = plant.A @ x + plant.B[:, 0] * 3.0
    xh = obs.A @ xh + obs.B @ np.array([3.0, y])
w_true, w_diff, w_obs = (np.array(v[1000:]) for v in (w_true, w_diff, w_obs))   # last 0.2 s
print(f"true speed {w_true.mean():.1f} rad/s")
print(f"differenced encoder: rms error {np.sqrt(np.mean((w_diff - w_true) ** 2)):5.2f} rad/s")
print(f"observer estimate:   rms error {np.sqrt(np.mean((w_obs - w_true) ** 2)):5.2f} rad/s")
true speed 149.3 rad/s
differenced encoder: rms error  7.85 rad/s
observer estimate:   rms error  0.04 rad/s

The observer's speed error is about 200 times smaller here, because the simulated model is exact. Its accuracy rests on the model: a wrong JJ or an unmodelled load torque biases it, which is why practical designs add a disturbance state or keep the observer poles moderately fast.

Guided lab: observer on a motor rig

Hand calculation. Observer poles at −600-600, −700-700, −2500 s−1-2500\ \text{s}^{-1}: estimate errors fall to under 1 % within about 8 ms8\ \text{ms}; the speed estimate's noise is set mainly by the slowest observer pole.

Simulation. Move the observer poles to −3000-3000, −3500-3500, −5000-5000 in the second program: the rms error rises from 0.040.04 to about 3 rad/s3\ \text{rad/s}, still better than differencing but much noisier. Fast observers pass quantisation noise through.

What you would measure. Encoder motor on a current-limited 12 V12\ \text{V} supply with a microcontroller logging, at 10 kHz10\ \text{kHz}, the differenced and the observed speed while the motor runs at a constant 3 V3\ \text{V}; a separate tachometer or a long-window count average gives the reference speed. Expect the differenced speed to show steps of 15.7 rad/s15.7\ \text{rad/s} and the observer to stay within a few rad/s, with a bias of a few percent if JJ or kk is off by 10 %.

Hazards and safe setup. As for any motor rig: clamp it, guard the shaft, set the current limit; log data rather than reach near the shaft while it turns.

Pitfalls

  • Observer poles far faster than needed: noisy estimates and large gains.
  • An observer with a wrong model: it converges to the wrong answer without complaint; check estimate against a measured state during commissioning.
  • Feeding the observer a different uu from what the actuator really applied (for example before a saturation): the estimate drifts. Use the saturated, applied value.
  • Forgetting that separation holds for the model, not for every model error: test robustness by simulating with perturbed JJ and kk.

Practice

  1. For A=[0100]A = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} and C=[ 1, 0 ]C = [\,1,\ 0\,], find LL for observer poles at −10-10 and −10-10.
  2. A controller has dominant poles at −4±j3-4 \pm j3. Suggest a range for the observer poles.
Answer
  1. A−LC=[−l11−l20]A - LC = \begin{bmatrix} -l_1 & 1 \\ -l_2 & 0 \end{bmatrix}, polynomial s2+l1s+l2s^2 + l_1 s + l_2; desired (s+10)2=s2+20s+100(s + 10)^2 = s^2 + 20s + 100: L=[ 20, 100 ]TL = [\,20,\ 100\,]^T.
  2. Two to five times faster in real part: about −8-8 to −20 s−1-20\ \text{s}^{-1}, then check the noise in simulation.

Test yourself

The estimation error of a Luenberger observer evolves as

  1. x~˙=Ax~\dot{\tilde{x}} = A\tilde{x}
  2. x~˙=(A−LC)x~\dot{\tilde{x}} = (A - LC)\tilde{x}
  3. x~˙=(A−BK)x~\dot{\tilde{x}} = (A - BK)\tilde{x}
  4. x~=0\tilde{x} = 0 always

The separation principle says the closed-loop poles of controller plus observer are

  1. only the controller poles
  2. the eigenvalues of A−BKA - BK together with those of A−LCA - LC
  3. the product of both
  4. the plant poles

How can ct.place design an observer gain?

  1. it cannot
  2. L = ct.place(A.T, C.T, poles).T, by duality
  3. L = ct.place(A, C, poles)
  4. L = K.T

Why is an observer's speed estimate smoother than a differenced encoder signal?

  1. it uses a faster sample rate
  2. it integrates a model and uses the measurement only through a correction with limited bandwidth
  3. it ignores the encoder
  4. it has no poles