OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
AugmentedState.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_AugmentedState_h_GUID_7A7BD6AE_F672_4096_679B_D5BB21D42445
26 #define INCLUDED_AugmentedState_h_GUID_7A7BD6AE_F672_4096_679B_D5BB21D42445
27 
28 // Internal Includes
29 #include "FlexibleKalmanBase.h"
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <type_traits>
36 
37 namespace osvr {
38 namespace kalman {
41  template <typename StateA, typename StateB> class AugmentedState {
42  public:
43  using StateTypeA = StateA;
44  using StateTypeB = StateB;
45 
46  static const types::DimensionType DIM_A =
48  static const types::DimensionType DIM_B =
50  static const types::DimensionType DIMENSION = DIM_A + DIM_B;
51 
52  using SquareMatrix = types::SquareMatrix<DIMENSION>;
53  using StateVector = types::Vector<DIMENSION>;
54 
56  AugmentedState(StateA &a, StateB &b) : a_(a), b_(b) {}
57 
59  AugmentedState(AugmentedState const &other) = default;
60 
62  AugmentedState(AugmentedState &&other) : a_(other.a_), b_(other.b_) {}
63 
65  AugmentedState &operator=(AugmentedState const &other) = delete;
66 
69  template <typename Derived>
70  void setStateVector(Eigen::MatrixBase<Derived> const &state) {
72  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, DIMENSION);
73  a().setStateVector(state.derived().template head<DIM_A>());
74  b().setStateVector(state.derived().template tail<DIM_B>());
75  }
76 
77  StateVector stateVector() const {
78  StateVector ret;
79  ret << a().stateVector(), b().stateVector();
80  return ret;
81  }
82 
83  SquareMatrix errorCovariance() const {
84  SquareMatrix ret = SquareMatrix::Zero();
85  ret.template topLeftCorner<DIM_A, DIM_A>() = a().errorCovariance();
86  ret.template bottomRightCorner<DIM_B, DIM_B>() =
87  b().errorCovariance();
88  return ret;
89  }
90 
91  template <typename Derived>
92  void setErrorCovariance(Eigen::MatrixBase<Derived> const &P) {
95  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, DIMENSION,
96  DIMENSION);
97  a().setErrorCovariance(P.template topLeftCorner<DIM_A, DIM_A>());
98  b().setErrorCovariance(
99  P.template bottomRightCorner<DIM_B, DIM_B>());
100  }
101 
102  void postCorrect() {
103  a().postCorrect();
104  b().postCorrect();
105  }
107 
111  StateTypeA &a() { return a_; }
113  StateTypeA const &a() const { return a_; }
114 
116  StateTypeB &b() { return b_; }
118  StateTypeB const &b() const { return b_; }
120 
121  private:
122  StateA &a_;
123  StateB &b_;
124  };
127  template <typename StateA, typename StateB>
128  using DeducedAugmentedState =
129  AugmentedState<typename std::remove_const<StateA>::type,
130  typename std::remove_const<StateB>::type>;
131 
133  template <typename StateA, typename StateB>
135  StateB &b) {
137  }
138 
139 } // namespace kalman
140 } // namespace osvr
141 
142 #endif // INCLUDED_AugmentedState_h_GUID_7A7BD6AE_F672_4096_679B_D5BB21D42445
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
StateTypeB const & b() const
Access the second part of the state.
typename detail::Dimension_impl< T >::type Dimension
Eigen::Matrix< Scalar, n, n > SquareMatrix
A square matrix, n x n.
The main namespace for all C++ elements of the framework, internal and external.
Definition: ClientKit.h:31
AugmentedState< typename std::remove_const< StateA >::type, typename std::remove_const< StateB >::type > DeducedAugmentedState
AugmentedState(AugmentedState &&other)
Move constructor.
AugmentedState(StateA &a, StateB &b)
Constructor.
StateTypeA const & a() const
Access the first part of the state.
void setStateVector(Eigen::MatrixBase< Derived > const &state)
StateTypeB & b()
Access the second part of the state.
void setErrorCovariance(Eigen::MatrixBase< Derived > const &P)
AugmentedState & operator=(AugmentedState const &other)=delete
non-assignable
std::size_t DimensionType
Type for dimensions.
DeducedAugmentedState< StateA, StateB > makeAugmentedState(StateA &a, StateB &b)
Factory function, akin to std::tie(), to make an augmented state.