OSVR-Core
CannedIMUMeasurement.h
Go to the documentation of this file.
1 
11 // Copyright 2016 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_CannedIMUMeasurement_h_GUID_98C6C454_C977_4081_2065_A89E6A62C8FA
26 #define INCLUDED_CannedIMUMeasurement_h_GUID_98C6C454_C977_4081_2065_A89E6A62C8FA
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <boost/assert.hpp>
33 #include <osvr/Util/Angles.h>
35 
36 // Standard includes
37 #include <array>
38 
39 namespace osvr {
40 namespace vbtracker {
41 
45  public:
46  void setYawCorrection(util::Angle y) { m_yawCorrection = y; }
47  util::Angle getYawCorrection() const { return m_yawCorrection; }
48  void setOrientation(Eigen::Quaterniond const &quat,
49  Eigen::Vector3d const &variance) {
50  Eigen::Vector4d::Map(m_quat.data()) = quat.coeffs();
51  Eigen::Vector3d::Map(m_quatVar.data()) = variance;
52  m_orientationValid = true;
53  }
54  bool orientationValid() const { return m_orientationValid; }
55 
56  void restoreQuat(Eigen::Quaterniond &quat) const {
57  BOOST_ASSERT_MSG(
58  orientationValid(),
59  "restoring quat on an invalid orientation measurement!");
60  quat.coeffs() = Eigen::Vector4d::Map(m_quat.data());
61  }
62 
63  void restoreQuatVariance(Eigen::Vector3d &var) const {
64  BOOST_ASSERT_MSG(orientationValid(), "restoring quat variance on "
65  "an invalid orientation "
66  "measurement!");
67  var = Eigen::Vector3d::Map(m_quatVar.data());
68  }
69 
70  void setAngVel(Eigen::Vector3d const &angVel,
71  Eigen::Vector3d const &variance) {
72  Eigen::Vector3d::Map(m_angVel.data()) = angVel;
73  Eigen::Vector3d::Map(m_angVelVar.data()) = variance;
74  m_angVelValid = true;
75  }
76 
77  bool angVelValid() const { return m_angVelValid; }
78  void restoreAngVel(Eigen::Vector3d &angVel) const {
79  BOOST_ASSERT_MSG(angVelValid(), "restoring ang vel on "
80  "an invalid ang vel "
81  "measurement!");
82  angVel = Eigen::Vector3d::Map(m_angVel.data());
83  }
84  void restoreAngVelVariance(Eigen::Vector3d &var) const {
85  BOOST_ASSERT_MSG(angVelValid(), "restoring ang vel variance on "
86  "an invalid ang vel "
87  "measurement!");
88  var = Eigen::Vector3d::Map(m_angVelVar.data());
89  }
90 
91  private:
92  util::Angle m_yawCorrection = 0;
93  bool m_orientationValid = false;
94  std::array<double, 4> m_quat;
95  std::array<double, 3> m_quatVar;
96  bool m_angVelValid = false;
97  std::array<double, 3> m_angVel;
98  std::array<double, 3> m_angVelVar;
99  };
100 } // namespace vbtracker
101 } // namespace osvr
102 #endif // INCLUDED_CannedIMUMeasurement_h_GUID_98C6C454_C977_4081_2065_A89E6A62C8FA
AngleRadiansd Angle
Default angle type.
Definition: Angles.h:63
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.
A safe way to store and transport an orientation measurement or an angular velocity measurement witho...
Definition: CannedIMUMeasurement.h:44
Definition: Quaternion.h:47
Header.