1# copy: never looks at y2d1 = h23d2 = -25*h1 - 2*h2 + 0.5*u4h1 += dt*d1; h2 += dt*d21e = y - h12d1 = h2 + 18*e3d2 = -25*h1 - 2*h2 + 0.5*u + 39*e4h1 += dt*d1; h2 += dt*d2u 0 Nx₁ 0.100 m · x₂ ?y 0.100 mx̂₁ 0.000 m · x̂₂ 0.00 m/sy − ŷ 0.100 m2 kgx̂yy
0.6 s3.7 s012345-0.4-0.200.20.4time (s)m/sVELOCITY x₂ (THE HIDDEN STATE)true (hidden)copy, L = 0observer, L = [18 39]r = 0.2 m00.511.522.5300.10.2time (s)mCART POSITION x₁, LOOP CLOSEDu = −Kx (true x)u = −Kx̂ (estimate)
Lit wire with moving dashes: a signal is flowing along itBack track: the real cart. Front track: the ghost cart, the observer's estimatePlots: hidden velocity and its estimates; position with the loop closed, computed from the modelPills: the sensor reading y going into the observer, and the estimate x̂ going to the controllerAn observer for a cart whose velocity nobody measures: the real cart slides along the back track, and a ghost cart on the front track shows what the observer believes. The plots below are integrated from the cart's equations as the steps play: the uncorrected copy stays wrong for seconds; the observer locks on in well under one. The plots show the true velocity, which a real observer never sees. Only a simulation knows both, which is exactly why we can check the estimate here.

The problem

  1. 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.

The observer

Using the estimate

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.