FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ExtendedKalmanFilter/src/tools.cpp at master · asterixds/ExtendedKalmanFilter · GitHub
asterixds
/
ExtendedKalmanFilter
Public
Notifications
You must be signed in to change notification settings
Fork
38
Star
89
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ExtendedKalmanFilter
/
src
/
tools.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
75 lines (60 loc) · 1.69 KB
Breadcrumbs
ExtendedKalmanFilter
/
src
/
tools.cpp
Copy path
File metadata and controls
executable file
·
75 lines (60 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
include
<
iostream
>
#
include
"
tools.h
"
using
Eigen::VectorXd;
using
Eigen::MatrixXd;
using
std::vector;
const
float
EPS
=
0.0001
;
Tools::Tools
() {}
Tools::~Tools
() {}
VectorXd
Tools::CalculateRMSE
(
const
vector<VectorXd> &estimations,
const
vector<VectorXd> &ground_truth) {
/*
*
TODO:
* Calculate the RMSE here.
*/
VectorXd
rmse
(
4
);
rmse <<
0
,
0
,
0
,
0
;
//
estimation vector len should be non-zero and equal ground truth vector len
if
(estimations.
size
() != ground_truth.
size
()
|| estimations.
size
() ==
0
){
cout <<
"
Invalid estimation or ground_truth data
"
<< endl;
return
rmse;
}
//
calculate squared errors
for
(
unsigned
int
i=
0
; i < estimations.
size
(); ++i){
VectorXd errors = estimations[i] - ground_truth[i];
errors = errors.
array
()*errors.
array
();
//
coefficient-wise multiplication
rmse += errors;
}
//
calculate the mean square root
rmse = rmse/estimations.
size
();
rmse = rmse.
array
().
sqrt
();
//
return the result
return
rmse;
}
MatrixXd
Tools::CalculateJacobian
(
const
VectorXd& x_state) {
/*
*
TODO:
* Calculate a Jacobian here.
*/
MatrixXd Hj =
MatrixXd::Zero
(
3
,
4
);
//
recover state parameters
float
px =
x_state
(
0
);
float
py =
x_state
(
1
);
float
vx =
x_state
(
2
);
float
vy =
x_state
(
3
);
float
c1 = px*px+py*py;
//
check division by zero
if
(
fabs
(c1) <
EPS
){
cout <<
"
c1 =
"
<< c1 << endl;
cout <<
"
CalculateJacobian () - Error - Division by Zero
"
<< endl;
return
Hj;
}
float
c2 =
sqrt
(c1);
float
c3 = (c1*c2);
//
compute the Jacobian
Hj << (px/c2), (py/c2),
0
,
0
,
-(py/c1), (px/c1),
0
,
0
,
py*(vx*py - vy*px)/c3, px*(px*vy - py*vx)/c3, px/c2, py/c2;
return
Hj;
}
Back
|
FazBrowse Home
|
New Git URL