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

paulmthompson / WhiskerToolbox / 18137869742

30 Sep 2025 05:12PM UTC coverage: 71.091% (-0.009%) from 71.1%
18137869742

push

github

paulmthompson
remove M_PI and replace with std::numbers::pi

356 of 455 new or added lines in 11 files covered. (78.24%)

13 existing lines in 2 files now uncovered.

47030 of 66155 relevant lines covered (71.09%)

1087.73 hits per line

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

82.98
/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(
104✔
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)
104✔
46
    : A(A),
104✔
47
      C(C),
104✔
48
      Q(Q),
104✔
49
      R(R),
104✔
50
      P0(P),
104✔
51
      m(C.rows()),
104✔
52
      n(A.rows()),
104✔
53
      dt(dt),
104✔
54
      initialized(false),
104✔
55
      I(n, n),
104✔
56
      x_hat(n),
104✔
57
      x_hat_new(n) {
208✔
58
    I.setIdentity();
104✔
59
}
104✔
60

61
KalmanFilter::KalmanFilter() {}
16✔
62

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

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

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

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

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

91
    t += dt;
734✔
92
}
734✔
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