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#define XRT_TRACKING_MAX_CAMS 5
15
16#include "xrt/xrt_defines.h"
17
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24struct time_state;
25struct xrt_device;
26struct xrt_tracking;
28struct xrt_tracked_psmv;
29struct xrt_tracked_psvr;
30struct xrt_tracked_slam;
31
32//! @todo This is from u_time, duplicated to avoid layer violation.
33typedef int64_t timepoint_ns;
34
35/*!
36 * @addtogroup xrt_iface
37 * @{
38 */
39
40/*!
41 * What kind of tracking system is this.
42 *
43 * @todo Is none, Colour, IR, Magnetic the kind of type we need to know about?
44 */
46{
47 //! The device(s) are never tracked.
49
50 //! The device(s) are tracked by RGB camera(s).
52
53 //! The device(s) are tracked by Lighthouse.
55
56 //! The device(s) are tracked by magnetic fields, eg. Razer Hydra.
58
59 //! The device(s) are tracked by external SLAM
61
62 //! The device(s) are tracked through a constellation of lights as seen by cameras.
64
65 //! The device(s) are tracked by other methods.
67
68 //! The device(s) are (re)attachable.
70};
71
72/*!
73 * A tracking system or device origin.
74 *
75 * Tracking systems will typically extend this structure.
76 */
78{
79 //! For debugging.
80 char name[XRT_TRACKING_NAME_LEN];
81
82 //! What can the state tracker expect from this tracking system.
84
85 /*!
86 * Read-only. Set once by the builder, or in some cases, the driver.
87 * With some systems, the offset may be changed at runtime using the space overseer.
88 */
90};
91
92/*!
93 * @interface xrt_tracking_factory
94 * Tracking factory.
95 */
97{
98 //! Internal frame context, exposed for debugging purposes.
100
101 /*!
102 * Create a tracked PSMV ball.
103 */
104 int (*create_tracked_psmv)(struct xrt_tracking_factory *, struct xrt_tracked_psmv **out_psmv);
105
106 /*!
107 * Create a tracked PSVR HMD.
108 */
109 int (*create_tracked_psvr)(struct xrt_tracking_factory *, struct xrt_tracked_psvr **out_psvr);
110
111
112
113 /*!
114 * Create a SLAM tracker.
115 */
116 int (*create_tracked_slam)(struct xrt_tracking_factory *, struct xrt_tracked_slam **out_slam);
117};
118
119/*!
120 * IMU Sample.
121 * @todo Replace with @ref xrt_imu_sample
122 */
124{
125 struct xrt_vec3 accel_m_s2;
126 struct xrt_vec3 gyro_rad_secs;
127};
128
129/*!
130 * IMU Sample.
131 * @todo Make @ref xrt_tracked_psmv and @ref xrt_tracked_psvr use this
132 */
134{
135 timepoint_ns timestamp_ns;
136 struct xrt_vec3_f64 accel_m_s2;
137 struct xrt_vec3_f64 gyro_rad_secs;
138};
139
140/*!
141 * Pose sample.
142 */
144{
145 timepoint_ns timestamp_ns;
146 struct xrt_pose pose;
147};
148
149/*!
150 * Masks (bounding boxes) of different hands from current views
151 */
153{
155 {
156 bool enabled; //!< Whether any hand mask for this camera is being reported
158 {
159 bool enabled; //!< Whether a mask for this hand is being reported
160 struct xrt_rect_f32 rect; //!< The mask itself in pixel coordinates
161 } hands[2];
162 } views[XRT_TRACKING_MAX_CAMS];
163};
164
165/*!
166 * @interface xrt_imu_sink
167 *
168 * An object to send IMU samples to.
169 *
170 * Similar to @ref xrt_frame_sink but the interface implementation must manage
171 * its own resources, not through a context graph.
172 *
173 * @todo Make @ref xrt_tracked_psmv and @ref xrt_tracked_psvr implement this
174 */
176{
177 /*!
178 * Push an IMU sample into the sink
179 */
180 void (*push_imu)(struct xrt_imu_sink *, struct xrt_imu_sample *sample);
181};
182
183/*!
184 * @interface xrt_pose_sink
185 *
186 * An object to send pairs of timestamps and poses to. @see xrt_imu_sink.
187 */
189{
190 void (*push_pose)(struct xrt_pose_sink *, struct xrt_pose_sample *sample);
191};
192
193/*!
194 * @interface xrt_hand_masks_sink
195 *
196 * An object to push @ref xrt_hand_masks_sample to.
197 */
199{
200 void (*push_hand_masks)(struct xrt_hand_masks_sink *, struct xrt_hand_masks_sample *hand_masks);
201};
202
203
204/*!
205 * Container of pointers to sinks that could be used for a SLAM system. Sinks
206 * are considered disabled if they are null.
207 */
209{
210 int cam_count;
211 struct xrt_frame_sink *cams[XRT_TRACKING_MAX_CAMS];
212 struct xrt_imu_sink *imu;
213 struct xrt_pose_sink *gt; //!< Can receive ground truth poses if available
214 struct xrt_hand_masks_sink *hand_masks;
215};
216
217/*!
218 * @interface xrt_tracked_psmv
219 *
220 * A single tracked PS Move controller, camera and ball are not synced.
221 *
222 * @todo How do we communicate ball colour change?
223 */
225{
226 //! The tracking system origin for this ball.
228
229 //! Device owning this ball.
231
232 //! Colour of the ball.
234
235 /*!
236 * Push a IMU sample into the tracking system.
237 */
238 void (*push_imu)(struct xrt_tracked_psmv *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample);
239
240 /*!
241 * Called by the owning @ref xrt_device @ref xdev to get the pose of
242 * the ball in the tracking space at the given time.
243 *
244 * @todo Should we add a out_time argument as a way to signal min and
245 * maximum, and as such only do interpelation between different captured
246 * frames.
247 */
249 enum xrt_input_name name,
250 timepoint_ns when_ns,
251 struct xrt_space_relation *out_relation);
252
253 /*!
254 * Destroy this tracked ball.
255 */
256 void (*destroy)(struct xrt_tracked_psmv *);
257};
258
259/*!
260 * @interface xrt_tracked_psvr
261 *
262 * A tracked PSVR headset.
263 *
264 * @todo How do we communicate led lighting status?
265 */
267{
268 //! The tracking system origin for this ball.
270
271 //! Device owning this ball.
273
274 /*!
275 * Push a IMU sample into the tracking system.
276 */
277 void (*push_imu)(struct xrt_tracked_psvr *, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample);
278
279 /*!
280 * Called by the owning @ref xrt_device @ref xdev to get the pose of
281 * the psvr in the tracking space at the given time.
282 */
284 timepoint_ns when_ns,
285 struct xrt_space_relation *out_relation);
286
287 /*!
288 * Destroy this tracked psvr.
289 */
290 void (*destroy)(struct xrt_tracked_psvr *);
291};
292
293/*!
294 * @interface xrt_tracked_slam
295 *
296 * An adapter that wraps an external SLAM tracker to provide SLAM tracking.
297 * Devices that want to be tracked through SLAM should create and manage an
298 * instance of this type.
299 */
301{
302 /*!
303 * Called by the owning @ref xrt_device to get the last estimated pose
304 * of the SLAM tracker.
305 */
307 timepoint_ns when_ns,
308 struct xrt_space_relation *out_relation);
309};
310
311/*
312 *
313 * Helper functions.
314 *
315 */
316
317//! @public @memberof xrt_imu_sink
318XRT_NONNULL_ALL static inline void
319xrt_sink_push_imu(struct xrt_imu_sink *sink, struct xrt_imu_sample *sample)
320{
321 sink->push_imu(sink, sample);
322}
323
324//! @public @memberof xrt_pose_sink
325XRT_NONNULL_ALL static inline void
326xrt_sink_push_pose(struct xrt_pose_sink *sink, struct xrt_pose_sample *sample)
327{
328 sink->push_pose(sink, sample);
329}
330
331//! @public @memberof xrt_hand_masks_sink
332XRT_NONNULL_ALL static inline void
333xrt_sink_push_hand_masks(struct xrt_hand_masks_sink *sink, struct xrt_hand_masks_sample *hand_masks)
334{
335 sink->push_hand_masks(sink, hand_masks);
336}
337
338//! @public @memberof xrt_tracked_psmv
339XRT_NONNULL_ALL static inline void
340xrt_tracked_psmv_get_tracked_pose(struct xrt_tracked_psmv *psmv,
341 enum xrt_input_name name,
342 timepoint_ns when_ns,
343 struct xrt_space_relation *out_relation)
344{
345 psmv->get_tracked_pose(psmv, name, when_ns, out_relation);
346}
347
348//! @public @memberof xrt_tracked_psmv
349XRT_NONNULL_ALL static inline void
350xrt_tracked_psmv_push_imu(struct xrt_tracked_psmv *psmv, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
351{
352 psmv->push_imu(psmv, timestamp_ns, sample);
353}
354
355//! @public @memberof xrt_tracked_psmv
356XRT_NONNULL_ALL static inline void
357xrt_tracked_psmv_destroy(struct xrt_tracked_psmv **xtmv_ptr)
358{
359 struct xrt_tracked_psmv *xtmv = *xtmv_ptr;
360 if (xtmv == NULL) {
361 return;
362 }
363
364 xtmv->destroy(xtmv);
365 *xtmv_ptr = NULL;
366}
367
368//! @public @memberof xrt_tracked_psmv
369XRT_NONNULL_ALL static inline void
370xrt_tracked_psvr_get_tracked_pose(struct xrt_tracked_psvr *psvr,
371 timepoint_ns when_ns,
372 struct xrt_space_relation *out_relation)
373{
374 psvr->get_tracked_pose(psvr, when_ns, out_relation);
375}
376
377//! @public @memberof xrt_tracked_psmv
378XRT_NONNULL_ALL static inline void
379xrt_tracked_psvr_push_imu(struct xrt_tracked_psvr *psvr, timepoint_ns timestamp_ns, struct xrt_tracking_sample *sample)
380{
381 psvr->push_imu(psvr, timestamp_ns, sample);
382}
383
384//! @public @memberof xrt_tracked_psmv
385XRT_NONNULL_ALL static inline void
386xrt_tracked_psvr_destroy(struct xrt_tracked_psvr **xtvr_ptr)
387{
388 struct xrt_tracked_psvr *xtvr = *xtvr_ptr;
389 if (xtvr == NULL) {
390 return;
391 }
392
393 xtvr->destroy(xtvr);
394 *xtvr_ptr = NULL;
395}
396
397
398//! @public @memberof xrt_tracked_slam
399XRT_NONNULL_ALL static inline void
400xrt_tracked_slam_get_tracked_pose(struct xrt_tracked_slam *slam,
401 timepoint_ns when_ns,
402 struct xrt_space_relation *out_relation)
403{
404 slam->get_tracked_pose(slam, when_ns, out_relation);
405}
406
407/*!
408 * @}
409 */
410
411
412#ifdef __cplusplus
413}
414#endif
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:930
xrt_tracking_type
What kind of tracking system is this.
Definition xrt_tracking.h:46
@ XRT_TRACKING_TYPE_NONE
The device(s) are never tracked.
Definition xrt_tracking.h:48
@ XRT_TRACKING_TYPE_MAGNETIC
The device(s) are tracked by magnetic fields, eg. Razer Hydra.
Definition xrt_tracking.h:57
@ XRT_TRACKING_TYPE_CONSTELLATION
The device(s) are tracked through a constellation of lights as seen by cameras.
Definition xrt_tracking.h:63
@ XRT_TRACKING_TYPE_LIGHTHOUSE
The device(s) are tracked by Lighthouse.
Definition xrt_tracking.h:54
@ XRT_TRACKING_TYPE_RGB
The device(s) are tracked by RGB camera(s).
Definition xrt_tracking.h:51
@ XRT_TRACKING_TYPE_OTHER
The device(s) are tracked by other methods.
Definition xrt_tracking.h:66
@ XRT_TRACKING_TYPE_ATTACHABLE
The device(s) are (re)attachable.
Definition xrt_tracking.h:69
@ XRT_TRACKING_TYPE_EXTERNAL_SLAM
The device(s) are tracked by external SLAM.
Definition xrt_tracking.h:60
Time-keeping state structure.
Definition u_time.cpp:30
A 3 element colour with floating point channels.
Definition xrt_defines.h:398
A single HMD or input device.
Definition xrt_device.h:311
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
bool enabled
Whether a mask for this hand is being reported.
Definition xrt_tracking.h:159
struct xrt_rect_f32 rect
The mask itself in pixel coordinates.
Definition xrt_tracking.h:160
bool enabled
Whether any hand mask for this camera is being reported.
Definition xrt_tracking.h:156
Masks (bounding boxes) of different hands from current views.
Definition xrt_tracking.h:153
An object to push xrt_hand_masks_sample to.
Definition xrt_tracking.h:199
IMU Sample.
Definition xrt_tracking.h:134
An object to send IMU samples to.
Definition xrt_tracking.h:176
void(* push_imu)(struct xrt_imu_sink *, struct xrt_imu_sample *sample)
Push an IMU sample into the sink.
Definition xrt_tracking.h:180
Pose sample.
Definition xrt_tracking.h:144
An object to send pairs of timestamps and poses to.
Definition xrt_tracking.h:189
A pose composed of a position and orientation.
Definition xrt_defines.h:492
Image rectangle.
Definition xrt_defines.h:470
Container of pointers to sinks that could be used for a SLAM system.
Definition xrt_tracking.h:209
struct xrt_pose_sink * gt
Can receive ground truth poses if available.
Definition xrt_tracking.h:213
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:683
A single tracked PS Move controller, camera and ball are not synced.
Definition xrt_tracking.h:225
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:238
struct xrt_device * xdev
Device owning this ball.
Definition xrt_tracking.h:230
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:248
void(* destroy)(struct xrt_tracked_psmv *)
Destroy this tracked ball.
Definition xrt_tracking.h:256
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition xrt_tracking.h:227
struct xrt_colour_rgb_f32 colour
Colour of the ball.
Definition xrt_tracking.h:233
A tracked PSVR headset.
Definition xrt_tracking.h:267
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:283
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition xrt_tracking.h:269
void(* destroy)(struct xrt_tracked_psvr *)
Destroy this tracked psvr.
Definition xrt_tracking.h:290
struct xrt_device * xdev
Device owning this ball.
Definition xrt_tracking.h:272
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:277
An adapter that wraps an external SLAM tracker to provide SLAM tracking.
Definition xrt_tracking.h:301
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:306
Tracking factory.
Definition xrt_tracking.h:97
int(* create_tracked_psmv)(struct xrt_tracking_factory *, struct xrt_tracked_psmv **out_psmv)
Create a tracked PSMV ball.
Definition xrt_tracking.h:104
struct xrt_frame_context * xfctx
Internal frame context, exposed for debugging purposes.
Definition xrt_tracking.h:99
int(* create_tracked_slam)(struct xrt_tracking_factory *, struct xrt_tracked_slam **out_slam)
Create a SLAM tracker.
Definition xrt_tracking.h:116
int(* create_tracked_psvr)(struct xrt_tracking_factory *, struct xrt_tracked_psvr **out_psvr)
Create a tracked PSVR HMD.
Definition xrt_tracking.h:109
A tracking system or device origin.
Definition xrt_tracking.h:78
struct xrt_pose initial_offset
Read-only.
Definition xrt_tracking.h:89
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition xrt_tracking.h:83
IMU Sample.
Definition xrt_tracking.h:124
A 3 element vector with single doubles.
Definition xrt_defines.h:301
A 3 element vector with single floats.
Definition xrt_defines.h:289
Common defines and enums for XRT.
int64_t timepoint_ns
Definition xrt_tracking.h:33