The Extended Kalman Filter: An Interactive Tutorial for Non-Experts
Part 20: TinyEKF
If you’ve come this far, you’re ready to start experimenting with an actual EKF implementation.
TinyEKF is a simple C/C++ implementation that I wrote primarily for running on a microcontroller like Arduino, Teensy, and the STM32 line used in popular flight controllers like Pixhawk, Multiwii32, and OpenPilot. Having looked over the EKF code in some of these flight controllers, I found the code difficult to relate to the understanding expressed in this tutorial. So I decided to write a simple EKF implementation that would be practical to use on an actual microcontroller, taking up a “tiny” amount of memory, while still being flexible enough to use on different projects. I also wrote a Python implementation, so you can prototype your EKF before running it on an actual microcontroller.
TinyEKF requires you to write only a single model function, filling in the values of the state-transition function $f(x)$, its Jacobian matrix $F(x)$, the sensor function $h(x)$, and its Jacobian $H(x)$. The prediction and update then handled automatically by passing the observation vector $z$ to the step function.
Three examples are provided:
- a pure C example using GPS satellite data stored in a file, based on You Chong’s Matlab implementation
- a C++ sensor-fusion example that runs on Arduino
- a Python mouse-tracking example (requires OpenCV)
Previous: The Jacobian