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
18extern "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
26struct m_ff_vec3_f32;
27
28enum m_imu_3dof_state
29{
30 M_IMU_3DOF_STATE_START = 0,
31 M_IMU_3DOF_STATE_RUNNING = 1,
32};
33
35{
36 struct xrt_quat rot; //!< Orientation
37
38 struct
39 {
40 uint64_t timestamp_ns;
41 struct xrt_vec3 gyro; //!< Angular velocity
42 struct xrt_vec3 accel; //!< Acceleration
43 double delta_ms;
44 float accel_length;
45 float gyro_length;
46 float gyro_biased_length;
47 } last;
48
49 enum m_imu_3dof_state state;
50
51 int flags;
52
53 // Filter fifos for accelerometer and gyroscope.
54 struct m_ff_vec3_f32 *word_accel_ff;
55 struct m_ff_vec3_f32 *gyro_ff;
56
57 // gravity correction
58 struct
59 {
60 uint64_t level_timestamp_ns;
61 struct xrt_vec3 error_axis;
62 float error_angle;
63 bool is_accel;
64 bool is_rotating;
65 } grav;
66
67 // gyro bias correction
68 struct
69 {
70 struct xrt_vec3 value;
71 bool manually_fire;
72 } gyro_bias;
73};
74
75void
76m_imu_3dof_init(struct m_imu_3dof *f, int flags);
77
78void
79m_imu_3dof_reset(struct m_imu_3dof *f);
80
81void
82m_imu_3dof_close(struct m_imu_3dof *f);
83
84void
85m_imu_3dof_add_vars(struct m_imu_3dof *f, void *root, const char *prefix);
86
87void
89 uint64_t timestamp_ns,
90 const struct xrt_vec3 *accel,
91 const struct xrt_vec3 *gyro);
92
93
94#ifdef __cplusplus
95}
96#endif
void m_imu_3dof_update(struct m_imu_3dof *f, uint64_t timestamp_ns, const struct xrt_vec3 *accel, const struct xrt_vec3 *gyro)
Definition: m_imu_3dof.c:230
Definition: m_space.cpp:87
Definition: m_filter_fifo.c:23
Definition: m_imu_3dof.h:35
struct xrt_quat rot
Orientation.
Definition: m_imu_3dof.h:36
struct xrt_vec3 accel
Acceleration.
Definition: m_imu_3dof.h:42
struct xrt_vec3 gyro
Angular velocity.
Definition: m_imu_3dof.h:41
A quaternion with single floats.
Definition: xrt_defines.h:216
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Common defines and enums for XRT.