Monado OpenXR Runtime
Loading...
Searching...
No Matches
xrt_tracking.h
Go to the documentation of this file.
1// Copyright 2019, Collabora, Ltd.
2// Copyright 2025-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Header defining the tracking system integration in Monado.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup xrt_iface
9 */
10
11#pragma once
12
13#define XRT_TRACKING_NAME_LEN 256
14
15#define XRT_TRACKING_MAX_FRAME_SOURCES 8
16#define XRT_TRACKING_FOR_EACH_FRAME_SOURCE(_) _(0) _(1) _(2) _(3) _(4) _(5) _(6) _(7)
17
18#define XRT_TRACKING_MAX_IMUS 3
19#define XRT_TRACKING_FOR_EACH_IMU(_) _(0) _(1) _(2)
20
21#define XRT_TRACKING_MAX_MASK_SINKS 2
22#define XRT_TRACKING_FOR_EACH_MASK_SINK(_) _(0) _(1)
23
24#include "xrt/xrt_defines.h"
25
26#include "xrt/xrt_system.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32
33struct time_state;
34struct xrt_device;
35struct xrt_tracking;
37struct xrt_tracked_psmv;
38struct xrt_tracked_psvr;
39struct xrt_tracked_slam;
40
41//! @todo This is from u_time, duplicated to avoid layer violation.
42typedef int64_t timepoint_ns;
43
44/*!
45 * @addtogroup xrt_iface
46 * @{
47 */
48
49/*!
50 * What kind of tracking system is this.
51 *
52 * @todo Is none, Colour, IR, Magnetic the kind of type we need to know about?
53 */
55{
56 //! The device(s) are never tracked.
58
59 //! The device(s) are tracked by RGB camera(s).
61
62 //! The device(s) are tracked by Lighthouse.
64
65 //! The device(s) are tracked by magnetic fields, eg. Razer Hydra.
67
68 //! The device(s) are tracked by external SLAM
70
71 //! The device(s) are tracked through a constellation of lights as seen by cameras.
73
74 //! The device(s) are tracked by other methods.
76
77 //! The device(s) are (re)attachable.
79};
80
81/*!
82 * A unique identifier for an @ref xrt_tracking_origin instance.
83 *
84 * Each tracking origin is assigned a 64-bit ID in the Monado service process,
85 * or in the application process for in-process setups. For out-of-process
86 * clients the ID is synchronized over the IPC layer, so every client connected
87 * to the same service refers to a given tracking origin by the same value.
88 *
89 * The ID is intended for hash maps, caches, and similar lookups. Unlike a
90 * memory pointer it is never reused after the tracking origin is destroyed.
91 *
92 * A value of zero is invalid and means the tracking origin ID has not been
93 * assigned, matching the zero-initialized state of the struct.
94 */
96{
97 uint64_t val;
98};
99
100/*!
101 * Value of an @ref xrt_tracking_origin_id that has not been assigned.
102 *
103 * @relates xrt_tracking_origin_id
104 */
105// clang-format off
106#define XRT_TRACKING_ORIGIN_ID_INVALID XRT_C11_COMPOUND(struct xrt_tracking_origin_id){0}
107// clang-format on
108
109/*!
110 * A tracking system or device origin.
111 *
112 * Tracking systems will typically extend this structure.
113 */
115{
116 /*!
117 * Instance identifier, see @ref xrt_tracking_origin_id. Assigned by
118 * whatever allocates the tracking origin, normally the driver. Must be
119 * set before the tracking origin is handed to the rest of the system
120 * and not changed afterwards.
121 */
123
124 //! For debugging.
125 char name[XRT_TRACKING_NAME_LEN];
126
127 //! What can the state tracker expect from this tracking system.
129
130 /*!
131 * Read-only. Set once by the builder, or in some cases, the driver.
132 * With some systems, the offset may be changed at runtime using the space overseer.
133 */
135};
136
137/*!
138 * @interface xrt_tracking_factory
139 * Tracking factory.
140 */
142{
143 //! Internal frame context, exposed for debugging purposes.
145
146 /*!
147 * Create a tracked PSMV ball.
148 */
149 int (*create_tracked_psmv)(struct xrt_tracking_factory *, struct xrt_tracked_psmv **out_psmv);
150
151 /*!
152 * Create a tracked PSVR HMD.
153 */
154 int (*create_tracked_psvr)(struct xrt_tracking_factory *, struct xrt_tracked_psvr **out_psvr);
155
156
157
158 /*!
159 * Create a SLAM tracker.
160 */
161 int (*create_tracked_slam)(struct xrt_tracking_factory *, struct xrt_tracked_slam **out_slam);
162};
163
164/*!
165 * IMU Sample.
166 * @todo Replace with @ref xrt_imu_sample
167 */
169{
170 struct xrt_vec3 accel_m_s2;
171 struct xrt_vec3 gyro_rad_secs;
172};
173
174/*!
175 * IMU Sample.
176 * @todo Make @ref xrt_tracked_psmv and @ref xrt_tracked_psvr use this
177 */
179{
180 timepoint_ns timestamp_ns;
181 struct xrt_vec3_f64 accel_m_s2;
182 struct xrt_vec3_f64 gyro_rad_secs;
183};
184
185/*!
186 * Noise model and bias calibration of one IMU sensor, in that sensor's units (rad/s or m/s^2), called "unit" below.
187 */
189{
190 //! Noise density at rest, in unit/sqrt(Hz).
192 //! Noise density per unit of reading on the same axis, the scale factor error, in 1/sqrt(Hz).
194 //! Noise density per unit of reading on the other axes, the cross axis error, in 1/sqrt(Hz).
196 //! Reading past which an axis is saturated, in unit.
198 //! Noise density of a saturated axis, in unit/sqrt(Hz).
200 //! Bias random walk, in unit/sqrt(s).
202 //! Standard deviation of the bias before anything has been observed, in unit.
204};
205
206/*!
207 * IMU noise model and bias calibration, the noise density grows with the reading on each axis.
208 *
209 * @note This doesn't contain bias/scale itself,
210 * that should be applied by the drivers before sending to trackers.
211 */
213{
214 //! Gyroscope calibration, in rad/s.
216 //! Accelerometer calibration, in m/s^2.
218
219 //! Accelerometer scale random walk, in 1/sqrt(s).
221 //! Standard deviation of the accelerometer scale before anything has been observed, unitless.
223};
224
225/*!
226 * Pose sample.
227 */
229{
230 timepoint_ns timestamp_ns;
231 struct xrt_pose pose;
232};
233
234/*!
235 * Masks (bounding boxes) of different hands from current views
236 */
238{
240 {
242 {
243 bool enabled; //!< Whether a mask for this hand is being reported
244 struct xrt_rect_f32 rect; //!< The mask itself in pixel coordinates
245 } devices[XRT_SYSTEM_MAX_DEVICES];
246 } views[XRT_TRACKING_MAX_FRAME_SOURCES];
247};
248
249/*!
250 * @interface xrt_imu_sink
251 *
252 * An object to send IMU samples to.
253 *
254 * Similar to @ref xrt_frame_sink but the interface implementation must manage
255 * its own resources, not through a context graph.
256 *
257 * @todo Make @ref xrt_tracked_psmv and @ref xrt_tracked_psvr implement this
258 */
260{
261 /*!
262 * Push an IMU sample into the sink
263 */
264 void (*push_imu)(struct xrt_imu_sink *, struct xrt_imu_sample *sample);
265};
266
267/*!
268 * @interface xrt_pose_sink
269 *
270 * An object to send pairs of timestamps and poses to. @see xrt_imu_sink.
271 */
273{
274 void (*push_pose)(struct xrt_pose_sink *, struct xrt_pose_sample *sample);
275};
276
277/*!
278 * @interface xrt_device_masks_sink
279 *
280 * An object to push @ref xrt_device_masks_sample to.
281 */
283{
284 void (*push_device_masks)(struct xrt_device_masks_sink *, struct xrt_device_masks_sample *device_masks);
285};
286
287
288/*!
289 * Container of pointers to sinks that could be used for a SLAM system. Sinks
290 * are considered disabled if they are null.
291 */
293{
294 int cam_count;
295 int imu_count;
296 struct xrt_frame_sink *cams[XRT_TRACKING_MAX_FRAME_SOURCES];
297 struct xrt_imu_sink *imus[XRT_TRACKING_MAX_IMUS];
298 //! Can receive ground truth poses if available
300 //! SLAM masks, one per optical tracker (so they can push masks asynchronously).
301 struct xrt_device_masks_sink *masks[XRT_TRACKING_MAX_MASK_SINKS];
302};
303
304/*!
305 * @interface xrt_tracked_psmv
306 *
307 * A single tracked PS Move controller, camera and ball are not synced.
308 *
309 * @todo How do we communicate ball colour change?
310 */
312{
313 //! The tracking system origin for this ball.
315
316 //! Device owning this ball.
318
319 //! Colour of the ball.
321
322 /*!
323 * Push a IMU sample into the tracking system.
324 */
325 void (*push_imu)(struct xrt_tracked_psmv *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample);
326
327 /*!
328 * Called by the owning @ref xrt_device @ref xdev to get the pose of
329 * the ball in the tracking space at the given time.
330 *
331 * @todo Should we add a out_time argument as a way to signal min and
332 * maximum, and as such only do interpelation between different captured
333 * frames.
334 */
336 enum xrt_input_name name,
337 timepoint_ns when_ns,
338 struct xrt_space_relation *out_relation);
339
340 /*!
341 * Destroy this tracked ball.
342 */
343 void (*destroy)(struct xrt_tracked_psmv *);
344};
345
346/*!
347 * @interface xrt_tracked_psvr
348 *
349 * A tracked PSVR headset.
350 *
351 * @todo How do we communicate led lighting status?
352 */
354{
355 //! The tracking system origin for this ball.
357
358 //! Device owning this ball.
360
361 /*!
362 * Push a IMU sample into the tracking system.
363 */
364 void (*push_imu)(struct xrt_tracked_psvr *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample);
365
366 /*!
367 * Called by the owning @ref xrt_device @ref xdev to get the pose of
368 * the psvr in the tracking space at the given time.
369 */
371 timepoint_ns when_ns,
372 struct xrt_space_relation *out_relation);
373
374 /*!
375 * Destroy this tracked psvr.
376 */
377 void (*destroy)(struct xrt_tracked_psvr *);
378};
379
380/*!
381 * @interface xrt_tracked_slam
382 *
383 * An adapter that wraps an external SLAM tracker to provide SLAM tracking.
384 * Devices that want to be tracked through SLAM should create and manage an
385 * instance of this type.
386 */
388{
389 /*!
390 * Called by the owning @ref xrt_device to get the last estimated pose
391 * of the SLAM tracker.
392 */
394 timepoint_ns when_ns,
395 struct xrt_space_relation *out_relation);
396};
397
398/*
399 *
400 * Helper functions.
401 *
402 */
403
404//! @public @memberof xrt_imu_sink
405XRT_NONNULL_ALL static inline void
406xrt_sink_push_imu(struct xrt_imu_sink *sink, struct xrt_imu_sample *sample)
407{
408 sink->push_imu(sink, sample);
409}
410
411//! @public @memberof xrt_pose_sink
412XRT_NONNULL_ALL static inline void
413xrt_sink_push_pose(struct xrt_pose_sink *sink, struct xrt_pose_sample *sample)
414{
415 sink->push_pose(sink, sample);
416}
417
418//! @public @memberof xrt_device_masks_sink
419XRT_NONNULL_ALL static inline void
420xrt_sink_push_device_masks(struct xrt_device_masks_sink *sink, struct xrt_device_masks_sample *device_masks)
421{
422 sink->push_device_masks(sink, device_masks);
423}
424
425//! @public @memberof xrt_tracked_psmv
426XRT_NONNULL_ALL static inline void
427xrt_tracked_psmv_get_tracked_pose(struct xrt_tracked_psmv *psmv,
428 enum xrt_input_name name,
429 timepoint_ns when_ns,
430 struct xrt_space_relation *out_relation)
431{
432 psmv->get_tracked_pose(psmv, name, when_ns, out_relation);
433}
434
435//! @public @memberof xrt_tracked_psmv
436XRT_NONNULL_ALL static inline void
437xrt_tracked_psmv_push_imu(struct xrt_tracked_psmv *psmv, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
438{
439 psmv->push_imu(psmv, timestamp_ns, sample);
440}
441
442//! @public @memberof xrt_tracked_psmv
443XRT_NONNULL_ALL static inline void
444xrt_tracked_psmv_destroy(struct xrt_tracked_psmv **xtmv_ptr)
445{
446 struct xrt_tracked_psmv *xtmv = *xtmv_ptr;
447 if (xtmv == NULL) {
448 return;
449 }
450
451 xtmv->destroy(xtmv);
452 *xtmv_ptr = NULL;
453}
454
455//! @public @memberof xrt_tracked_psmv
456XRT_NONNULL_ALL static inline void
457xrt_tracked_psvr_get_tracked_pose(struct xrt_tracked_psvr *psvr,
458 timepoint_ns when_ns,
459 struct xrt_space_relation *out_relation)
460{
461 psvr->get_tracked_pose(psvr, when_ns, out_relation);
462}
463
464//! @public @memberof xrt_tracked_psmv
465XRT_NONNULL_ALL static inline void
466xrt_tracked_psvr_push_imu(struct xrt_tracked_psvr *psvr, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
467{
468 psvr->push_imu(psvr, timestamp_ns, sample);
469}
470
471//! @public @memberof xrt_tracked_psmv
472XRT_NONNULL_ALL static inline void
473xrt_tracked_psvr_destroy(struct xrt_tracked_psvr **xtvr_ptr)
474{
475 struct xrt_tracked_psvr *xtvr = *xtvr_ptr;
476 if (xtvr == NULL) {
477 return;
478 }
479
480 xtvr->destroy(xtvr);
481 *xtvr_ptr = NULL;
482}
483
484
485//! @public @memberof xrt_tracked_slam
486XRT_NONNULL_ALL static inline void
487xrt_tracked_slam_get_tracked_pose(struct xrt_tracked_slam *slam,
488 timepoint_ns when_ns,
489 struct xrt_space_relation *out_relation)
490{
491 slam->get_tracked_pose(slam, when_ns, out_relation);
492}
493
494/*!
495 * @}
496 */
497
498
499#ifdef __cplusplus
500}
501#endif
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition xrt_limits.h:26
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:1031
xrt_tracking_type
What kind of tracking system is this.
Definition xrt_tracking.h:55
@ XRT_TRACKING_TYPE_NONE
The device(s) are never tracked.
Definition xrt_tracking.h:57
@ XRT_TRACKING_TYPE_MAGNETIC
The device(s) are tracked by magnetic fields, eg. Razer Hydra.
Definition xrt_tracking.h:66
@ XRT_TRACKING_TYPE_CONSTELLATION
The device(s) are tracked through a constellation of lights as seen by cameras.
Definition xrt_tracking.h:72
@ XRT_TRACKING_TYPE_LIGHTHOUSE
The device(s) are tracked by Lighthouse.
Definition xrt_tracking.h:63
@ XRT_TRACKING_TYPE_RGB
The device(s) are tracked by RGB camera(s).
Definition xrt_tracking.h:60
@ XRT_TRACKING_TYPE_OTHER
The device(s) are tracked by other methods.
Definition xrt_tracking.h:75
@ XRT_TRACKING_TYPE_ATTACHABLE
The device(s) are (re)attachable.
Definition xrt_tracking.h:78
@ XRT_TRACKING_TYPE_EXTERNAL_SLAM
The device(s) are tracked by external SLAM.
Definition xrt_tracking.h:69
Time-keeping state structure.
Definition u_time.cpp:30
A 3 element colour with floating point channels.
Definition xrt_defines.h:441
bool enabled
Whether a mask for this hand is being reported.
Definition xrt_tracking.h:243
struct xrt_rect_f32 rect
The mask itself in pixel coordinates.
Definition xrt_tracking.h:244
Masks (bounding boxes) of different hands from current views.
Definition xrt_tracking.h:238
An object to push xrt_device_masks_sample to.
Definition xrt_tracking.h:283
A single HMD or input device.
Definition xrt_device.h:345
Object used to track all sinks and frame producers in a graph.
Definition xrt_frame.h:108
A object that is sent frames.
Definition xrt_frame.h:58
IMU noise model and bias calibration, the noise density grows with the reading on each axis.
Definition xrt_tracking.h:213
double accel_scale_initial_sigma
Standard deviation of the accelerometer scale before anything has been observed, unitless.
Definition xrt_tracking.h:222
double accel_scale_random_walk
Accelerometer scale random walk, in 1/sqrt(s).
Definition xrt_tracking.h:220
struct xrt_imu_sensor_calibration accel
Accelerometer calibration, in m/s^2.
Definition xrt_tracking.h:217
struct xrt_imu_sensor_calibration gyro
Gyroscope calibration, in rad/s.
Definition xrt_tracking.h:215
IMU Sample.
Definition xrt_tracking.h:179
Noise model and bias calibration of one IMU sensor, in that sensor's units (rad/s or m/s^2),...
Definition xrt_tracking.h:189
double scale_factor_noise_density
Noise density per unit of reading on the same axis, the scale factor error, in 1/sqrt(Hz).
Definition xrt_tracking.h:193
double axis_saturation
Reading past which an axis is saturated, in unit.
Definition xrt_tracking.h:197
double noise_density
Noise density at rest, in unit/sqrt(Hz).
Definition xrt_tracking.h:191
double bias_initial_sigma
Standard deviation of the bias before anything has been observed, in unit.
Definition xrt_tracking.h:203
double saturated_noise_density
Noise density of a saturated axis, in unit/sqrt(Hz).
Definition xrt_tracking.h:199
double cross_axis_noise_density
Noise density per unit of reading on the other axes, the cross axis error, in 1/sqrt(Hz).
Definition xrt_tracking.h:195
double bias_random_walk
Bias random walk, in unit/sqrt(s).
Definition xrt_tracking.h:201
An object to send IMU samples to.
Definition xrt_tracking.h:260
void(* push_imu)(struct xrt_imu_sink *, struct xrt_imu_sample *sample)
Push an IMU sample into the sink.
Definition xrt_tracking.h:264
Pose sample.
Definition xrt_tracking.h:229
An object to send pairs of timestamps and poses to.
Definition xrt_tracking.h:273
A pose composed of a position and orientation.
Definition xrt_defines.h:535
Image rectangle.
Definition xrt_defines.h:513
Container of pointers to sinks that could be used for a SLAM system.
Definition xrt_tracking.h:293
struct xrt_pose_sink * gt
Can receive ground truth poses if available.
Definition xrt_tracking.h:299
struct xrt_device_masks_sink * masks[2]
SLAM masks, one per optical tracker (so they can push masks asynchronously).
Definition xrt_tracking.h:301
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:726
A single tracked PS Move controller, camera and ball are not synced.
Definition xrt_tracking.h:312
void(* push_imu)(struct xrt_tracked_psmv *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
Push a IMU sample into the tracking system.
Definition xrt_tracking.h:325
struct xrt_device * xdev
Device owning this ball.
Definition xrt_tracking.h:317
void(* get_tracked_pose)(struct xrt_tracked_psmv *, enum xrt_input_name name, timepoint_ns when_ns, struct xrt_space_relation *out_relation)
Called by the owning xrt_device xdev to get the pose of the ball in the tracking space at the given t...
Definition xrt_tracking.h:335
void(* destroy)(struct xrt_tracked_psmv *)
Destroy this tracked ball.
Definition xrt_tracking.h:343
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition xrt_tracking.h:314
struct xrt_colour_rgb_f32 colour
Colour of the ball.
Definition xrt_tracking.h:320
A tracked PSVR headset.
Definition xrt_tracking.h:354
void(* get_tracked_pose)(struct xrt_tracked_psvr *, timepoint_ns when_ns, struct xrt_space_relation *out_relation)
Called by the owning xrt_device xdev to get the pose of the psvr in the tracking space at the given t...
Definition xrt_tracking.h:370
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition xrt_tracking.h:356
void(* destroy)(struct xrt_tracked_psvr *)
Destroy this tracked psvr.
Definition xrt_tracking.h:377
struct xrt_device * xdev
Device owning this ball.
Definition xrt_tracking.h:359
void(* push_imu)(struct xrt_tracked_psvr *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
Push a IMU sample into the tracking system.
Definition xrt_tracking.h:364
An adapter that wraps an external SLAM tracker to provide SLAM tracking.
Definition xrt_tracking.h:388
void(* get_tracked_pose)(struct xrt_tracked_slam *, timepoint_ns when_ns, struct xrt_space_relation *out_relation)
Called by the owning xrt_device to get the last estimated pose of the SLAM tracker.
Definition xrt_tracking.h:393
Tracking factory.
Definition xrt_tracking.h:142
int(* create_tracked_psmv)(struct xrt_tracking_factory *, struct xrt_tracked_psmv **out_psmv)
Create a tracked PSMV ball.
Definition xrt_tracking.h:149
struct xrt_frame_context * xfctx
Internal frame context, exposed for debugging purposes.
Definition xrt_tracking.h:144
int(* create_tracked_slam)(struct xrt_tracking_factory *, struct xrt_tracked_slam **out_slam)
Create a SLAM tracker.
Definition xrt_tracking.h:161
int(* create_tracked_psvr)(struct xrt_tracking_factory *, struct xrt_tracked_psvr **out_psvr)
Create a tracked PSVR HMD.
Definition xrt_tracking.h:154
A unique identifier for an xrt_tracking_origin instance.
Definition xrt_tracking.h:96
A tracking system or device origin.
Definition xrt_tracking.h:115
struct xrt_pose initial_offset
Read-only.
Definition xrt_tracking.h:134
struct xrt_tracking_origin_id id
Instance identifier, see xrt_tracking_origin_id.
Definition xrt_tracking.h:122
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition xrt_tracking.h:128
IMU Sample.
Definition xrt_tracking.h:169
A 3 element vector with single doubles.
Definition xrt_defines.h:335
A 3 element vector with single floats.
Definition xrt_defines.h:323
Common defines and enums for XRT.
Header for system objects.
int64_t timepoint_ns
Definition xrt_tracking.h:42