Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unscented Kalman Filter in python #1411

Merged
merged 19 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/kalman/ukf-nonlinear-complex-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@
const unsigned int nbCmds = cmds.size();

// Initialize the attributes of the UKF
std::shared_ptr<vpUKSigmaDrawerAbstract> drawer = std::make_shared<vpUKSigmaDrawerMerwe>(3, 0.00001, 2., 0, stateResidual, stateAdd);
std::shared_ptr<vpUKSigmaDrawerAbstract> drawer = std::make_shared<vpUKSigmaDrawerMerwe>(3, 0.1, 2., 0, stateResidual, stateAdd);

Check warning on line 543 in example/kalman/ukf-nonlinear-complex-example.cpp

View check run for this annotation

Codecov / codecov/patch

example/kalman/ukf-nonlinear-complex-example.cpp#L543

Added line #L543 was not covered by tests

vpMatrix R1landmark(2, 2, 0.); // The covariance of the noise introduced by the measurement with 1 landmark
R1landmark[0][0] = sigmaRange*sigmaRange;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/visp3/core/vpUKSigmaDrawerMerwe.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
protected:
inline void computeLambda()
{
m_lambda = m_alpha * m_alpha * (m_n + m_kappa) - m_n;
m_lambda = m_alpha * m_alpha * (static_cast<double>(m_n) + m_kappa) - static_cast<double>(m_n);

Check warning on line 138 in modules/core/include/visp3/core/vpUKSigmaDrawerMerwe.h

View check run for this annotation

Codecov / codecov/patch

modules/core/include/visp3/core/vpUKSigmaDrawerMerwe.h#L138

Added line #L138 was not covered by tests
}

double m_alpha; /*!< A factor, which should be a real in the interval [0; 1]. The larger alpha is,
Expand Down
7 changes: 5 additions & 2 deletions modules/core/src/math/matrix/vpMatrix_cholesky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@
vpMatrix A = *this;
dpotrf_((char *)"L", &rowNum_, A.data, &lda, &info);

if (info != 0)
throw(vpException(vpException::fatalError, "Cannot inverse by Cholesky with Lapack: error in dpotrf_()"));
if (info != 0) {
std::stringstream errMsg;
errMsg << "Cannot inverse by Cholesky with Lapack: error "<< info << " in dpotrf_()";
throw(vpException(vpException::fatalError, errMsg.str()));

Check warning on line 199 in modules/core/src/math/matrix/vpMatrix_cholesky.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/math/matrix/vpMatrix_cholesky.cpp#L197-L199

Added lines #L197 - L199 were not covered by tests
}

dpotri_((char *)"L", &rowNum_, A.data, &lda, &info);
if (info != 0) {
Expand Down
15 changes: 15 additions & 0 deletions modules/python/doc/rst/tutorials/misc/ukf-linear.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Example on a linear case study on how to use Unscented Kalman filter
=======================================================================

This example shows how to use an Unscented Kalman filter in Python.

This example is a linear case study. It is not what is intended for the Unscented
Kalman filter, but it permits to get familiar with the different classes that
are used.

The state vector and measurements are explained in the `C++ example <https://visp-doc.inria.fr/doxygen/visp-daily/ukf-linear-example_8cpp-example.html>`_.



.. literalinclude:: /examples/ukf-linear-example.py
:language: python
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Example on a complex non-linear case study on how to use Unscented Kalman filter
=======================================================================

This example shows how to use an Unscented Kalman filter in Python.

This example is a complex non-linear case study.

The state vector and measurements are explained in the `C++ example <https://visp-doc.inria.fr/doxygen/visp-daily/ukf-nonlinear-complex-example_8cpp-example.html>`_.



.. literalinclude:: /examples/ukf-nonlinear-complex-example.py
:language: python
13 changes: 13 additions & 0 deletions modules/python/doc/rst/tutorials/misc/ukf-nonlinear-linear.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Example on a non-linear case study on how to use Unscented Kalman filter
=======================================================================

This example shows how to use an Unscented Kalman filter in Python.

This example is a non-linear case study.

The state vector and measurements are explained in the `C++ example <https://visp-doc.inria.fr/doxygen/visp-daily/ukf-nonlinear-example_8cpp-example.html>`_.



.. literalinclude:: /examples/ukf-nonlinear-example.py
:language: python
39 changes: 39 additions & 0 deletions modules/python/doc/rst/tutorials/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,42 @@ Tracking
:maxdepth: 2

tracking/*

rolalaro marked this conversation as resolved.
Show resolved Hide resolved


.. _Examples:

Examples
====================


Visual servoing
-----------------------

.. toctree::
:glob:
:maxdepth: 2

vs/*



Tracking
-----------------------

.. toctree::
:glob:
:maxdepth: 2

tracking/*



Other tools
-----------------------

.. toctree::
:glob:
:maxdepth: 2

misc/*
6 changes: 2 additions & 4 deletions modules/python/examples/ukf-linear-example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#############################################################################
#
# ViSP, open source Visual Servoing Platform software.
# Copyright (C) 2005 - 2023 by Inria. All rights reserved.
# Copyright (C) 2005 - 2024 by Inria. All rights reserved.
#
# This software is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -58,7 +58,7 @@
not perfect.
"""

from visp.core import ColVector, Matrix, UnscentedKalman, UKSigmaDrawerMerwe, GaussRand
from visp.core import ColVector, Matrix, UnscentedKalman, UKSigmaDrawerMerwe

# For the Graphical User Interface
try:
Expand Down Expand Up @@ -184,8 +184,6 @@ def generate_Q_matrix(dt: float) -> Matrix:
z_prec = ColVector(2, 0.) # Previous measurement vector
np.random.seed(4224)

rngX = GaussRand(sigmaXmeas, 0., 4224) # Gaussian noise random generator for x-axis measurement
rngY = GaussRand(sigmaYmeas, 0., 2112) # Gaussian noise random generator for y-axis measurement
for i in range(100):
# Creating noisy measurements
x_meas = gt_X[0] + np.random.normal(0.0, sigmaXmeas)
Expand Down
Loading
Loading