TooN Algorithm Library - tag  0.2
constantvelocity.h
Go to the documentation of this file.
1 #ifndef TAG_CONSTANTVELOCITY_H
2 #define TAG_CONSTANTVELOCITY_H
3 
4 #include <TooN/se3.h>
5 
6 namespace tag {
7 
8 namespace ConstantVelocity {
9 
14 
18 class State {
19 public:
20  inline State(void){
21  reset();
22  }
23 
24  void reset(void){
25  pose = TooN::SE3<>();
26  angularVelocity = TooN::Zeros;
27  velocity = TooN::Zeros;
28  covariance = TooN::Identity;
29  }
30 
31  void resetVelocity(void){
32  angularVelocity = TooN::Zeros;
33  velocity = TooN::Zeros;
34  }
35 
36  static const int STATE_DIMENSION = 12;
37  TooN::SE3<> pose;
38  TooN::Vector<3> angularVelocity;
39  TooN::Vector<3> velocity;
40  TooN::Matrix<STATE_DIMENSION> covariance;
41 };
42 
45 template <class O>
46 inline O & operator<< (O & os , const State & st){
47  os << st.pose.ln() << st.velocity << st.angularVelocity << st.pose.inverse().get_translation();
48  return os;
49 }
50 
54 class Model {
55 public:
56  TooN::Vector<State::STATE_DIMENSION> sigma;
57  TooN::Matrix<State::STATE_DIMENSION> jacobian;
58  TooN::Matrix<State::STATE_DIMENSION> noise;
59  // dampening of velocity
60  double damp;
61 
62  Model(void){
63  sigma = TooN::Zeros;
64  damp = 1;
65  jacobian = TooN::Identity;
66  noise = TooN::Zeros;
67  }
68 
69  // Jacobian has pos, rot, vel, angularVel in this order
70  const TooN::Matrix<State::STATE_DIMENSION> & getJacobian(const State & /*state*/, const double dt) {
71  jacobian(0,6) = dt;
72  jacobian(1,7) = dt;
73  jacobian(2,8) = dt;
74  jacobian(3,9) = dt;
75  jacobian(4,10) = dt;
76  jacobian(5,11) = dt;
77  return jacobian;
78  }
79 
80  void updateState( State & state, const double dt ){
81  // full velocity vector
82  TooN::Vector<6> vel;
83  vel.slice<0,3>() = state.velocity;
84  vel.slice<3,3>() = state.angularVelocity;
85 
86  // update translational components
87  state.pose = TooN::SE3<>::exp(vel * dt) * state.pose;
88  // dampen velocitys
89  double attenuation = pow(damp, dt);
90  state.velocity *= attenuation;
91  state.angularVelocity *= attenuation;
92  }
93 
94  const TooN::Matrix<State::STATE_DIMENSION> & getNoiseCovariance( const double dt ){
95  const double dt2 = dt * dt * 0.5;
96  const double dt3 = dt * dt * dt * 0.3333333333333;
97  for(unsigned int i = 0; i < 6; i++){
98  noise(i,i) = dt * sigma[i] + dt3 * sigma[i+6];
99  noise(i+6,i) = noise(i,i+6) = dt2 * sigma[i+6];
100  noise(i+6, i+6) = dt * sigma[i+6];
101  }
102  return noise;
103  }
104 
105  void updateFromMeasurement( State & state, const TooN::Vector<State::STATE_DIMENSION> & innovation ){
106  state.pose = TooN::SE3<>::exp(innovation.slice<0,6>()) * state.pose;
107  state.velocity = state.velocity + innovation.slice<6,3>();
108  state.angularVelocity = state.angularVelocity + innovation.slice<9,3>();
109  }
110 };
111 
112 } // namespace ConstantVelocity
113 
114 } // namespace tag
115 
116 #endif