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