FILTER_KALMAN(9)

πŸ“¦
version 2.9.4 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– filter_kalman β€” HAL Component, section 9 πŸ’–

okay bestie, sit down, hydrate, because we're doing a Kalman filter today and it's honestly iconic. this is FILTER_KALMAN(9) from the LinuxCNC docs and we're gonna make it make sense 🫢


✨ NAME ✨

filter_kalman β€” a Unidimensional Kalman filter, which also goes by the fancier government name linear quadratic estimation (LQE for the girlies in a hurry πŸ’…).


✨ SYNOPSIS ✨

loadrt filter_kalman [count=N|names=name1[,name2...]]

that's it. that's the whole load line. she's simple, she's effective 🌸


✨ DESCRIPTION ✨

so like, what is she FOR? reducing input signal noise β€” think voltage sensors, temperature sensors, all those lil guys who be actin' up with jittery readings 😭. she smooths them out. main character energy fr fr.

more info lives here: https://en.wikipedia.org/wiki/Kalman_filter

πŸŽ€ adjusting Qr and Qk covariances πŸŽ€

okay here's the tea. the default values of Rk and Qk are given for informational purpose only. like, they are NOT the vibe you should just trust. the nature of the filter literally requires the parameters to be individually computed. no shortcuts, bestie β€” the filter wants bespoke numbers πŸ‘‘

one of the possible and quite practical methods (and, ngl, probably far from being the best) of estimating the Rk covariance is this:

  1. collect the raw data from the sensor β€” either by asserting the debug pin or by using halscope πŸ“ˆ
  2. then compute the covariance using the cov() function from the Octave package

and because we're nice, there's a ready-to-use script right here: https://github.com/dwrobel/TrivialKalmanFilter/blob/master/examples/DS18B20Test/covariance.m

adjusting Qk covariance mostly depends on the required response time of the filter. there's a whole relationship between Qk and response time, and it goes like this: the lower the Qk covariance is, the slower the response of the filter is. the way that math just… does that 😌

common practice is also to conservatively set Rk and Qk slightly larger then computed ones to get robustness. (yes, "then". that's what the doc says. we're keeping it. πŸ’–)


✨ FUNCTIONS ✨

  • filter-kalman.N β€” needs a floating-point thread to live her truth. she updates xk-out based on the zk input. that's her whole job and she does it flawlessly ✨

✨ PINS ✨

all of these are per-instance, so N is your instance number β€” like filter-kalman.0, filter-kalman.1, etc. count them, name them, love them πŸ’…

  • filter-kalman.N.debug β€” bit, in. default: FALSE. when you assert this bad boy, she prints out measured and estimated values. like a lil live commentary πŸ—£οΈ
  • filter-kalman.N.passthrough β€” bit, in. default: FALSE. when asserted, she copies the measured value straight into the estimated value. no filtering, just vibes. instant ✨
  • filter-kalman.N.reset β€” bit, in. default: FALSE. when asserted, she resets the filter to its initial state and returns 0 as an estimated value. and FYI β€” the reset pin has higher priority than the passthrough pin, so if both get asserted, reset wins πŸ‘‘
  • filter-kalman.N.zk β€” float, in. the measured value. the raw, unfiltered, messy truth πŸ™ˆ
  • filter-kalman.N.xk-out β€” float, out. the estimated value. the glow-up version πŸ’–

✨ PARAMETERS ✨

these are read-write, so you can go in and tweak them whenever, bestie πŸ”§

  • filter-kalman.N.Rk β€” float, rw. default: 1.17549e-38. this is your estimation of the noise covariances (process). yes girl, process noise. that's the one πŸ“
  • filter-kalman.N.Qk β€” float, rw. default: 1.17549e-38. this is your estimation of the noise covariances (observation). observation noise, the other half of the duo 🌈

✨ AUTHOR ✨

Dmian Wrobel <dwrobel@ertelnet.rybnik.pl> β€” thank you for this gift, we are obsessed 🫢


✨ LICENSE ✨

GPL-2.0-or-later β€” free as in freedom, periodt πŸ’œ


and that's the whole page, bestie!! no cap, you now know a Kalman filter πŸ’…

signing off: this was LinuxCNC Documentation, dated 2026-03-17, filed under FILTER_KALMAN(9) β€” go smooth out some sensor noise, you got this πŸ¦‹βœ¨

πŸ“¦ where this page comes from