-
Notifications
You must be signed in to change notification settings - Fork 1
/
ut.cpp
53 lines (45 loc) · 1.5 KB
/
ut.cpp
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
#include <iostream>
#include <Eigen/Dense>
#include "ukf.h"
using Eigen::Matrix;
using ukf::NumberT;
using ukf::kStDim;
using ukf::kObsDim;
using ukf::Gaussian;
template <typename Number,unsigned dim_st>
struct Predictor
{
Matrix<Number,dim_st,1> operator()(const Matrix<Number,2*dim_st,1> &in)
{
Matrix<Number,dim_st,1> out = in.topLeftCorner(dim_st,1);
return out;
}
};
static Predictor<NumberT,kStDim> g_predictor;
template <typename Number,unsigned dim_st,unsigned dim_obs>
struct Observer
{
Observer():projector_(Matrix<Number,dim_obs,dim_st+dim_obs>::Random()){}
Matrix<Number,dim_obs,1> operator()(const Matrix<Number,dim_st+dim_obs,1> &st)
{
return projector_*st;
}
Matrix<Number,dim_obs,dim_st+dim_obs> projector_;
};
static Observer<NumberT,kStDim,kObsDim> g_observer;
int main(int argc,char *argv[])
{
Gaussian<NumberT,kStDim> x;
Gaussian<NumberT,kStDim> w(0);
Gaussian<NumberT,kObsDim> v(0);
Matrix<NumberT,kObsDim,1> z;
std::cout << "===== x:" << std::endl << x << std::endl;
ukf::UKF<NumberT,kStDim,kObsDim> u(x,w,v,g_predictor,g_observer);
for(unsigned i=0;i<2;++i)
{
Matrix<NumberT,kStDim+kObsDim,1> random_ext_st = Matrix<NumberT,kStDim+kObsDim,1>::Random();
random_ext_st.topLeftCorner(kStDim,1) = random_ext_st.topLeftCorner(kStDim,1) + x.mean_;
z = g_observer(random_ext_st);
std::cout << "===== x estimation: " << std::endl << u.step(z) << std::endl;
}
}