OSVR-Core
FlexibleKalmanBase.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_FlexibleKalmanBase_h_GUID_E4CC84A0_1B4F_4389_95ED_9C37F5FEE95D
26 #define INCLUDED_FlexibleKalmanBase_h_GUID_E4CC84A0_1B4F_4389_95ED_9C37F5FEE95D
27 
28 // Internal Includes
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <type_traits>
36 
37 #ifndef OSVR_KALMAN_DEBUG_OUTPUT
38 #define OSVR_KALMAN_DEBUG_OUTPUT(Name, Value)
39 #endif
40 
41 namespace osvr {
44 namespace kalman {
46  namespace types {
48  using Scalar = double;
49 
51  using DimensionType = std::size_t;
52 
54  template <DimensionType n>
55  using DimensionConstant = std::integral_constant<DimensionType, n>;
56 
57  struct HasDimensionBase {};
58  } // namespace types
59 
62  template <types::DimensionType DIM>
64  using Dimension = types::DimensionConstant<DIM>;
65  };
66 
67  namespace types {
68  namespace detail {
69  template <typename T, typename = void> struct Dimension_impl {
71  };
72  // explicit specialization
73  template <DimensionType n>
74  struct Dimension_impl<DimensionConstant<n>, void> {
75  using type = DimensionConstant<n>;
76  };
77  // explicit specialization
78  template <typename T>
79  struct Dimension_impl<T, typename std::enable_if<std::is_base_of<
80  HasDimensionBase, T>::value>::type> {
81  using type = typename T::Dimension;
82  };
83  } // namespace detail
86  template <typename T>
87  using Dimension = typename detail::Dimension_impl<T>::type;
88 
90  template <typename FilterType>
91  using StateType = typename FilterType::State;
92 
94  template <typename FilterType>
95  using ProcessModelType = typename FilterType::ProcessModel;
96 
98  template <DimensionType n> using Vector = Eigen::Matrix<Scalar, n, 1>;
99 
101  template <typename T> using DimVector = Vector<Dimension<T>::value>;
102 
104  template <DimensionType n>
106 
108  template <typename T>
110 
112  template <DimensionType n>
114 
116  template <typename T>
118 
120  template <DimensionType m, DimensionType n>
122 
124  template <typename T, typename U>
126 
127  } // namespace types
128 
133  template <typename StateType, typename ProcessModelType>
136  ProcessModelType &processModel, double dt) {
138  processModel.getStateTransitionMatrix(state, dt);
139  // OSVR_KALMAN_DEBUG_OUTPUT("State transition matrix", A);
140  types::DimSquareMatrix<StateType> P = state.errorCovariance();
144  // auto Q = processModel.getSampledProcessNoiseCovariance(dt);
145  OSVR_KALMAN_DEBUG_OUTPUT(
146  "Process Noise Covariance Q",
147  processModel.getSampledProcessNoiseCovariance(dt));
148  return A * P * A.transpose() +
149  processModel.getSampledProcessNoiseCovariance(dt);
150  }
151 
152 } // namespace kalman
153 } // namespace osvr
154 
155 #endif // INCLUDED_FlexibleKalmanBase_h_GUID_E4CC84A0_1B4F_4389_95ED_9C37F5FEE95D
Definition: FlexibleKalmanBase.h:57
types::DimSquareMatrix< StateType > predictErrorCovariance(StateType const &state, ProcessModelType &processModel, double dt)
Computes P-.
Definition: FlexibleKalmanBase.h:135
typename FilterType::State StateType
Given a filter type, get the state type.
Definition: FlexibleKalmanBase.h:91
std::integral_constant< DimensionType, n > DimensionConstant
Type constant for dimensions.
Definition: FlexibleKalmanBase.h:55
typename detail::Dimension_impl< T >::type Dimension
Given a state or measurement, get the dimension as a std::integral_constant.
Definition: FlexibleKalmanBase.h:87
Convenience base class for things (like states and measurements) that have a dimension.
Definition: FlexibleKalmanBase.h:63
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:135
Definition: TypeSafeIdHash.h:44
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
typename FilterType::ProcessModel ProcessModelType
Given a filter type, get the process model type.
Definition: FlexibleKalmanBase.h:95
Definition: newuoa.h:1888
Definition: FlexibleKalmanBase.h:69
std::size_t DimensionType
Type for dimensions.
Definition: FlexibleKalmanBase.h:51
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48