OSVR-Core
FlexibleKalmanFilter.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_FlexibleKalmanFilter_h_GUID_3A3B8A14_6DFC_4A81_97CA_189834AC4B61
26 #define INCLUDED_FlexibleKalmanFilter_h_GUID_3A3B8A14_6DFC_4A81_97CA_189834AC4B61
27 
28 // Internal Includes
29 #include "FlexibleKalmanBase.h"
30 #include "FlexibleKalmanCorrect.h"
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 // - none
37 
38 namespace osvr {
39 namespace kalman {
40 
41  template <typename StateType, typename ProcessModelType>
42  void predict(StateType &state, ProcessModelType &processModel, double dt) {
43  processModel.predictState(state, dt);
44  OSVR_KALMAN_DEBUG_OUTPUT("Predicted state",
45  state.stateVector().transpose());
46 
47  OSVR_KALMAN_DEBUG_OUTPUT("Predicted error covariance",
48  state.errorCovariance());
49  }
50 
56  template <typename StateType, typename ProcessModelType,
57  typename MeasurementType>
58  inline bool correct(StateType &state, ProcessModelType &processModel,
59  MeasurementType &meas, bool cancelIfNotFinite = true) {
60 
61  auto inProgress = beginCorrection(state, processModel, meas);
62  if (cancelIfNotFinite && !inProgress.stateCorrectionFinite) {
63  return false;
64  }
65 
66  return inProgress.finishCorrection(cancelIfNotFinite);
67  }
68 
72  template <typename ProcessModelType,
73  typename StateType = typename ProcessModelType::State>
75  public:
76  using State = StateType;
77  using ProcessModel = ProcessModelType;
78  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
81  FlexibleKalmanFilter() : m_processModel(), m_state() {}
82 
85  explicit FlexibleKalmanFilter(State const &state)
86  : m_processModel(), m_state(state) {}
87 
90  explicit FlexibleKalmanFilter(State &&state)
91  : m_processModel(), m_state(state) {}
92 
94  FlexibleKalmanFilter(ProcessModel const &processModel,
95  State const &state)
96  : m_processModel(processModel), m_state(state) {}
97 
99  FlexibleKalmanFilter(ProcessModel &&processModel, State &&state)
100  : m_processModel(processModel), m_state(state) {}
101 
102  void predict(double dt) {
103  kalman::predict(state(), processModel(), dt);
104  }
105 
106  template <typename MeasurementType>
107  void correct(MeasurementType &meas) {
108  kalman::correct(state(), processModel(), meas);
109  }
110 
111  ProcessModel &processModel() { return m_processModel; }
112  ProcessModel const &processModel() const { return m_processModel; }
113 
114  State &state() { return m_state; }
115  State const &state() const { return m_state; }
116 
117  private:
118  ProcessModel m_processModel;
119  State m_state;
120  };
121 
122 } // namespace kalman
123 } // namespace osvr
124 
125 #endif // INCLUDED_FlexibleKalmanFilter_h_GUID_3A3B8A14_6DFC_4A81_97CA_189834AC4B61
typename FilterType::State StateType
Given a filter type, get the state type.
Definition: FlexibleKalmanBase.h:91
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
FlexibleKalmanFilter(State const &state)
Copy initialization from just state - depends on default-initializable process model.
Definition: FlexibleKalmanFilter.h:85
FlexibleKalmanFilter(ProcessModel const &processModel, State const &state)
copy initialization
Definition: FlexibleKalmanFilter.h:94
FlexibleKalmanFilter(State &&state)
Move initialization from just state - depends on default-initializable process model.
Definition: FlexibleKalmanFilter.h:90
typename FilterType::ProcessModel ProcessModelType
Given a filter type, get the process model type.
Definition: FlexibleKalmanBase.h:95
CorrectionInProgress< StateType, MeasurementType > beginCorrection(StateType &state, ProcessModelType &processModel, MeasurementType &meas)
Definition: FlexibleKalmanCorrect.h:135
FlexibleKalmanFilter(ProcessModel &&processModel, State &&state)
move initialization.
Definition: FlexibleKalmanFilter.h:99
EIGEN_MAKE_ALIGNED_OPERATOR_NEW FlexibleKalmanFilter()
Default initialization - depends on default-initializable process model and state.
Definition: FlexibleKalmanFilter.h:81
bool correct(StateType &state, ProcessModelType &processModel, MeasurementType &meas, bool cancelIfNotFinite=true)
Definition: FlexibleKalmanFilter.h:58
The main class implementing the common components of the Kalman family of filters.
Definition: FlexibleKalmanFilter.h:74