ethzasl-msf - Modular Sensor Fusion
Time delay compensated single and multi sensor fusion framework based on an EKF
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
msf_core.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2013 Simon Lynen, ASL, ETH Zurich, Switzerland
3  * You can contact the author at <slynen at ethz dot ch>
4  * Copyright (C) 2011-2012 Stephan Weiss, ASL, ETH Zurich, Switzerland
5  * You can contact the author at <stephan dot weiss at ieee dot org>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
33 #ifndef MSF_CORE_H_
34 #define MSF_CORE_H_
35 
36 #include <vector>
37 #include <queue>
38 
39 #include <Eigen/Eigen>
40 
42 #include <msf_core/msf_state.h>
44 
45 namespace msf_core {
46 
47 template<typename EKFState_T>
48 class MSF_SensorManager;
49 template<typename EKFState_T>
50 class IMUHandler;
51 
59 template<typename EKFState_T>
60 class MSF_Core {
61  friend class MSF_MeasurementBase<EKFState_T> ;
62  friend class IMUHandler<EKFState_T> ;
63  public:
65 
66  enum {
70  nStatesAtCompileTime = EKFState_T::nStatesAtCompileTime
71  };
72 
73  typedef typename EKFState_T::StateDefinition_T StateDefinition_T;
74  typedef typename EKFState_T::StateSequence_T StateSequence_T;
76  typedef Eigen::Matrix<double, nErrorStatesAtCompileTime, 1> ErrorState;
78  typedef Eigen::Matrix<double, nErrorStatesAtCompileTime,
80 
87 
93  void addMeasurement(shared_ptr<MSF_MeasurementBase<EKFState_T> > measurement);
94 
101  void init(shared_ptr<MSF_MeasurementBase<EKFState_T> > measurement);
102 
107  shared_ptr<EKFState_T> getClosestState(double tstamp);
108 
112  void getAccumF_SC(
113  const shared_ptr<EKFState_T>& state_old,
114  const shared_ptr<EKFState_T>& state_new,
115  Eigen::Matrix<double, nErrorStatesAtCompileTime, nErrorStatesAtCompileTime>& F);
119  shared_ptr<msf_core::MSF_MeasurementBase<EKFState_T> > getPreviousMeasurement(
120  double time, int sensorID);
121 
126  shared_ptr<EKFState_T> getStateAtTime(double tstamp);
127 
133  void predictProcessCovariance(shared_ptr<EKFState_T>& state_old,
134  shared_ptr<EKFState_T>& state_new);
135 
141  void propagateState(shared_ptr<EKFState_T>& state_old,
142  shared_ptr<EKFState_T>& state_new);
143 
148  void CleanUpBuffers();
149 
154  void setPCore(
155  Eigen::Matrix<double, EKFState_T::nErrorStatesAtCompileTime,
156  EKFState_T::nErrorStatesAtCompileTime>& P);
157 
165  ~MSF_Core();
166 
168 
169  private:
170 
175  enum {
177  StateSequence_T>::value
178  };
179 
181  typedef typename msf_tmp::getEnumStateType<StateSequence_T,
183 
185  // asc.
190  std::queue<shared_ptr<MSF_MeasurementBase<EKFState_T> > > queueFutureMeasurements_;
196  Eigen::Matrix<double, 3, 1> g_;
197 
205  // states.
209 
217  bool applyCorrection(shared_ptr<EKFState_T>& delaystate,
218  ErrorState & correction, double fuzzythres = 0.1);
219 
224  void propPToState(shared_ptr<EKFState_T>& state);
225 
226  //Internal state propagation:
234  void process_imu(const msf_core::Vector3&linear_acceleration,
235  const msf_core::Vector3&angular_velocity,
236  const double& msg_stamp, size_t msg_seq);
237 
239 
247  void process_extstate(const msf_core::Vector3& linear_acceleration,
248  const msf_core::Vector3& angular_velocity,
249  const msf_core::Vector3& p, const msf_core::Vector3& v,
250  const msf_core::Quaternion& q,
251  bool is_already_propagated, const double& msg_stamp,
252  size_t msg_seq);
253 
255  void propagatePOneStep();
256 
259 
260 };
261 
262 }
263 ;
264 // msf_core
265 
267 
268 #endif /* MSF_CORE_H_ */