The problem
Pole placement fed the cart both states: position x₁ and velocity x₂. Our cart has only a position sensor. The velocity is a hidden state: it is real and it matters, but nothing measures it.
Idea one: simulate the cart in software, fed the same push u. Its state x̂ (x-hat) is our estimate. The cart was let go from 0.1 m; the copy starts at 0, because we never saw that. Nothing corrects it.
Call the gap e = x − x̂. For the copy it obeys ė = Ae, so it fades only as fast as the cart's own poles, −1 ± j4.90. The velocity estimate is off by 0.01 m/s or more until 3.7 s.
The observer
The sensor gives y, the real position. The copy predicts ŷ = Cx̂ = x̂₁. Their difference, y − ŷ, is the output error: the only evidence that the copy is wrong. At the start it is 0.100 − 0 = 0.100 m.
Feed the output error back into the copy: x̂̇ = Ax̂ + Bu + L(y − ŷ). The column L = [l₁, l₂] says how hard each estimate is pushed. A copy corrected this way is called a Luenberger observer.
Subtract the observer from the cart and u cancels again: ė = (A − LC)e. Now L moves the gap's poles, just as K moved the cart's. The characteristic polynomial is s² + (2 + l₁)s + (25 + 2l₁ + l₂).
Put both error poles at −10, 2.5 times further left than the controller's −4 ± j4. Match (s + 10)² = s² + 20s + 100: 2 + l₁ = 20 and 25 + 2l₁ + l₂ = 100. So L = [18, 39].
Same wrong start, now with L. The ghost cart snaps onto the real one. The velocity estimate is off by 0.24 m/s at worst, and within 0.01 m/s after 0.6 s, where the plain copy needed 3.7 s. Nobody measured velocity.
Using the estimate
Now close the loop on the estimate: u = −Kx̂ + N̄r, with K = [14, 12] and N̄ = 64 from pole placement, aiming at r = 0.2 m. The controller never sees x₂; it trusts the observer.
The loop's poles are the controller's −4 ± j4 plus the observer's −10, −10. This is the separation principle: design K and L apart. The wrong start only costs 23.1 mm at t = 0.42 s, then the curves join.
A faster observer means a bigger L, so it leans harder on y and copies the sensor's noise into x̂ and then into u. A rough rule: make it about twice as fast as the controller. And it needs an observable system.
What is happening
# step 1/11 · hidden
# about: Cart (plant), Position sensor
cart ẋ = A x + B u, y = C x
A = [[0, 1], [-25, -2]] B = [0, 0.5]
C = [1, 0] ← one sensor: position
x1 position measured: y = x1
x2 velocity hidden
State feedback u = -K x needs x2 too.
The cart is the same model as in "State-space models" (2 kg, 4 N·s/m, 50 N/m). Every curve and number in the figure is integrated from its equations with 1 ms steps; the estimation error is also checked against its exact solution. The Python in the step details is plain Python 3 with Euler steps of 1 ms. It prints the same settling time the figure computes with RK4.