Monado OpenXR Runtime
t_imu.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief C interface to basic IMU fusion.
6  * @author Ryan Pavlik <ryan.pavlik@collabora.com>
7  * @ingroup aux_tracking
8  */
9 
10 #include "math/m_api.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 
17 /*!
18  * Opaque type for fusing IMU reports.
19  */
20 struct imu_fusion;
21 
22 /*!
23  * Create a struct imu_fusion.
24  *
25  * @public @memberof imu_fusion
26  * @ingroup aux_tracking
27  */
28 struct imu_fusion *
30 
31 
32 /*!
33  * Destroy a struct imu_fusion.
34  *
35  * Should not be called simultaneously with any other imu_fusion function.
36  *
37  * @param fusion The IMU Fusion object
38  *
39  * @public @memberof imu_fusion
40  * @ingroup aux_tracking
41  */
42 void
43 imu_fusion_destroy(struct imu_fusion *fusion);
44 
45 /*!
46  * Predict and correct fusion with a gyroscope reading.
47  *
48  * dt should not be zero: If you're receiving accel and gyro data at the same
49  * time, call imu_fusion_incorporate_gyros_and_accelerometer() instead.
50  *
51  * Should not be called simultaneously with any other imu_fusion function.
52  *
53  * Non-zero return means error.
54  *
55  * @param fusion The IMU Fusion object
56  * @param timestamp_ns The timestamp corresponding to the information being
57  * processed with this call.
58  * @param ang_vel Angular velocity vector from gyroscope: in radians per second.
59  * @param ang_vel_variance The variance of the angular velocity measurements:
60  * part of the characteristics of the IMU being used.
61  *
62  * @public @memberof imu_fusion
63  * @ingroup aux_tracking
64  */
65 int
67  uint64_t timestamp_ns,
68  struct xrt_vec3 const *ang_vel,
69  struct xrt_vec3 const *ang_vel_variance);
70 
71 /*!
72  * Predict and correct fusion with an accelerometer reading.
73  *
74  * If you're receiving accel and gyro data at the same time, call
75  * imu_fusion_incorporate_gyros_and_accelerometer() instead.
76  *
77  * Should not be called simultaneously with any other imu_fusion function.
78  *
79  * Non-zero return means error.
80  *
81  * @param fusion The IMU Fusion object
82  * @param timestamp_ns The timestamp corresponding to the information being
83  * processed with this call.
84  * @param accel Accelerometer data (in m/s/s) including the effect of gravity -
85  * assumed to be +y when aligned with the world.
86  * @param accel_variance The variance of the accelerometer measurements: part of
87  * the characteristics of the IMU being used.
88  * @param out_world_accel Optional output parameter: will contain the
89  * non-gravity acceleration in the world frame.
90  *
91  * @public @memberof imu_fusion
92  * @ingroup aux_tracking
93  */
94 int
96  uint64_t timestamp_ns,
97  struct xrt_vec3 const *accel,
98  struct xrt_vec3 const *accel_variance,
99  struct xrt_vec3 *out_world_accel);
100 
101 /*!
102  * Predict and correct fusion with a simultaneous accelerometer and gyroscope
103  * reading.
104  *
105  * Should not be called simultaneously with any other imu_fusion function.
106  *
107  * Non-zero return means error.
108  *
109  * @param fusion The IMU Fusion object
110  * @param timestamp_ns The timestamp corresponding to the information being
111  * processed with this call.
112  * @param ang_vel Angular velocity vector from gyroscope: radians/s
113  * @param ang_vel_variance The variance of the angular velocity measurements:
114  * part of the characteristics of the IMU being used.
115  * @param accel Accelerometer data (in m/s/s) including the effect of gravity -
116  * assumed to be +y when aligned with the world.
117  * @param accel_variance The variance of the accelerometer measurements: part of
118  * the characteristics of the IMU being used.
119  * @param out_world_accel Optional output parameter: will contain the
120  * non-gravity acceleration in the world frame.
121  *
122  * @public @memberof imu_fusion
123  * @ingroup aux_tracking
124  */
125 int
127  struct imu_fusion *fusion,
128  uint64_t timestamp_ns,
129  struct xrt_vec3 const *ang_vel,
130  struct xrt_vec3 const *ang_vel_variance,
131  struct xrt_vec3 const *accel,
132  struct xrt_vec3 const *accel_variance,
133  struct xrt_vec3 *out_world_accel);
134 
135 /*!
136  * Get the predicted state. Does not advance the internal state clock.
137  *
138  * Non-zero return means error.
139  *
140  * @param fusion The IMU Fusion object
141  * @param timestamp_ns The timestamp corresponding to the predicted state you
142  * want.
143  * @param out_quat The quaternion to populate with the predicted orientation.
144  * @param out_ang_vel The vector to poluate with the predicted angular velocity.
145  *
146  * @public @memberof imu_fusion
147  * @ingroup aux_tracking
148  */
149 int
150 imu_fusion_get_prediction(struct imu_fusion const *fusion,
151  uint64_t timestamp_ns,
152  struct xrt_quat *out_quat,
153  struct xrt_vec3 *out_ang_vel);
154 
155 
156 /*!
157  * Get the predicted state as a rotation vector. Does not advance the internal
158  * state clock.
159  *
160  * This is mostly for debugging: a rotation vector can be easier to visualize or
161  * understand intuitively.
162  *
163  * Non-zero return means error.
164  *
165  * @param fusion The IMU Fusion object
166  * @param timestamp_ns The timestamp corresponding to the predicted state you
167  * want.
168  * @param out_rotation_vec The vector to poluate with the predicted orientation
169  * rotation vector.
170  *
171  * @public @memberof imu_fusion
172  * @ingroup aux_tracking
173  */
174 int
176  uint64_t timestamp_ns,
177  struct xrt_vec3 *out_rotation_vec);
178 
179 
180 #ifdef __cplusplus
181 }
182 #endif
struct imu_fusion * imu_fusion_create()
Create a struct imu_fusion.
Definition: t_imu.cpp:36
A 3 element vector with single floats.
Definition: xrt_defines.h:133
int imu_fusion_incorporate_gyros(struct imu_fusion *fusion, uint64_t timestamp_ns, struct xrt_vec3 const *ang_vel, struct xrt_vec3 const *ang_vel_variance)
Predict and correct fusion with a gyroscope reading.
Definition: t_imu.cpp:56
int imu_fusion_get_prediction_rotation_vec(struct imu_fusion const *fusion, uint64_t timestamp_ns, struct xrt_vec3 *out_rotation_vec)
Get the predicted state as a rotation vector.
Definition: t_imu.cpp:140
A quaternion with single floats.
Definition: xrt_defines.h:99
int imu_fusion_incorporate_gyros_and_accelerometer(struct imu_fusion *fusion, uint64_t timestamp_ns, struct xrt_vec3 const *ang_vel, struct xrt_vec3 const *ang_vel_variance, struct xrt_vec3 const *accel, struct xrt_vec3 const *accel_variance, struct xrt_vec3 *out_world_accel)
Predict and correct fusion with a simultaneous accelerometer and gyroscope reading.
Definition: t_imu.cpp:173
void imu_fusion_destroy(struct imu_fusion *fusion)
Destroy a struct imu_fusion.
Definition: t_imu.cpp:47
Definition: t_imu.cpp:20
int imu_fusion_get_prediction(struct imu_fusion const *fusion, uint64_t timestamp_ns, struct xrt_quat *out_quat, struct xrt_vec3 *out_ang_vel)
Get the predicted state.
Definition: t_imu.cpp:105
int imu_fusion_incorporate_accelerometer(struct imu_fusion *fusion, uint64_t timestamp_ns, struct xrt_vec3 const *accel, struct xrt_vec3 const *accel_variance, struct xrt_vec3 *out_world_accel)
Predict and correct fusion with an accelerometer reading.
Definition: t_imu.cpp:77
C interface to math library.