OSVR-Core
AbsoluteOrientationMeasurement.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_AbsoluteOrientationMeasurement_h_GUID_71285DD8_A6F1_47A8_4B2E_B10171C91248
26 #define INCLUDED_AbsoluteOrientationMeasurement_h_GUID_71285DD8_A6F1_47A8_4B2E_B10171C91248
27 
28 // Internal Includes
29 #include "ExternalQuaternion.h"
30 #include "FlexibleKalmanBase.h"
31 #include "PoseState.h"
34 
35 // Library/third-party includes
36 // - none
37 
38 // Standard includes
39 // - none
40 
41 namespace osvr {
42 namespace kalman {
47  public:
48  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
49  static const types::DimensionType DIMENSION = 3;
53  types::Vector<3> const &emVariance)
54  : m_quat(quat), m_covariance(emVariance.asDiagonal()) {}
55 
56  template <typename State>
57  MeasurementSquareMatrix const &getCovariance(State const &) {
58  return m_covariance;
59  }
60 
67  template <typename State>
69  const Eigen::Quaterniond prediction = s.getCombinedQuaternion();
70  const Eigen::Quaterniond residualq = m_quat * prediction.inverse();
71  // Two equivalent quaternions: but their logs are typically
72  // different: one is the "short way" and the other is the "long
73  // way". We'll compute both and pick the "short way".
74  MeasurementVector residual = util::quat_exp_map(residualq).ln();
75  MeasurementVector equivResidual =
76  util::quat_exp_map(Eigen::Quaterniond(-(residualq.coeffs())))
77  .ln();
78  return residual.squaredNorm() < equivResidual.squaredNorm()
79  ? residual
80  : equivResidual;
81  }
83  void setMeasurement(Eigen::Quaterniond const &quat) { m_quat = quat; }
84 
88  return Eigen::Matrix3d::Identity();
89  }
90 
91  private:
92  Eigen::Quaterniond m_quat;
93  MeasurementSquareMatrix m_covariance;
94  };
95 
98  template <typename StateType> class AbsoluteOrientationMeasurement;
99 
101  template <>
102  class AbsoluteOrientationMeasurement<pose_externalized_rotation::State>
103  : public AbsoluteOrientationBase {
104  public:
106  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
107  static const types::DimensionType STATE_DIMENSION =
110 
112  types::Vector<3> const &eulerVariance)
113  : Base(quat, eulerVariance) {}
114 
116  getJacobian(State const &s) const {
117  using namespace pose_externalized_rotation;
119  Jacobian ret = Jacobian::Zero();
120  ret.block<DIMENSION, 3>(0, 3) = Base::getJacobianBlock();
121  return ret;
122  }
123  };
124 } // namespace kalman
125 } // namespace osvr
126 #endif // INCLUDED_AbsoluteOrientationMeasurement_h_GUID_71285DD8_A6F1_47A8_4B2E_B10171C91248
typename detail::Dimension_impl< T >::type Dimension
Given a state or measurement, get the dimension as a std::integral_constant.
Definition: FlexibleKalmanBase.h:87
const Coefficients & coeffs() const
Definition: Quaternion.h:93
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
void setMeasurement(Eigen::Quaterniond const &quat)
Convenience method to be able to store and re-use measurements.
Definition: AbsoluteOrientationMeasurement.h:83
types::Matrix< DIMENSION, 3 > getJacobianBlock() const
Get the block of jacobian that is non-zero: your subclass will have to put it where it belongs for ea...
Definition: AbsoluteOrientationMeasurement.h:87
Header.
This is the subclass of AbsoluteOrientationBase: only explicit specializations, and on state types...
Definition: AbsoluteOrientationMeasurement.h:98
Definition: Quaternion.h:47
The measurement here has been split into a base and derived type, so that the derived type only conta...
Definition: AbsoluteOrientationMeasurement.h:46
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
MeasurementVector getResidual(State const &s) const
Gets the measurement residual, also known as innovation: predicts the measurement from the predicted ...
Definition: AbsoluteOrientationMeasurement.h:68
Eigen::Quaterniond getCombinedQuaternion() const
Definition: PoseState.h:238
Quaternion inverse(void) const
Definition: Quaternion.h:375