OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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;
50  using MeasurementVector = types::Vector<DIMENSION>;
51  using MeasurementSquareMatrix = types::SquareMatrix<DIMENSION>;
52  AbsoluteOrientationBase(Eigen::Quaterniond const &quat,
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>
68  MeasurementVector getResidual(State const &s) const {
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:
105  using State = pose_externalized_rotation::State;
106  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
107  static const types::DimensionType STATE_DIMENSION =
110 
111  AbsoluteOrientationMeasurement(Eigen::Quaterniond const &quat,
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
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
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
types::Matrix< DIMENSION, 3 > getJacobianBlock() const
Header wrapping include of and for warning quieting.
void setMeasurement(Eigen::Quaterniond const &quat)
Convenience method to be able to store and re-use measurements.
Header.
std::size_t DimensionType
Type for dimensions.
MeasurementVector getResidual(State const &s) const
Eigen::Matrix< Scalar, m, n > Matrix
A matrix with rows = m, cols = n.