OSVR-Core
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 
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>
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>
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 =
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
typename detail::Dimension_impl< T >::type Dimension
Given a state or measurement, get the dimension as a std::integral_constant.
Definition: FlexibleKalmanBase.h:87
StateTypeA const & a() const
Access the first part of the state.
Definition: AugmentedState.h:113
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
AugmentedState(AugmentedState &&other)
Move constructor.
Definition: AugmentedState.h:62
AugmentedState(StateA &a, StateB &b)
Constructor.
Definition: AugmentedState.h:56
State type that consists entirely of references to two independent sub-states.
Definition: AugmentedState.h:41
void setStateVector(Eigen::MatrixBase< Derived > const &state)
Definition: AugmentedState.h:70
StateTypeB const & b() const
Access the second part of the state.
Definition: AugmentedState.h:118
StateTypeB & b()
Access the second part of the state.
Definition: AugmentedState.h:116
void setErrorCovariance(Eigen::MatrixBase< Derived > const &P)
Definition: AugmentedState.h:92
AugmentedState & operator=(AugmentedState const &other)=delete
non-assignable
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
DeducedAugmentedState< StateA, StateB > makeAugmentedState(StateA &a, StateB &b)
Factory function, akin to std::tie(), to make an augmented state.
Definition: AugmentedState.h:134
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48