Giter Site home page Giter Site logo

kalman's Introduction

Kalman bdg bdg bdg

Implement Kalman filter for your Arduino projects

ℹ️ Visit the github project's page https://github.com/rfetick/Kalman

☑️ Tested successfully on Arduino Uno and Nano (ATmega 328P old bootloader)

🔄 Any suggestion or issue? Please write to https://github.com/rfetick/Kalman/issues

I. Long description

Other Kalman libraries already exist for Arduino, but so far I have only seen filters applied to independent scalars. The matricial implementation of this project allows to use the full power of the Kalman filter to coupled variables. It allows to merge measurements from multiple sensors such as accelerometers, GPS, ultrasound (distance) or pressure (altitude) sensors...

This library is adapted to your most sophisticated projects. In order to use it you need some knowledge about matrix formalism and be able to write (or find on internet) the actual state equations of your system.

II. Using the Kalman library

1. Prerequisites

BasicLinearAlgebra: You might find it in the library manager of your Arduino IDE, or directly download it at https://github.com/tomstewart89/BasicLinearAlgebra

2. Downloading the Kalman library

This library is available in the official Arduino library manager. Just type Kalman and you should find it.

Other possibility is to download (or clone) this project from GITHUB and add it to your Arduino/libraries/ folder.

3. Start using the library in your Arduino projects

See the GETTING_STARTED file.

See also the examples\ folder.

III. Possible issues

  • The library BLA::Matrix seems to throw errors for matrices of size <1,1>. So the Kalman library will only work for Nstate>1 and Nobs>1. For one-dimensional Kalman filters, please refer to other Arduino libraries.

  • In case of issues with matrices computation please make sure to use the latest version of BasicLinearAlgebra. It works fine on my side with BasicLinearAlgebra version 3.2, however compatibilities issues may occur with different versions.

  • Size of matrices has to be relatively small due to the limited SRAM memory of Arduino. Effort has been made to reduce SRAM usage.

  • An issue has been reported with Arduino Nano IoT 33: the program compiles but is not correctly loaded to Arduino Nano IoT 33. I might investigate this in the future.

kalman's People

Contributors

per1234 avatar rfetick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kalman's Issues

Does not compile on arduino ide

Arduino:1.8.19 (Windows 10), Kart:"Node32s, Default, 80MHz, 921600, None, Disabled"

In file included from C:\Users\yasin\Desktop\Dosyalar\arduino\libraries\Kalman-master\examples\kalman_minimal\kalman_minimal.ino:12:

C:\Users\yasin\Desktop\Dosyalar\arduino\libraries\Kalman-master/Kalman.h:131:59: error: 'Array' does not name a type

template<int Nstate, int Nobs, int Ncom = 0, class MemF = Array<Nstate,Nstate,float> >

                                                       ^~~~~

C:\Users\yasin\Desktop\Dosyalar\arduino\libraries\Kalman-master/Kalman.h:131:64: error: expected '>' before '<' token

template<int Nstate, int Nobs, int Ncom = 0, class MemF = Array<Nstate,Nstate,float> >

                                                            ^

C:\Users\yasin\Desktop\Dosyalar\arduino\libraries\Kalman-master/Kalman.h:135:10: error: 'Identity' in namespace 'BLA' does not name a template type

 BLA::Identity<Nstate,Nstate> Id; // Identity matrix

      ^~~~~~~~

kalman_minimal:31:19: error: template argument 4 is invalid

KALMAN<Nstate,Nobs> K; // your Kalman filter

               ^

C:\Users\yasin\Desktop\Dosyalar\arduino\libraries\Kalman-master\examples\kalman_minimal\kalman_minimal.ino: In function 'void setup()':

kalman_minimal:47:5: error: request for member 'F' in 'K', which is of non-class type 'int'

K.F = {1.0, 0.0,

 ^

kalman_minimal:50:5: error: request for member 'H' in 'K', which is of non-class type 'int'

K.H = {1.0, 0.0,

 ^

kalman_minimal:53:5: error: request for member 'R' in 'K', which is of non-class type 'int'

K.R = {n1*n1, 0.0,

 ^

kalman_minimal:56:5: error: request for member 'Q' in 'K', which is of non-class type 'int'

K.Q = {m1*m1, 0.0,

 ^

C:\Users\yasin\Desktop\Dosyalar\arduino\libraries\Kalman-master\examples\kalman_minimal\kalman_minimal.ino: In function 'void loop()':

kalman_minimal:68:5: error: request for member 'F' in 'K', which is of non-class type 'int'

K.F = {1.0, 0.2,

 ^

kalman_minimal:75:5: error: request for member 'update' in 'K', which is of non-class type 'int'

K.update(obs);

 ^~~~~~

kalman_minimal:78:29: error: request for member 'x' in 'K', which is of non-class type 'int'

Serial << obs << ' ' << K.x << '\n';

                         ^

exit status 1

template argument 4 is invalid

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Use of "inverse" function /// get_sensor_data() missing /// µC blocks

Kalman.h:183:16: error: 'class BLA::Matrix<2, 2, BLA::Array<2, 2, float> >' has no member named 'Inverse'
  183 |   K = P*(~H)*S.Inverse(&status);
      |              ~~^~~~~~~

The BasicLinearAlgebra Github has this example and the syntax is "Invert(Matrix)", so maybe a easy fix? I have solved this by changing that section to:

  //K = P*(~H)*S.Inverse(&status);
  bool is_nonsingular = Invert(S);
  K = P*(~H)*S;
  if(is_nonsingular){
  //if(!status){

Additionally, in the minimal example:
kalman_minimal:71:9: error: 'get_sensor_data' was not declared in this scope
Where is this function? Is it like "SIMULATOR_UPDATE()"?

Additionally:
My Feather M0 stops working (needs manual reset into boot loader) when I include this line:
KALMAN<Nstate,Nobs> K; // your Kalman filter
Need to test a different µC --> works with Arduino Leonardo (Pro Micro // MEGA32U4)

PS:
Any issue or successful test? Your feedback is important for improving this library. See the Contact section at the end of this file or write to the Group!
The link is broken. It can be found atleast at one more position.

GPS & IMU data fusion

Salut Romain,

I was wondering if it would be possible to fuse a low-cost GPS (tinyGPS++) and IMU (bno055)? Thanks

Arduino Boot

After i used the Example, the Arduino didn't booted anymor.
After a lon search i found the term, which is killing the arduini.
KALMAN<Nstate,Nobs> K;
as soon as i implement this, the Arduini is not booting anymore after the upload.
PC cannot find it anymore. I have to do the double reset to send a new program.
I tried it on the Arduino Nano33 IoT and the MKR 1010 (Both SMAD)

Examples do not compile

Using "kalman_minimal" example I get tons of error. I tried to hot-fix the issue (array -> matrix etc.) but simply failed.

kalman_minimal\kalman_minimal.ino: In function 'void setup()':
kalman_minimal\kalman_minimal.ino:54:22: error: no match for 'operator=' (operand types are 'BLA::Matrix<2, 2, Symmetric<2, float> >' and '<brace-enclosed initializer list>')
            0.0, n2*n2};
                      ^
In file included from BasicLinearAlgebra/BasicLinearAlgebra.h:7:0,
                 from Kalman/Kalman.h:34,
                 from kalman_minimal\kalman_minimal.ino:12:
BasicLinearAlgebra/ElementStorage.h:50:13: note: candidate: BLA::Matrix<Rows, Cols, DType>& BLA::Matrix<Rows, Cols, DType>::operator=(const BLA::Matrix<Rows, Cols, DType>&) [with int Rows = 2; int Cols = 2; DType = Symmetric<2, float>]
     Matrix &operator=(const Matrix &mat)
             ^~~~~~~~
BasicLinearAlgebra/ElementStorage.h:50:13: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const BLA::Matrix<2, 2, Symmetric<2, float> >&'
kalman_minimal\kalman_minimal.ino:57:22: error: no match for 'operator=' (operand types are 'BLA::Matrix<2, 2, Symmetric<2, float> >' and '<brace-enclosed initializer list>')
            0.0, m2*m2};
                      ^
In file included from BasicLinearAlgebra/BasicLinearAlgebra.h:7:0,
                 from Kalman/Kalman.h:34,
                 from kalman_minimal\kalman_minimal.ino:12:
BasicLinearAlgebra/ElementStorage.h:50:13: note: candidate: BLA::Matrix<Rows, Cols, DType>& BLA::Matrix<Rows, Cols, DType>::operator=(const BLA::Matrix<Rows, Cols, DType>&) [with int Rows = 2; int Cols = 2; DType = Symmetric<2, float>]
     Matrix &operator=(const Matrix &mat)
             ^~~~~~~~
BasicLinearAlgebra/ElementStorage.h:50:13: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const BLA::Matrix<2, 2, Symmetric<2, float> >&'
In file included from kalman_minimal\kalman_minimal.ino:12:0:
Kalman/Kalman.h: In instantiation of 'KALMAN<Nstate, Nobs, Ncom, MemF>::KALMAN() [with int Nstate = 2; int Nobs = 2; int Ncom = 0; MemF = BLA::Matrix<2, 2, float>]':
kalman_minimal\kalman_minimal.ino:31:21:   required from here
Kalman/Kalman.h:253:3: error: no matching function for call to 'BLA::Matrix<2, 2, Symmetric<2, float> >::Fill(double)'
   this->P.Fill(0.0);
   ^~~~
In file included from Kalman/Kalman.h:34:0,
                 from kalman_minimal\kalman_minimal.ino:12:
BasicLinearAlgebra/BasicLinearAlgebra.h:78:10: note: candidate: void BLA::MatrixBase<DerivedType, rows, cols, DType>::Fill(const DType&) [with DerivedType = BLA::Matrix<2, 2, Symmetric<2, float> >; int rows = 2; int cols = 2; d_type = Symmetric<2, float>; BLA::MatrixBase<DerivedType, rows, cols, DType>::DType = Symmetric<2, float>]
     void Fill(const DType &val) { *this = val; }
          ^~~~
BasicLinearAlgebra/BasicLinearAlgebra.h:78:10: note:   no known conversion for argument 1 from 'double' to 'const DType& {aka const Symmetric<2, float>&}'
In file included from kalman_minimal\kalman_minimal.ino:12:0:
Kalman/Kalman.h: In instantiation of 'void KALMAN<Nstate, Nobs, Ncom, MemF>::_update(BLA::Matrix<Outputs>, BLA::Matrix<Nstate>) [with int Nstate = 2; int Nobs = 2; int Ncom = 0; MemF = BLA::Matrix<2, 2, float>]':
Kalman/Kalman.h:240:10:   required from 'void KALMAN<Nstate, Nobs, Ncom, MemF>::update(BLA::Matrix<Outputs>) [with int Nstate = 2; int Nobs = 2; int Ncom = 0; MemF = BLA::Matrix<2, 2, float>]'
kalman_minimal\kalman_minimal.ino:75:15:   required from here
[...many more errors...]

Issue at line "KALMAN<Nstate,Nobs> K; // your Kalman filter"

In file included from C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:16:0:
c:\Users\ADMIN\Documents\Arduino\libraries\Kalman/Kalman.h:131:59: error: 'Array' does not name a type
template<int Nstate, int Nobs, int Ncom = 0, class MemF = Array<Nstate,Nstate,float> >
^~~~~
c:\Users\ADMIN\Documents\Arduino\libraries\Kalman/Kalman.h:131:64: error: expected '>' before '<' token
template<int Nstate, int Nobs, int Ncom = 0, class MemF = Array<Nstate,Nstate,float> >
^
c:\Users\ADMIN\Documents\Arduino\libraries\Kalman/Kalman.h:135:10: error: 'Identity' in namespace 'BLA' does not name a template type
BLA::Identity<Nstate,Nstate> Id; // Identity matrix
^~~~~~~~
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:36:19: error: template argument 4 is invalid
KALMAN<Nstate,Nobs> K; // your Kalman filter
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino: In function 'void setup()':
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:62:5: error: request for member 'F' in 'K', which is of non-class type 'int'
K.F = {1.0, 0.0,
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:65:5: error: request for member 'H' in 'K', which is of non-class type 'int'
K.H = {1.0, 0.0,
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:68:5: error: request for member 'R' in 'K', which is of non-class type 'int'
K.R = {n1n1, 0.0,
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:71:5: error: request for member 'Q' in 'K', which is of non-class type 'int'
K.Q = {m1
m1, 0.0,
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino: In function 'void loop()':
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:89:5: error: request for member 'update' in 'K', which is of non-class type 'int'
K.update(obs);
^~~~~~
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:92:45: error: request for member 'x' in 'K', which is of non-class type 'int'
Serial << state << ' ' << obs << ' ' << K.x << '\n';
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino: In function 'void SIMULATOR_UPDATE()':
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:120:13: error: request for member 'F' in 'K', which is of non-class type 'int'
state = K.F * state + state_var; // time evolution
^
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino: In function 'void SIMULATOR_MEASURE()':
C:\Users\ADMIN\AppData\Local\Temp.arduinoIDE-unsaved2023812-12140-1a8a6ox.cm8d\kalman_step\kalman_step.ino:131:11: error: request for member 'H' in 'K', which is of non-class type 'int'
obs = K.H * state + noise; // measurement
^

exit status 1

Compilation error: template argument 4 is invalid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.