Monado OpenXR Runtime
m_imu_3dof.h
Go to the documentation of this file.
1 // Copyright 2013, Fredrik Hultin.
2 // Copyright 2013, Jakob Bornecrantz.
3 // Copyright 2020, Collabora, Ltd.
4 // SPDX-License-Identifier: BSL-1.0
5 /*!
6  * @file
7  * @brief A IMU fusion specially made for 3dof devices.
8  * @author Jakob Bornecrantz <jakob@collabora.com>
9  * @ingroup aux_math
10  */
11 
12 #pragma once
13 
14 #include "xrt/xrt_defines.h"
15 
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 
22 #define M_IMU_3DOF_USE_GRAVITY_DUR_300MS (1 << 0)
23 #define M_IMU_3DOF_USE_GRAVITY_DUR_20MS (1 << 1)
24 
25 
26 struct m_ff_vec3_f32;
27 
28 enum m_imu_3dof_state
29 {
30  M_IMU_3DOF_STATE_START = 0,
31  M_IMU_3DOF_STATE_RUNNING = 1,
32 };
33 
34 struct m_imu_3dof
35 {
36  struct xrt_quat rot; //!< Orientation
37 
38  struct
39  {
40  uint64_t timepoint_ns;
41  struct xrt_vec3 gyro; //!< Angular velocity
42  struct xrt_vec3 accel; //!< Acceleration
43  float delta_ms;
44  } last;
45 
46  enum m_imu_3dof_state state;
47 
48  int flags;
49 
50  // Filter fifos for accelerometer and gyroscope.
51  struct m_ff_vec3_f32 *word_accel_ff;
52  struct m_ff_vec3_f32 *gyro_ff;
53 
54  // gravity correction
55  struct
56  {
57  uint64_t level_timepoint_ns;
58  struct xrt_vec3 error_axis;
59  float error_angle;
60  } grav;
61 };
62 
63 void
64 m_imu_3dof_init(struct m_imu_3dof *f, int flags);
65 
66 void
67 m_imu_3dof_close(struct m_imu_3dof *f);
68 
69 void
71  uint64_t timepoint_ns,
72  const struct xrt_vec3 *accel,
73  const struct xrt_vec3 *gyro);
74 
75 
76 #ifdef __cplusplus
77 }
78 #endif
A 3 element vector with single floats.
Definition: xrt_defines.h:131
Definition: m_filter_fifo.c:16
A quaternion with single floats.
Definition: xrt_defines.h:97
struct xrt_vec3 gyro
Angular velocity.
Definition: m_imu_3dof.h:41
struct xrt_quat rot
Orientation.
Definition: m_imu_3dof.h:36
Common defines and enums for XRT.
int64_t timepoint_ns
Integer timestamp type.
Definition: u_time.h:34
struct xrt_vec3 accel
Acceleration.
Definition: m_imu_3dof.h:42
Definition: m_imu_3dof.h:34
void m_imu_3dof_update(struct m_imu_3dof *f, uint64_t timepoint_ns, const struct xrt_vec3 *accel, const struct xrt_vec3 *gyro)
Definition: m_imu_3dof.c:147