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