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