TooN Algorithm Library - tag  0.2
measurements.h
Go to the documentation of this file.
1 #ifndef TAG_MEASUREMENTS_H
2 #define TAG_MEASUREMENTS_H
3 
4 #include <TooN/se3.h>
5 
6 namespace tag {
7 
13 
17 template <class State>
19 public:
20  static const int M_DIMENSION = 6;
21 
22  TooN::Matrix<M_DIMENSION> covariance;
23  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
24  TooN::Vector<M_DIMENSION> measurement;
25 
27  covariance = TooN::Identity;
28  jacobian = TooN::Zeros;
29  jacobian.template slice<0,0,6,6>() = TooN::Identity;
30  measurement = TooN::Zeros;
31  }
32 
33  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
34  return jacobian;
35  }
36 
37  TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ){
38  return covariance;
39  }
40 
41  TooN::Vector<M_DIMENSION> & getInnovation( const State & state ){
42  return measurement;
43  }
44 
45  void setMeasurement( const TooN::SE3<> & increment ){
46  measurement = increment.ln();
47  }
48 };
49 
53 template <class State>
54 class WorldPose {
55 public:
56  static const int M_DIMENSION = 6;
57 
58  TooN::Matrix<M_DIMENSION> covariance;
59  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
60  TooN::SE3<> measurement;
61 
62  WorldPose(void){
63  covariance = TooN::Identity;
64  jacobian = TooN::Zeros;
65  jacobian.template slice<0,0,6,6>() = TooN::Identity;
66  }
67 
68  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
69  return jacobian;
70  }
71 
72  const TooN::Matrix<M_DIMENSION> getMeasurementCovariance( const State & state ) const {
73  TooN::Matrix<M_DIMENSION> localCovariance = covariance;
74  state.pose.adjoint(localCovariance);
75  return localCovariance;
76  }
77 
78  const TooN::Vector<M_DIMENSION> getInnovation( const State & state ) const {
79  return (measurement * state.pose.inverse()).ln();
80  }
81 };
82 
86 template <class State>
88 public:
89 
90  static const int M_DIMENSION = 3;
91  TooN::Vector<M_DIMENSION> position;
92  TooN::Matrix<M_DIMENSION> covariance;
93  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
94 
96  covariance = TooN::Identity;
97  position = TooN::Zeros;
98  jacobian = TooN::Zeros;
99  jacobian.template slice<0,0,3,3>() = TooN::Identity;
100  }
101 
102  const TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ) const {
103  return jacobian;
104  }
105 
106  const TooN::Matrix<M_DIMENSION> getMeasurementCovariance( const State & state ) const {
107  TooN::Matrix<2 * M_DIMENSION> localCovariance = TooN::Zeros;
108  localCovariance.template slice<0,0,3,3>() = covariance;
109  state.pose.adjoint(localCovariance);
110  return localCovariance.template slice<0,0,3,3>();
111  }
112 
113  const TooN::Vector<M_DIMENSION> getInnovation( const State & state ) const {
116  return -(state.pose * position);
117  }
118 
119  void setCovariance( double sigma ){
120  covariance = TooN::Identity * sigma;
121  }
122 
123  void setCovariance( const TooN::Vector<M_DIMENSION> & sigma ){
124  covariance = TooN::Zeros;
125  for(int i = 0; i < M_DIMENSION; ++i){
126  covariance(i,i) = sigma[i];
127  }
128  }
129 };
130 
133 template <class State>
135 public:
136 
137  static const int M_DIMENSION = 3;
138 
139  TooN::Vector<3> gyro;
140  TooN::Matrix<M_DIMENSION> covariance;
141  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
142 
144  covariance = TooN::Identity;
145  gyro = TooN::Zeros;
146  // angularVelocity jacobian
147  jacobian = TooN::Zeros;
148  jacobian.template slice<0,9,3,3>() = TooN::Identity;
149  }
150 
151  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
152  return jacobian;
153  }
154 
155  TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ){
156  return covariance;
157  }
158 
159  TooN::Vector<M_DIMENSION> getInnovation( const State & state ){
160  // angular velocity
162  return (-gyro - state.angularVelocity);
163  }
164 
165  void setCovariance( double sigma ){
166  covariance = TooN::Identity * sigma;
167  }
168 };
169 
173 template <class State>
175 public:
176 
177  static const int M_DIMENSION = 3;
178 
179  TooN::Vector<3> measurement;
180  TooN::Vector<3> reference;
181 
182  TooN::Matrix<M_DIMENSION> covariance;
183 
185  covariance = TooN::Identity;
186  measurement = TooN::Zeros;
187  reference = TooN::Zeros;
188  }
189 
190  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> getMeasurementJacobian( const State & state ){
191  TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> result = TooN::Zeros;
192  // direction jacobian
193  TooN::Vector<M_DIMENSION> local = state.pose.get_rotation() * reference;
194  result.template slice<0,3,3,1>() = TooN::SO3<>::generator_field(0, local ).as_col();
195  result.template slice<0,4,3,1>() = TooN::SO3<>::generator_field(1, local ).as_col();
196  result.template slice<0,5,3,1>() = TooN::SO3<>::generator_field(2, local ).as_col();
197  return result;
198  }
199 
200  TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ){
201  return covariance;
202  }
203 
204  TooN::Vector<M_DIMENSION> getInnovation( const State & state ){
205  return (measurement - (state.pose.get_rotation() * reference));
206  }
207 
208  void setCovariance( double sigma ){
209  covariance = TooN::Identity * sigma;
210  }
211 };
212 
213 } // namespace tag
214 
215 #endif