State Observer

A ball and beam held by a PD controller, with three estimates of the ball's velocity side by side: the finite difference, the filtered derivative and a Luenberger observer. Choose which one feeds the controller, drag the ▲ under the beam to move the desired position r, and press start the observer in the wrong place to watch it recover.
▶ Video: State Observers Explained: Estimating Velocity on a Ball and Beam · playlists Kalman Filters, Ball and Beam
t = 0.0 s

Controller

θ = −kp (p − r) − kd v,  |θ| ≤ 9°
kp = rad/m, kd = rad·s/m
finite difference, filtered derivative: p = y; observer: p̂, v̂

Sensor

Filtered derivative

Observer

Offsets the observer's state by p̂ + 8 cm, v̂ − 0.10 m/s, as in the video's “choosing the gains”.
x̂k+1 = Ad x̂k + Bd θk + L (yk − C x̂k)
p̂k+1 = p̂k + Δt v̂k + l1 (yk − p̂k)
v̂k+1 = v̂k + Δt b θk + l2 (yk − p̂k)
ek+1 = (Ad − LC) ek,  Ad − LC = [1 − l1, Δt; −l2, 1]
b = 5/7 g = m/s² per rad, Δt = 0.02 s

Velocity v [m/s], last 10 s: true v and

Position p from the sensor [m]: true p, measured y, observer p̂, desired r

Beam angle [deg]: θ, the servo's tilt, and the PD's command (dashed: the ±9° limit)

How good is each estimate? (last 8 s, against the true ball)

estimatev error, rms [m/s]lag [ms]p error, rms [mm]
finite difference
filtered derivative
observer
The lag is the delay (in whole samples) that best lines the estimate up with the true velocity; the finite difference and the filtered derivative use the measurement as their position, so their position error is the sensor's.

How it works

The rig is simulated as in the video. The true ball runs the nonlinear model (g sin θ, the centrifugal term, the servo's lag and rate limit and its linkage) at 1 kHz, and the distance sensor measures p every Δt = 20 ms with noise σ. The three velocity estimates run side by side on the same measurements; the observer uses the linear model, discretized with forward Euler. The gauge at the top of the rig shows the true velocity and the three estimates live; the plots show the last 10 s.

On a touch screen, drag the ▲ sideways to move r; a swipe anywhere else scrolls the page.

Things to try