OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ProcessIMUMessage.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_ProcessIMUMessage_h_GUID_9F00FD7F_C068_4DB1_61C8_42317D1CF786
26 #define INCLUDED_ProcessIMUMessage_h_GUID_9F00FD7F_C068_4DB1_61C8_42317D1CF786
27 
28 // Internal Includes
29 #include "IMUMessage.h"
30 #include "TrackedBody.h"
31 #include "TrackedBodyIMU.h"
32 
33 // Library/third-party includes
34 #include <osvr/TypePack/Contains.h>
35 #include <osvr/Util/EigenInterop.h>
36 
37 // Standard includes
38 #include <type_traits>
39 
40 namespace osvr {
41 namespace vbtracker {
42  namespace detail {
43 
46  template <typename Report>
47  using is_timestamped_report =
48  typepack::contains<TimestampedReports, Report>;
49 
51  class IMUMessageProcessor : public boost::static_visitor<> {
52  public:
53  BodyId bodyId;
54  ImuMessageCategory messageType = ImuMessageCategory::Empty;
55 
56  void operator()(boost::none_t const &) const {
58  }
59 
60  template <typename Report>
61  typename std::enable_if<is_timestamped_report<Report>::value>::type
62  operator()(Report const &report) {
65  bodyId = report.imu().getBody().getId();
66 
68  updatePose(report.imu(), report.timestamp, report.data);
69  }
70 
71  void updatePose(TrackedBodyIMU &imu,
72  util::time::TimeValue const &timestamp,
73  OSVR_OrientationReport const &ori) {
74  messageType = ImuMessageCategory::Orientation;
76  timestamp, util::eigen_interop::map(ori.rotation).quat());
77  }
78 
79  void updatePose(TrackedBodyIMU &imu,
80  util::time::TimeValue const &timestamp,
81  OSVR_AngularVelocityReport const &angVel) {
82  messageType = ImuMessageCategory::AngularVelocity;
84  timestamp,
85  util::eigen_interop::map(angVel.state.incrementalRotation)
86  .quat(),
87  angVel.state.dt);
88  }
89  };
90  } // namespace detail
91  inline std::pair<BodyId, ImuMessageCategory>
92  processImuMessage(IMUMessage const &m) {
93 
94  detail::IMUMessageProcessor processor;
95  boost::apply_visitor(processor, m);
96  return std::make_pair(processor.bodyId, processor.messageType);
97  }
98 } // namespace vbtracker
99 } // namespace osvr
100 #endif // INCLUDED_ProcessIMUMessage_h_GUID_9F00FD7F_C068_4DB1_61C8_42317D1CF786
std::enable_if< is_timestamped_report< Report >::value >::type operator()(Report const &report)
void updatePoseFromOrientation(util::time::TimeValue const &tv, Eigen::Quaterniond const &quat)
Processes an orientation.
OSVR_AngularVelocityState state
The state itself.
void updatePoseFromAngularVelocity(util::time::TimeValue const &tv, Eigen::Quaterniond const &deltaquat, double dt)
Processes an angular velocity.
Report type for an orientation callback on a tracker interface.
void operator()(boost::none_t const &) const
Implementation detail of unpacking and handling the IMU messages.
Header for interoperation between the Eigen math library, the internal mini math library, and VRPN's quatlib.
Report type for an angular velocity callback on a tracker interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
OSVR_OrientationState rotation
The rotation unit quaternion.
Header.
Header.