• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 18166700002

01 Oct 2025 03:09PM UTC coverage: 71.132% (-0.04%) from 71.174%
18166700002

push

github

paulmthompson
clang format

61 of 61 new or added lines in 3 files covered. (100.0%)

20 existing lines in 3 files now uncovered.

47096 of 66209 relevant lines covered (71.13%)

1084.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.85
/src/StateEstimation/Kalman/kalman.cpp
1
/**
2
 * 
3
 * 
4
 * The MIT License (MIT)
5

6
Copyright (c) 2014 Hayk Martirosyan
7

8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14

15
The above copyright notice and this permission notice shall be included in all
16
copies or substantial portions of the Software.
17

18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
SOFTWARE.
25
* Kalman filter implementation using Eigen. Based on the following
26
* introductory paper:
27
*
28
*     http://www.cs.unc.edu/~welch/media/pdf/kalman_intro.pdf
29
*
30
* @author: Hayk Martirosyan
31
* @date: 2014.11.15
32
*/
33

34
#include "kalman.hpp"
35

36
#include <iostream>
37
#include <stdexcept>
38

39
KalmanFilter::KalmanFilter(
15✔
40
        double dt,
41
        Eigen::MatrixXd const & A,
42
        Eigen::MatrixXd const & C,
43
        Eigen::MatrixXd const & Q,
44
        Eigen::MatrixXd const & R,
45
        Eigen::MatrixXd const & P)
15✔
46
    : A(A),
15✔
47
      C(C),
15✔
48
      Q(Q),
15✔
49
      R(R),
15✔
50
      P0(P),
15✔
51
      m(C.rows()),
15✔
52
      n(A.rows()),
15✔
53
      dt(dt),
15✔
54
      initialized(false),
15✔
55
      I(n, n),
15✔
56
      x_hat(n),
15✔
57
      x_hat_new(n) {
30✔
58
    I.setIdentity();
15✔
59
}
15✔
60

UNCOV
61
KalmanFilter::KalmanFilter() {}
×
62

63
void KalmanFilter::init(double t0, Eigen::VectorXd const & x0) {
15✔
64
    x_hat = x0;
15✔
65
    P = P0;
15✔
66
    this->t0 = t0;
15✔
67
    t = t0;
15✔
68
    initialized = true;
15✔
69
}
15✔
70

71
void KalmanFilter::init() {
×
72
    x_hat.setZero();
×
73
    P = P0;
×
74
    t0 = 0;
×
75
    t = t0;
×
76
    initialized = true;
×
77
}
×
78

79
void KalmanFilter::update(Eigen::VectorXd const & y) {
13✔
80

81
    if (!initialized)
13✔
82
        throw std::runtime_error("Filter is not initialized!");
×
83

84
    x_hat_new = A * x_hat;
13✔
85
    P = A * P * A.transpose() + Q;
13✔
86
    K = P * C.transpose() * (C * P * C.transpose() + R).inverse();
13✔
87
    x_hat_new += K * (y - C * x_hat_new);
13✔
88
    P = (I - K * C) * P;
13✔
89
    x_hat = x_hat_new;
13✔
90

91
    t += dt;
13✔
92
}
13✔
93

94
void KalmanFilter::update(Eigen::VectorXd const & y, double dt, Eigen::MatrixXd const A) {
2✔
95

96
    this->A = A;
2✔
97
    this->dt = dt;
2✔
98
    update(y);
2✔
99
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc