OSVR-Core
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 =
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 
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)
Definition: ProcessIMUMessage.h:62
apply_list< quote< or_ >, transform< Haystack, detail::is_< Needle >>> contains
Determines if type Needle is in the list Haystack - is an alias for a type that inherits std::true_ty...
Definition: Contains.h:49
void updatePoseFromOrientation(util::time::TimeValue const &tv, Eigen::Quaterniond const &quat)
Processes an orientation.
Definition: TrackedBodyIMU.cpp:49
OSVR_AngularVelocityState state
The state itself.
Definition: ClientReportTypesC.h:191
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
typepack::contains< TimestampedReports, Report > is_timestamped_report
Alias to determine if a class is in fact a "Timestamped Report" type.
Definition: ProcessIMUMessage.h:48
Definition: newuoa.h:1888
void updatePoseFromAngularVelocity(util::time::TimeValue const &tv, Eigen::Quaterniond const &deltaquat, double dt)
Processes an angular velocity.
Definition: TrackedBodyIMU.cpp:82
Report type for an orientation callback on a tracker interface.
Definition: ClientReportTypesC.h:145
Definition: TrackedBodyIMU.h:44
void operator()(boost::none_t const &) const
Definition: ProcessIMUMessage.h:56
Implementation detail of unpacking and handling the IMU messages.
Definition: ProcessIMUMessage.h:51
Header for interoperation between the Eigen math library, the internal mini math library, and VRPN&#39;s quatlib.
boost::variant< boost::none_t, TimestampedOrientation, TimestampedAngVel > IMUMessage
A "typesafe tagged-union" variant that can hold an IMU report data along with the timestamp and the p...
Definition: IMUMessage.h:93
Report type for an angular velocity callback on a tracker interface.
Definition: ClientReportTypesC.h:187
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.
Definition: ClientReportTypesC.h:149
Header.
Header.