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_CAMS 8
16#define XRT_TRACKING_FOR_EACH_CAM(_) _(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 tracking system or device origin.
83 *
84 * Tracking systems will typically extend this structure.
85 */
87{
88 //! For debugging.
89 char name[XRT_TRACKING_NAME_LEN];
90
91 //! What can the state tracker expect from this tracking system.
93
94 /*!
95 * Read-only. Set once by the builder, or in some cases, the driver.
96 * With some systems, the offset may be changed at runtime using the space overseer.
97 */
99};
100
101/*!
102 * @interface xrt_tracking_factory
103 * Tracking factory.
104 */
106{
107 //! Internal frame context, exposed for debugging purposes.
109
110 /*!
111 * Create a tracked PSMV ball.
112 */
113 int (*create_tracked_psmv)(struct xrt_tracking_factory *, struct xrt_tracked_psmv **out_psmv);
114
115 /*!
116 * Create a tracked PSVR HMD.
117 */
118 int (*create_tracked_psvr)(struct xrt_tracking_factory *, struct xrt_tracked_psvr **out_psvr);
119
120
121
122 /*!
123 * Create a SLAM tracker.
124 */
125 int (*create_tracked_slam)(struct xrt_tracking_factory *, struct xrt_tracked_slam **out_slam);
126};
127
128/*!
129 * IMU Sample.
130 * @todo Replace with @ref xrt_imu_sample
131 */
133{
134 struct xrt_vec3 accel_m_s2;
135 struct xrt_vec3 gyro_rad_secs;
136};
137
138/*!
139 * IMU Sample.
140 * @todo Make @ref xrt_tracked_psmv and @ref xrt_tracked_psvr use this
141 */
143{
144 timepoint_ns timestamp_ns;
145 struct xrt_vec3_f64 accel_m_s2;
146 struct xrt_vec3_f64 gyro_rad_secs;
147};
148
149/*!
150 * Pose sample.
151 */
153{
154 timepoint_ns timestamp_ns;
155 struct xrt_pose pose;
156};
157
158/*!
159 * Masks (bounding boxes) of different hands from current views
160 */
162{
164 {
166 {
167 bool enabled; //!< Whether a mask for this hand is being reported
168 struct xrt_rect_f32 rect; //!< The mask itself in pixel coordinates
169 } devices[XRT_SYSTEM_MAX_DEVICES];
170 } views[XRT_TRACKING_MAX_CAMS];
171};
172
173/*!
174 * @interface xrt_imu_sink
175 *
176 * An object to send IMU samples to.
177 *
178 * Similar to @ref xrt_frame_sink but the interface implementation must manage
179 * its own resources, not through a context graph.
180 *
181 * @todo Make @ref xrt_tracked_psmv and @ref xrt_tracked_psvr implement this
182 */
184{
185 /*!
186 * Push an IMU sample into the sink
187 */
188 void (*push_imu)(struct xrt_imu_sink *, struct xrt_imu_sample *sample);
189};
190
191/*!
192 * @interface xrt_pose_sink
193 *
194 * An object to send pairs of timestamps and poses to. @see xrt_imu_sink.
195 */
197{
198 void (*push_pose)(struct xrt_pose_sink *, struct xrt_pose_sample *sample);
199};
200
201/*!
202 * @interface xrt_device_masks_sink
203 *
204 * An object to push @ref xrt_device_masks_sample to.
205 */
207{
208 void (*push_device_masks)(struct xrt_device_masks_sink *, struct xrt_device_masks_sample *device_masks);
209};
210
211
212/*!
213 * Container of pointers to sinks that could be used for a SLAM system. Sinks
214 * are considered disabled if they are null.
215 */
217{
218 int cam_count;
219 int imu_count;
220 struct xrt_frame_sink *cams[XRT_TRACKING_MAX_CAMS];
221 struct xrt_imu_sink *imus[XRT_TRACKING_MAX_IMUS];
222 //! Can receive ground truth poses if available
224 //! SLAM masks, one per optical tracker (so they can push masks asynchronously).
225 struct xrt_device_masks_sink *masks[XRT_TRACKING_MAX_MASK_SINKS];
226};
227
228/*!
229 * @interface xrt_tracked_psmv
230 *
231 * A single tracked PS Move controller, camera and ball are not synced.
232 *
233 * @todo How do we communicate ball colour change?
234 */
236{
237 //! The tracking system origin for this ball.
239
240 //! Device owning this ball.
242
243 //! Colour of the ball.
245
246 /*!
247 * Push a IMU sample into the tracking system.
248 */
249 void (*push_imu)(struct xrt_tracked_psmv *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample);
250
251 /*!
252 * Called by the owning @ref xrt_device @ref xdev to get the pose of
253 * the ball in the tracking space at the given time.
254 *
255 * @todo Should we add a out_time argument as a way to signal min and
256 * maximum, and as such only do interpelation between different captured
257 * frames.
258 */
260 enum xrt_input_name name,
261 timepoint_ns when_ns,
262 struct xrt_space_relation *out_relation);
263
264 /*!
265 * Destroy this tracked ball.
266 */
267 void (*destroy)(struct xrt_tracked_psmv *);
268};
269
270/*!
271 * @interface xrt_tracked_psvr
272 *
273 * A tracked PSVR headset.
274 *
275 * @todo How do we communicate led lighting status?
276 */
278{
279 //! The tracking system origin for this ball.
281
282 //! Device owning this ball.
284
285 /*!
286 * Push a IMU sample into the tracking system.
287 */
288 void (*push_imu)(struct xrt_tracked_psvr *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample);
289
290 /*!
291 * Called by the owning @ref xrt_device @ref xdev to get the pose of
292 * the psvr in the tracking space at the given time.
293 */
295 timepoint_ns when_ns,
296 struct xrt_space_relation *out_relation);
297
298 /*!
299 * Destroy this tracked psvr.
300 */
301 void (*destroy)(struct xrt_tracked_psvr *);
302};
303
304/*!
305 * @interface xrt_tracked_slam
306 *
307 * An adapter that wraps an external SLAM tracker to provide SLAM tracking.
308 * Devices that want to be tracked through SLAM should create and manage an
309 * instance of this type.
310 */
312{
313 /*!
314 * Called by the owning @ref xrt_device to get the last estimated pose
315 * of the SLAM tracker.
316 */
318 timepoint_ns when_ns,
319 struct xrt_space_relation *out_relation);
320};
321
322/*
323 *
324 * Helper functions.
325 *
326 */
327
328//! @public @memberof xrt_imu_sink
329XRT_NONNULL_ALL static inline void
330xrt_sink_push_imu(struct xrt_imu_sink *sink, struct xrt_imu_sample *sample)
331{
332 sink->push_imu(sink, sample);
333}
334
335//! @public @memberof xrt_pose_sink
336XRT_NONNULL_ALL static inline void
337xrt_sink_push_pose(struct xrt_pose_sink *sink, struct xrt_pose_sample *sample)
338{
339 sink->push_pose(sink, sample);
340}
341
342//! @public @memberof xrt_device_masks_sink
343XRT_NONNULL_ALL static inline void
344xrt_sink_push_device_masks(struct xrt_device_masks_sink *sink, struct xrt_device_masks_sample *device_masks)
345{
346 sink->push_device_masks(sink, device_masks);
347}
348
349//! @public @memberof xrt_tracked_psmv
350XRT_NONNULL_ALL static inline void
351xrt_tracked_psmv_get_tracked_pose(struct xrt_tracked_psmv *psmv,
352 enum xrt_input_name name,
353 timepoint_ns when_ns,
354 struct xrt_space_relation *out_relation)
355{
356 psmv->get_tracked_pose(psmv, name, when_ns, out_relation);
357}
358
359//! @public @memberof xrt_tracked_psmv
360XRT_NONNULL_ALL static inline void
361xrt_tracked_psmv_push_imu(struct xrt_tracked_psmv *psmv, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
362{
363 psmv->push_imu(psmv, timestamp_ns, sample);
364}
365
366//! @public @memberof xrt_tracked_psmv
367XRT_NONNULL_ALL static inline void
368xrt_tracked_psmv_destroy(struct xrt_tracked_psmv **xtmv_ptr)
369{
370 struct xrt_tracked_psmv *xtmv = *xtmv_ptr;
371 if (xtmv == NULL) {
372 return;
373 }
374
375 xtmv->destroy(xtmv);
376 *xtmv_ptr = NULL;
377}
378
379//! @public @memberof xrt_tracked_psmv
380XRT_NONNULL_ALL static inline void
381xrt_tracked_psvr_get_tracked_pose(struct xrt_tracked_psvr *psvr,
382 timepoint_ns when_ns,
383 struct xrt_space_relation *out_relation)
384{
385 psvr->get_tracked_pose(psvr, when_ns, out_relation);
386}
387
388//! @public @memberof xrt_tracked_psmv
389XRT_NONNULL_ALL static inline void
390xrt_tracked_psvr_push_imu(struct xrt_tracked_psvr *psvr, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
391{
392 psvr->push_imu(psvr, timestamp_ns, sample);
393}
394
395//! @public @memberof xrt_tracked_psmv
396XRT_NONNULL_ALL static inline void
397xrt_tracked_psvr_destroy(struct xrt_tracked_psvr **xtvr_ptr)
398{
399 struct xrt_tracked_psvr *xtvr = *xtvr_ptr;
400 if (xtvr == NULL) {
401 return;
402 }
403
404 xtvr->destroy(xtvr);
405 *xtvr_ptr = NULL;
406}
407
408
409//! @public @memberof xrt_tracked_slam
410XRT_NONNULL_ALL static inline void
411xrt_tracked_slam_get_tracked_pose(struct xrt_tracked_slam *slam,
412 timepoint_ns when_ns,
413 struct xrt_space_relation *out_relation)
414{
415 slam->get_tracked_pose(slam, when_ns, out_relation);
416}
417
418/*!
419 * @}
420 */
421
422
423#ifdef __cplusplus
424}
425#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:961
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:428
bool enabled
Whether a mask for this hand is being reported.
Definition xrt_tracking.h:167
struct xrt_rect_f32 rect
The mask itself in pixel coordinates.
Definition xrt_tracking.h:168
Masks (bounding boxes) of different hands from current views.
Definition xrt_tracking.h:162
An object to push xrt_device_masks_sample to.
Definition xrt_tracking.h:207
A single HMD or input device.
Definition xrt_device.h:328
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 Sample.
Definition xrt_tracking.h:143
An object to send IMU samples to.
Definition xrt_tracking.h:184
void(* push_imu)(struct xrt_imu_sink *, struct xrt_imu_sample *sample)
Push an IMU sample into the sink.
Definition xrt_tracking.h:188
Pose sample.
Definition xrt_tracking.h:153
An object to send pairs of timestamps and poses to.
Definition xrt_tracking.h:197
A pose composed of a position and orientation.
Definition xrt_defines.h:522
Image rectangle.
Definition xrt_defines.h:500
Container of pointers to sinks that could be used for a SLAM system.
Definition xrt_tracking.h:217
struct xrt_pose_sink * gt
Can receive ground truth poses if available.
Definition xrt_tracking.h:223
struct xrt_device_masks_sink * masks[2]
SLAM masks, one per optical tracker (so they can push masks asynchronously).
Definition xrt_tracking.h:225
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:713
A single tracked PS Move controller, camera and ball are not synced.
Definition xrt_tracking.h:236
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:249
struct xrt_device * xdev
Device owning this ball.
Definition xrt_tracking.h:241
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:259
void(* destroy)(struct xrt_tracked_psmv *)
Destroy this tracked ball.
Definition xrt_tracking.h:267
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition xrt_tracking.h:238
struct xrt_colour_rgb_f32 colour
Colour of the ball.
Definition xrt_tracking.h:244
A tracked PSVR headset.
Definition xrt_tracking.h:278
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:294
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition xrt_tracking.h:280
void(* destroy)(struct xrt_tracked_psvr *)
Destroy this tracked psvr.
Definition xrt_tracking.h:301
struct xrt_device * xdev
Device owning this ball.
Definition xrt_tracking.h:283
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:288
An adapter that wraps an external SLAM tracker to provide SLAM tracking.
Definition xrt_tracking.h:312
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:317
Tracking factory.
Definition xrt_tracking.h:106
int(* create_tracked_psmv)(struct xrt_tracking_factory *, struct xrt_tracked_psmv **out_psmv)
Create a tracked PSMV ball.
Definition xrt_tracking.h:113
struct xrt_frame_context * xfctx
Internal frame context, exposed for debugging purposes.
Definition xrt_tracking.h:108
int(* create_tracked_slam)(struct xrt_tracking_factory *, struct xrt_tracked_slam **out_slam)
Create a SLAM tracker.
Definition xrt_tracking.h:125
int(* create_tracked_psvr)(struct xrt_tracking_factory *, struct xrt_tracked_psvr **out_psvr)
Create a tracked PSVR HMD.
Definition xrt_tracking.h:118
A tracking system or device origin.
Definition xrt_tracking.h:87
struct xrt_pose initial_offset
Read-only.
Definition xrt_tracking.h:98
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition xrt_tracking.h:92
IMU Sample.
Definition xrt_tracking.h:133
A 3 element vector with single doubles.
Definition xrt_defines.h:322
A 3 element vector with single floats.
Definition xrt_defines.h:310
Common defines and enums for XRT.
Header for system objects.
int64_t timepoint_ns
Definition xrt_tracking.h:42