All Projects → pronenewbits → Embedded_UKF_Library

pronenewbits / Embedded_UKF_Library

Licence: CC0-1.0 license
A compact Unscented Kalman Filter (UKF) library for Teensy4/Arduino system (or any real time embedded system in general)

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Embedded UKF Library

o1heap
Constant-complexity deterministic memory allocator (heap) for hard real-time high-integrity embedded systems
Stars: ✭ 119 (+283.87%)
Mutual labels:  real-time, embedded, realtime, embedded-systems
Zephyr
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Stars: ✭ 5,335 (+17109.68%)
Mutual labels:  real-time, microcontroller, embedded, mcu
Incubator Nuttx
Apache NuttX is a mature, real-time embedded operating system (RTOS)
Stars: ✭ 591 (+1806.45%)
Mutual labels:  real-time, microcontroller, embedded, mcu
Incubator Nuttx Apps
Apache NuttX Apps is a collection of tools, shells, network utilities, libraries, interpreters and can be used with the NuttX RTOS
Stars: ✭ 65 (+109.68%)
Mutual labels:  real-time, microcontroller, embedded, mcu
Rf1101se Teensy
Driving one of those cheap RF1101SE boards with a Arduino or Teensy
Stars: ✭ 45 (+45.16%)
Mutual labels:  microcontroller, teensy, mcu
Ferret
Ferret is a free software lisp implementation for real time embedded control systems.
Stars: ✭ 878 (+2732.26%)
Mutual labels:  microcontroller, teensy, embedded-systems
Chino Os
A real time operating system for IoT written in C++
Stars: ✭ 139 (+348.39%)
Mutual labels:  microcontroller, embedded, realtime
rnk
rnk is a RTOS targeting ARM architecture.
Stars: ✭ 22 (-29.03%)
Mutual labels:  real-time, microcontroller, mcu
Pyocd
Open source Python library for programming and debugging Arm Cortex-M microcontrollers
Stars: ✭ 550 (+1674.19%)
Mutual labels:  microcontroller, embedded, mcu
Lib Python
Blynk IoT library for Python and Micropython
Stars: ✭ 140 (+351.61%)
Mutual labels:  microcontroller, embedded, mcu
pyUKF
Unscented kalman filter (UKF) library in python that supports multiple measurement updates
Stars: ✭ 52 (+67.74%)
Mutual labels:  unscented-kalman-filter, ukf, kalman-filter
Distortos
object-oriented C++ RTOS for microcontrollers
Stars: ✭ 354 (+1041.94%)
Mutual labels:  real-time, microcontroller, embedded
Lvgl
Powerful and easy-to-use embedded GUI library with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash).
Stars: ✭ 8,172 (+26261.29%)
Mutual labels:  microcontroller, embedded, mcu
Guilite
✔️The smallest header-only GUI library(4 KLOC) for all platforms
Stars: ✭ 5,841 (+18741.94%)
Mutual labels:  microcontroller, embedded, mcu
Daplink
Stars: ✭ 1,162 (+3648.39%)
Mutual labels:  microcontroller, embedded, mcu
Embox
Modular and configurable OS for embedded applications
Stars: ✭ 576 (+1758.06%)
Mutual labels:  microcontroller, embedded, mcu
Real Time Cpp
Real-Time C++ Companion Code
Stars: ✭ 242 (+680.65%)
Mutual labels:  microcontroller, realtime, embedded-systems
Tock
A secure embedded operating system for microcontrollers
Stars: ✭ 3,258 (+10409.68%)
Mutual labels:  microcontroller, embedded, mcu
Nnom
A higher-level Neural Network library for microcontrollers.
Stars: ✭ 382 (+1132.26%)
Mutual labels:  microcontroller, embedded, mcu
Fprime
F' - A flight software and embedded systems framework
Stars: ✭ 8,642 (+27777.42%)
Mutual labels:  real-time, embedded, embedded-systems

Arduino_UKF_Library

This is a compact Unscented Kalman Filter (UKF) library for Teensy4.0/Arduino system (or real time embedded system in general).

  • It's not using Eigen (small source code - more simple to understand).
  • It's not using C++ Standard Library/std (for embedded consideration).
  • If you set SYSTEM_IMPLEMENTATION to SYSTEM_IMPLEMENTATION_EMBEDDED_NO_PRINT in konfig.h, the code is platform agnostic (not using any library beside these C header files: stdlib.h, stdint.h, stdbool.h, string.h, and math.h).
  • There's no malloc/new/free dynamic memory allocation for real time application (but using heavy stack local variables, so you need to run it through static memory analyzer if you are really concerned about implement this in mission critical hard real time application).

The Background

The Unscented Kalman Filter is designed to handle state variable estimation where the system is highly nonlinear that the Extended Kalman Flter (EKF) will do the job poorly, or even fail to do so (e.g. for non-differentiable nonlinear system). Unfortunately, the algorithm is quite complex compared to EKF. With that in mind, I made this library for any student who want to learn the structure of UKF, the computer code implementation of it, and how to use the filter for a nontrivial problem.

This library is made with specific goal for educational purpose (I've made decision to sacrifice speed to get best code readability I could get) while still capable of tackling real-time control system implementation (the code is computed under 250 us for non trivia application! See Some Benchmark section below). I strongly suggest you to learn the EKF first in my other repository (Arduino_EKF_Library) before delve deeper into UKF, because many UKF motivation and design lies on analyzing EKF weakness (specifically, on its need for linearization).

Without further ado, first some definition: UKF Definition

Many authors blended the unscented transformation into kalman filter structure (even in the Jeffrey Uhlmann's paper) to make it into a familiar KF structure. But in this implementation, I prefer to emphasize the unscented transformation structure in the hope you can get the big idea of the transformation more easily. That make the implementation somewhat different from a typical UKF formulation, but in essence it's all the same.

The UKF algorithm can be descibed as: UKF Calculation

How to Use

The UKF code is self contained and can be accessed in the folder ukf_engl (this is the template project). Inside you will find these files:

  • matrix.h/cpp : The backbone of all my code in this account. This files contain the class for Matrix operation.
  • ukf.h/cpp : The source files of the Unscented Kalman Filter Class.
  • konfig.h : The configuration file.
  • ukf_engl.ino : The arduino main file (this is only the template file).

For custom implementation, typically you only need to modify konfig.h and *.ino files. Where basically you need to:

  1. Set the length of X, U, Z vectors and sampling time dt in konfig.h, depend on your model.
  2. Implement the nonlinear update function f(x), measurement function h(x), initialization value P(k=0), and Rv & Rn constants value in the *.ino file.

After that, you only need to initialize the UKF class, set the non-zero initialization matrix by calling UKF::vReset(X_INIT, P_INIT, Rv_INIT, Rn_INIT) function at initialization, and call UKF::bUpdate(Y,U) function every sampling time.

To see how you can implement the library in non-trivial application, I've implemented 2 example:

  1. ukf_example1_pendulum. This example simulate the damped pendulum. See the README file inside the folder to get more information.
  2. ukf_example2_imu. This example process IMU (Inertial Measurement Unit) data using sensor MPU9250. See the README file inside the folder to get more information.

 

*For Arduino configuration (SYSTEM_IMPLEMENTATION is set to SYSTEM_IMPLEMENTATION_EMBEDDED_ARDUINO in konfig.h): The code is tested on compiler Arduino IDE 1.8.10 and hardware Teensy 4.0 Platform.

*For PC configuration (SYSTEM_IMPLEMENTATION is set to SYSTEM_IMPLEMENTATION_PC in konfig.h): The code is tested on compiler Qt Creator 4.8.2 and typical PC Platform.

Important note: For Teensy 4.0, I encounter RAM limitation where the MATRIX_MAXIMUM_SIZE can't be more than 28 (if you are using double precision) or 40 (if using single precision). If you already set more than that, your Teensy might be unable to be programmed (stack overflow make the bootloader program goes awry?). The solution is simply to change the MATRIX_MAXIMUM_SIZE to be less than that, compile & upload the code from the compiler. The IDE then will protest that it cannot find the Teensy board. DON'T PANIC. Click the program button on the Teensy board to force the bootloader to restart and download the firmware from the computer.

next step: implement memory pool for Matrix library!

Some Benchmark

The computation time needed to compute one iteration of UKF::bUpdate(Y,U) function are:

  1. ukf_example1_pendulum (2 state, no input, 2 output): 45 us to compute one iteration (single precision math) or 53 us (double precision). The result, plotted using Scilab (you can see at the beginning, the estimated value is converging to the truth despite wrong initial value):

Result for Pendulum simulation

  1. ukf_example2_imu (4 state, 3 input, 6 output): 206 us to compute one iteration (single precision math) or 246 us (double precision). The result, displayed by Processing script based on FreeIMU project:

Result for IMU visualization

You can also see the video in the ukf_example2_imu folder.

Closing Remark

I hope you can test & validate my result or inform me if there are some bugs / mathematical error you encounter along the way! (or if you notice some grammar error in the documentation).

I published the code under CC0 license, effectively placed the code on public domain. But it will be great if you can tell me if you use the code, for what/why. That means a lot to me and give me motivation to expand the work (⌒▽⌒)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].