Code Monkey home page Code Monkey logo

kalman-cpp's Introduction

kalman-cpp

C/C++ CI

Kalman filter and extended Kalman filter implementation in C++

Implemented filters so far:

  • Kalman filter
  • Extended Kalman filter
  • Second-order extended Kalman filter
  • Unscented Kalman filter

Please use cmake to build all the codes.

The steps to compile are:

mkdir build
cd build
cmake ..
make

Windows System

In a Windows system, a Visual Studio solution file (VS 2019) is provided.

Dependencies

This library utilizes Armadillo. In Windows system, the armadillo library is provided in "windows-libs" folder. The contents of windows-libs.zip need to be first extracted. Armadillo itself is very easy to use. More information on the Armadillo can be found here.

blas and lapack

By default, now kalman-cpp uses blas and lapack. For Windows machine, working with blas and lapack is a messy stuff. Thus, we will use the precompiled blas and lapack from: https://www.fi.muni.cz/~xsvobod2/misc/lapack/.

The precompiled blas and lapack libraries are included in windows-libs.zip. There are four LIB files. Additionally, in "bin" folder, there are four corresponding DLL files as well. There are four files because two files are for the 32-bit platform, and the other two files are for the 64-bit platform.

The compiled binary must always be located in the same folder as these DLL files.

MATLAB m-files for plotting

MATLAB m-files for each example are provided in 'm-files' folder. Octave can also be used instead of MATLAB.

Documentation

https://auralius.github.io/kalman-cpp/

kalman-cpp's People

Contributors

auralius avatar wkwg 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

Watchers

 avatar  avatar  avatar  avatar

kalman-cpp's Issues

Cmake changes for VSCode

The Visual Studio projects (vs2019/ folder) compiled the examples fine for Windows, but if you want to use VSCode and CMake instead, there are some changes needed: include link_directories to libs, add path for header files, remove armadillo lib link and add blas, lapack libs to link :

cmake_minimum_required(VERSION 2.6)

project(kalman-cpp)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ../bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../bin)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(CMAKE_BUILD_TYPE Debug)

link_directories(${CMAKE_SOURCE_DIR}/windows-libs)
add_library (kalman-cpp ./kalman/kf.cpp ./kalman/ekf.cpp ./kalman/ekf2.cpp ./kalman/ukf.cpp ./kalman/fx.cpp)

target_include_directories (kalman-cpp PUBLIC ./kalman ./windows-libs/armadillo/include)

add_executable(demo1 ./samples/main1.cpp)
add_executable(demo2 ./samples/main2.cpp)
add_executable(demo3 ./samples/main3.cpp)
add_executable(demo4 ./samples/main4.cpp)
add_executable(demo5 ./samples/main5.cpp)
add_executable(demo6 ./samples/main6.cpp)
add_executable(demo7 ./samples/main7.cpp)
add_executable(demo8 ./samples/main8.cpp)
add_executable(demo9 ./samples/main9.cpp)
add_executable(demo10 ./samples/main10.cpp)
add_executable(demo11 ./samples/main11.cpp)

install(TARGETS demo1 RUNTIME DESTINATION ../bin)
install(TARGETS demo2 RUNTIME DESTINATION ../bin)
install(TARGETS demo3 RUNTIME DESTINATION ../bin)
install(TARGETS demo4 RUNTIME DESTINATION ../bin)
install(TARGETS demo5 RUNTIME DESTINATION ../bin)
install(TARGETS demo6 RUNTIME DESTINATION ../bin)
install(TARGETS demo7 RUNTIME DESTINATION ../bin)
install(TARGETS demo8 RUNTIME DESTINATION ../bin)
install(TARGETS demo9 RUNTIME DESTINATION ../bin)
install(TARGETS demo10 RUNTIME DESTINATION ../bin)
install(TARGETS demo11 RUNTIME DESTINATION ../bin)

target_link_libraries (demo1 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo2 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo3 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo4 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo5 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo6 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo7 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo8 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo9 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo10 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)
target_link_libraries (demo11 LINK_PUBLIC kalman-cpp cbia.lib.lapack.dyn.rel.x64.12 cbia.lib.blas.dyn.rel.x64.12)

Since the blas, lapack dlls are in bin, i changed my VSCode launch configuration like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/debug/demo1.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bin/",
"environment": [],
"console": "externalTerminal"
}

]

}

Project integration

How can I integrate your project in a cmake project? I have linking errors

H matrix dimension

Hi @auralius,

Thanks for this library. Trying to some prototyping work with this. I am new to both Armadillo and C++ so I have a question.

For this line, why is H a 4x2 matrix? Shouldn't it be 2x4 given that your X is 4x1?

Let me know if I missed anything obvious.

Error in execution.

Friend, I try to run your project but I have errors.
I installed all the necessary packages: ATLAS, ARPACK, LAPACK, BLAS and ARMADILLO.
Which versions do you use?

ERROR:
joahannes@Joahannes:~/Downloads/kalman-cpp-master$ g++ main5.cpp -o test -O2 -larmadillo ekf.cpp
/tmp/ccAJNHBr.o: na função void arma::glue_times_redirect2_helper<false>::apply<arma::Mat<double>, arma::Col<double> >(arma::Mat<arma::Mat<double>::elem_type>&, arma::Glue<arma::Mat<double>, arma::Col<double>, arma::glue_times> const&)': ekf.cpp:(.text.hot._ZN4arma27glue_times_redirect2_helperILb0EE5applyINS_3MatIdEENS_3ColIdEEEEvRNS3_INT_9elem_typeEEERKNS_4GlueIS7_T0_NS_10glue_timesEEE[_ZN4arma27glue_times_redirect2_helperILb0EE5applyINS_3MatIdEENS_3ColIdEEEEvRNS3_INT_9elem_typeEEERKNS_4GlueIS7_T0_NS_10glue_timesEEE]+0x12c): referência indefinida para wrapper_dgemv_'
ekf.cpp:(.text.hot.ZN4arma27glue_times_redirect2_helperILb0EE5applyINS_3MatIdEENS_3ColIdEEEEvRNS3_INT_9elem_typeEEERKNS_4GlueIS7_T0_NS_10glue_timesEEE[ZN4arma27glue_times_redirect2_helperILb0EE5applyINS_3MatIdEENS_3ColIdEEEEvRNS3_INT_9elem_typeEEERKNS_4GlueIS7_T0_NS_10glue_timesEEE]+0x2f3): referência indefinida para wrapper_dgemv_' ekf.cpp:(.text.hot._ZN4arma27glue_times_redirect2_helperILb0EE5applyINS_3MatIdEENS_3ColIdEEEEvRNS3_INT_9elem_typeEEERKNS_4GlueIS7_T0_NS_10glue_timesEEE[_ZN4arma27glue_times_redirect2_helperILb0EE5applyINS_3MatIdEENS_3ColIdEEEEvRNS3_INT_9elem_typeEEERKNS_4GlueIS7_T0_NS_10glue_timesEEE]+0x807): referência indefinida para wrapper_dgemv'
/tmp/ccAJNHBr.o: na função void arma::glue_times::apply<double, false, false, false, arma::Mat<double>, arma::Mat<double> >(arma::Mat<double>&, arma::Mat<double> const&, arma::Mat<double> const&, double)': ekf.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x286): referência indefinida para wrapper_dgemm
'
ekf.cpp:(.text.hot.ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4[ZN4arma10glue_times5applyIdLb0ELb0ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4]+0x4be): referência indefinida para wrapper_dgemv_' /tmp/ccAJNHBr.o: na função arma::arma_real_only::result arma::op_dot::direct_dot(unsigned int, double const*, double const*)':
ekf.cpp:(.text.hot.ZN4arma6op_dot10direct_dotIdEENS_14arma_real_onlyIT_E6resultEjPKS3_S7[ZN4arma6op_dot10direct_dotIdEENS_14arma_real_onlyIT_E6resultEjPKS3_S7]+0xca): referência indefinida para wrapper_ddot_' /tmp/ccAJNHBr.o: na função void arma::glue_times::apply<double, false, true, false, arma::Mat, arma::Mat >(arma::Mat&, arma::Mat const&, arma::Mat const&, double)':
ekf.cpp:(.text.hot.ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4[ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4]+0x298): referência indefinida para wrapper_dgemm_' ekf.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_[_ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4_]+0x52d): referência indefinida para wrapper_dgemv_'
ekf.cpp:(.text.hot.ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4[ZN4arma10glue_times5applyIdLb0ELb1ELb0ENS_3MatIdEES3_EEvRNS2_IT_EERKT3_RKT4_S4]+0x63f): referência indefinida para wrapper_dsyrk_' /tmp/ccAJNHBr.o: na função void arma::glue_times::apply<double, false, true, false, false, arma::Mat, arma::Mat, arma::Mat >(arma::Mat&, arma::Mat const&, arma::Mat const&, arma::Mat const&, double)':
ekf.cpp:(.text.hot.ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4[ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4]+0x2a1): referência indefinida para wrapper_dgemm_' ekf.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4_[_ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4_]+0x5cf): referência indefinida para wrapper_dgemv_'
ekf.cpp:(.text.hot.ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4[ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4]+0x689): referência indefinida para wrapper_dgemv_' ekf.cpp:(.text.hot._ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4_[_ZN4arma10glue_times5applyIdLb0ELb1ELb0ELb0ENS_3MatIdEES3_S3_EEvRNS2_IT_EERKT4_RKT5_RKT6_S4_]+0x72c): referência indefinida para wrapper_dsyrk_'
/tmp/ccAJNHBr.o: na função void arma::glue_times_redirect3_helper<false>::apply<arma::Mat<double>, arma::Op<arma::Mat<double>, arma::op_htrans>, arma::Op<arma::eGlue<arma::Glue<arma::Glue<arma::Mat<double>, arma::Mat<double>, arma::glue_times>, arma::Op<arma::Mat<double>, arma::op_htrans>, arma::glue_times>, arma::Mat<double>, arma::eglue_plus>, arma::op_inv> >(arma::Mat<arma::Mat<double>::elem_type>&, arma::Glue<arma::Glue<arma::Mat<double>, arma::Op<arma::Mat<double>, arma::op_htrans>, arma::glue_times>, arma::Op<arma::eGlue<arma::Glue<arma::Glue<arma::Mat<double>, arma::Mat<double>, arma::glue_times>, arma::Op<arma::Mat<double>, arma::op_htrans>, arma::glue_times>, arma::Mat<double>, arma::eglue_plus>, arma::op_inv>, arma::glue_times> const&)': ekf.cpp:(.text.hot._ZN4arma27glue_times_redirect3_helperILb0EE5applyINS_3MatIdEENS_2OpIS4_NS_9op_htransEEENS5_INS_5eGlueINS_4GlueINS9_IS4_S4_NS_10glue_timesEEES7_SA_EES4_NS_10eglue_plusEEENS_6op_invEEEEEvRNS3_INT_9elem_typeEEERKNS9_INS9_ISH_T0_SA_EET1_SA_EE[_ZN4arma27glue_times_redirect3_helperILb0EE5applyINS_3MatIdEENS_2OpIS4_NS_9op_htransEEENS5_INS_5eGlueINS_4GlueINS9_IS4_S4_NS_10glue_timesEEES7_SA_EES4_NS_10eglue_plusEEENS_6op_invEEEEEvRNS3_INT_9elem_typeEEERKNS9_INS9_ISH_T0_SA_EET1_SA_EE]+0x38f): referência indefinida para wrapper_dgetri_'
ekf.cpp:(.text.hot._ZN4arma27glue_times_redirect3_helperILb0EE5applyINS_3MatIdEENS_2OpIS4_NS_9op_htransEEENS5_INS_5eGlueINS_4GlueINS9_IS4_S4_NS_10glue_timesEEES7_SA_EES4_NS_10eglue_plusEEENS_6op_invEEEEEvRNS3_INT_9elem_typeEEERKNS9_INS9_ISH_T0_SA_EET1_SA_EE[ZN4arma27glue_times_redirect3_helperILb0EE5applyINS_3MatIdEENS_2OpIS4_NS_9op_htransEEENS5_INS_5eGlueINS_4GlueINS9_IS4_S4_NS_10glue_timesEEES7_SA_EES4_NS_10eglue_plusEEENS_6op_invEEEEEvRNS3_INT_9elem_typeEEERKNS9_INS9_ISH_T0_SA_EET1_SA_EE]+0x5a3): referência indefinida para wrapper_dgetrf_' ekf.cpp:(.text.hot._ZN4arma27glue_times_redirect3_helperILb0EE5applyINS_3MatIdEENS_2OpIS4_NS_9op_htransEEENS5_INS_5eGlueINS_4GlueINS9_IS4_S4_NS_10glue_timesEEES7_SA_EES4_NS_10eglue_plusEEENS_6op_invEEEEEvRNS3_INT_9elem_typeEEERKNS9_INS9_ISH_T0_SA_EET1_SA_EE[_ZN4arma27glue_times_redirect3_helperILb0EE5applyINS_3MatIdEENS_2OpIS4_NS_9op_htransEEENS5_INS_5eGlueINS_4GlueINS9_IS4_S4_NS_10glue_timesEEES7_SA_EES4_NS_10eglue_plusEEENS_6op_invEEEEEvRNS3_INT_9elem_typeEEERKNS9_INS9_ISH_T0_SA_EET1_SA_EE]+0x963): referência indefinida para wrapper_dgetri'
collect2: error: ld returned 1 exit status

Aditional dependencies

lapack and blas have additional dependencies on DLLs that were not installed on my system. I solved by going to:
https://www.intel.com/content/www/us/en/developer/articles/tool/compilers-redistributable-libraries-by-version.html
and downloading "Intel® Fortran Compiler Runtime for Windows* and running the installed. It might save future programmers a few minutes by documenting this dependency.

=======
C:\Downloads\kalman-cpp-master\bin>dumpbin /dependents cbia.lib.lapack.dyn.rel.x64.12.dll
Microsoft (R) COFF/PE Dumper Version 14.26.28806.0
Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file cbia.lib.lapack.dyn.rel.x64.12.dll

File Type: DLL

Image has the following dependencies:

cbia.lib.blas.dyn.rel.x64.12.dll
**libifcoremd.dll**
**libmmd.dll**
MSVCR120.dll
**svml_dispmd.dll**
KERNEL32.dll

LAPACK use

While trying to use the library with larger matrices I ran into this error:
image

I've tried replacing the armadillo dependency with a system installed version, tried modifying the armadillo config.hpp header with #define ARMA_USE_LAPACK - but no matter what I try the error keeps happening. Have you ran into this issue before? Any suggestions?

p.s. I am by no means a cpp expert so I apologise if it turns out that this has nothing to do with your library.

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.