Control Theory 4
When I can, I point to other online resources that sufficiently explain or illustrate material because I don't like duplicating work. This guide to Kalman filters is very well written in my opinion and includes graphics which I couldn't hope to replicate (I don't do graphics design well). Apparently he used Photoshop and a stylus.
Now that the theoretical groundwork has been laid, I'm going to present a Kalman filter implementation written in C++ that our team used in 2013. That year, we our robot had a flywheel and we needed to measure its speed. We used a Hall's Effect sensor to produce analog voltage pulses from gear teeth rotating by it. A Schmitt trigger was used to turn these analog voltages into well defined digital values we could count in software. The speeds calculated where really noisy, so we employed a filter to allow the use of larger Kd terms in the flywheel's PID controller to decrease settling time (see CT 1 for more on PID controllers). This implementation only used one input, so it functioned like a sophisticated averaging technique. It did, however, work much better than a rolling average filter; it filtered the noise out sufficiently while introducing less lag.KalmanFilter.hpp
Normally, one would gather sample measurements to determine the optimum values for the process noise Q and measurement noise R. I didn't know how to do that in 2013, so I found values that worked through trial and error. That only took about an hour, but I don't see that process working for more complicated systems which use multidimensional Kalman filters.