Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
J
jfx_kalman_filter_src
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
oscar
jfx_kalman_filter_src
Commits
4978d6a1
Commit
4978d6a1
authored
Dec 15, 2021
by
oscar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改Xd为Xf因为需要用float,不能使用double
parent
86946029
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
26 deletions
+26
-26
kalman_filter.cpp
tracker/kalman_filter.cpp
+17
-17
kalman_filter.h
tracker/kalman_filter.h
+9
-9
No files found.
tracker/kalman_filter.cpp
View file @
4978d6a1
...
...
@@ -6,27 +6,27 @@ KalmanFilter::KalmanFilter(unsigned int num_states, unsigned int num_obs) :
num_states_
(
num_states
),
num_obs_
(
num_obs
)
{
/*** Predict ***/
// State vector
x_
=
Eigen
::
VectorX
d
::
Zero
(
num_states
);
x_
=
Eigen
::
VectorX
f
::
Zero
(
num_states
);
// Predicted(a prior) state vector
x_predict_
=
Eigen
::
VectorX
d
::
Zero
(
num_states
);
x_predict_
=
Eigen
::
VectorX
f
::
Zero
(
num_states
);
// State transition matrix F_
F_
=
Eigen
::
MatrixX
d
::
Zero
(
num_states
,
num_states
);
F_
=
Eigen
::
MatrixX
f
::
Zero
(
num_states
,
num_states
);
// Error covariance matrix P
P_
=
Eigen
::
MatrixX
d
::
Zero
(
num_states
,
num_states
);
P_
=
Eigen
::
MatrixX
f
::
Zero
(
num_states
,
num_states
);
// Predicted(a prior) error covariance matrix
P_predict_
=
Eigen
::
MatrixX
d
::
Zero
(
num_states
,
num_states
);
P_predict_
=
Eigen
::
MatrixX
f
::
Zero
(
num_states
,
num_states
);
// Covariance matrix of process noise
Q_
=
Eigen
::
MatrixX
d
::
Zero
(
num_states
,
num_states
);
Q_
=
Eigen
::
MatrixX
f
::
Zero
(
num_states
,
num_states
);
/*** Update ***/
// Observation matrix
H_
=
Eigen
::
MatrixX
d
::
Zero
(
num_obs
,
num_states
);
H_
=
Eigen
::
MatrixX
f
::
Zero
(
num_obs
,
num_states
);
// Covariance matrix of observation noise
R_
=
Eigen
::
MatrixX
d
::
Zero
(
num_obs
,
num_obs
);
R_
=
Eigen
::
MatrixX
f
::
Zero
(
num_obs
,
num_obs
);
log_likelihood_delta_
=
0.0
;
NIS_
=
0.0
;
...
...
@@ -46,21 +46,21 @@ void KalmanFilter::Predict() {
}
Eigen
::
VectorX
d
KalmanFilter
::
PredictionToObservation
(
const
Eigen
::
VectorXd
&
state
)
{
Eigen
::
VectorX
f
KalmanFilter
::
PredictionToObservation
(
const
Eigen
::
VectorXf
&
state
)
{
return
(
H_
*
state
);
}
void
KalmanFilter
::
Update
(
const
Eigen
::
VectorX
d
&
z
)
{
Eigen
::
VectorX
d
z_predict
=
PredictionToObservation
(
x_predict_
);
void
KalmanFilter
::
Update
(
const
Eigen
::
VectorX
f
&
z
)
{
Eigen
::
VectorX
f
z_predict
=
PredictionToObservation
(
x_predict_
);
// y - innovation, z - real observation, z_predict - predicted observation
Eigen
::
VectorX
d
y
=
z
-
z_predict
;
Eigen
::
VectorX
f
y
=
z
-
z_predict
;
Eigen
::
MatrixX
d
Ht
=
H_
.
transpose
();
Eigen
::
MatrixX
f
Ht
=
H_
.
transpose
();
// S - innovation covariance
Eigen
::
MatrixX
d
S
=
H_
*
P_predict_
*
Ht
+
R_
;
Eigen
::
MatrixX
f
S
=
H_
*
P_predict_
*
Ht
+
R_
;
NIS_
=
y
.
transpose
()
*
S
.
inverse
()
*
y
;
...
...
@@ -85,12 +85,12 @@ void KalmanFilter::Update(const Eigen::VectorXd& z) {
// K - Kalman gain
Eigen
::
MatrixX
d
K
=
P_predict_
*
Ht
*
S
.
inverse
();
Eigen
::
MatrixX
f
K
=
P_predict_
*
Ht
*
S
.
inverse
();
// Updated state estimation
x_
=
x_predict_
+
K
*
y
;
Eigen
::
MatrixX
d
I
=
Eigen
::
MatrixXd
::
Identity
(
num_states_
,
num_states_
);
Eigen
::
MatrixX
f
I
=
Eigen
::
MatrixXf
::
Identity
(
num_states_
,
num_states_
);
// Joseph form
//P_ = (I - K * H_) * P_predict_ * (I - K * H_).transpose() + K * R_ * K.transpose();
// Optimal gain
...
...
@@ -98,7 +98,7 @@ void KalmanFilter::Update(const Eigen::VectorXd& z) {
}
float
KalmanFilter
::
CalculateLogLikelihood
(
const
Eigen
::
VectorX
d
&
y
,
const
Eigen
::
MatrixXd
&
S
)
{
float
KalmanFilter
::
CalculateLogLikelihood
(
const
Eigen
::
VectorX
f
&
y
,
const
Eigen
::
MatrixXf
&
S
)
{
float
log_likelihood
;
// Note: Computing log(M.determinant()) in Eigen C++ is risky for large matrices since it may overflow or underflow.
...
...
tracker/kalman_filter.h
View file @
4978d6a1
...
...
@@ -37,36 +37,36 @@ public:
* using the observation model
* User can implement their own method for more complicated models
*/
virtual
Eigen
::
VectorX
d
PredictionToObservation
(
const
Eigen
::
VectorXd
&
state
);
virtual
Eigen
::
VectorX
f
PredictionToObservation
(
const
Eigen
::
VectorXf
&
state
);
/**
* Updates the state by using Extended Kalman Filter equations
* @param z The measurement at k+1
*/
virtual
void
Update
(
const
Eigen
::
VectorX
d
&
z
);
virtual
void
Update
(
const
Eigen
::
VectorX
f
&
z
);
/**
* Calculate marginal log-likelihood to evaluate different parameter choices
*/
float
CalculateLogLikelihood
(
const
Eigen
::
VectorX
d
&
y
,
const
Eigen
::
MatrixXd
&
S
);
float
CalculateLogLikelihood
(
const
Eigen
::
VectorX
f
&
y
,
const
Eigen
::
MatrixXf
&
S
);
// State vector
Eigen
::
VectorX
d
x_
,
x_predict_
;
Eigen
::
VectorX
f
x_
,
x_predict_
;
// Error covariance matrix
Eigen
::
MatrixX
d
P_
,
P_predict_
;
Eigen
::
MatrixX
f
P_
,
P_predict_
;
// State transition matrix
Eigen
::
MatrixX
d
F_
;
Eigen
::
MatrixX
f
F_
;
// Covariance matrix of process noise
Eigen
::
MatrixX
d
Q_
;
Eigen
::
MatrixX
f
Q_
;
// measurement matrix
Eigen
::
MatrixX
d
H_
;
Eigen
::
MatrixX
f
H_
;
// covariance matrix of observation noise
Eigen
::
MatrixX
d
R_
;
Eigen
::
MatrixX
f
R_
;
unsigned
int
num_states_
,
num_obs_
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment