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 
14 #include "xrt/xrt_defines.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 
21 struct time_state;
22 struct xrt_device;
23 struct xrt_tracking;
25 struct xrt_tracked_psmv;
27 
28 //! @todo This is from u_time, duplicated to avoid layer violation.
29 typedef int64_t timepoint_ns;
30 
31 /*!
32  * @ingroup xrt_iface
33  * @{
34  */
35 
36 /*!
37  * What kind of tracking system is this.
38  *
39  * @todo Is none, Colour, IR, Magnetic the kind of type we need to know about?
40  */
42 {
43  // The device(s) are never tracked.
44  XRT_TRACKING_TYPE_NONE,
45 
46  // The device(s) are tracked by RGB camera(s).
47  XRT_TRACKING_TYPE_RGB,
48 };
49 
50 /*!
51  * A tracking system or device origin.
52  */
54 {
55  //! For debugging.
56  char name[XRT_TRACKING_NAME_LEN];
57 
58  //! What can the state tracker expect from this tracking system.
60 
61  /*!
62  * Read and written to by the state-tracker using the device(s)
63  * this tracking system is tracking.
64  */
65  struct xrt_pose offset;
66 };
67 
68 /*!
69  * Tracking factory.
70  */
72 {
73  //! Internal frame context, exposed for debugging purposes.
75 
76  /*!
77  * Create a tracked PSMV ball.
78  */
79  int (*create_tracked_psmv)(struct xrt_tracking_factory *,
80  struct xrt_device *xdev,
81  struct xrt_tracked_psmv **out_psmv);
82 
83  /*!
84  * Create a tracked PSVR ball.
85  */
86  int (*create_tracked_psvr)(struct xrt_tracking_factory *,
87  struct xrt_device *xdev,
88  struct xrt_tracked_psvr **out_psvr);
89 };
90 
91 /*!
92  * IMU Sample.
93  */
95 {
96  struct xrt_vec3 accel_m_s2;
97  struct xrt_vec3 gyro_rad_secs;
98 };
99 
100 /*!
101  * A single tracked PS Move controller, camera and ball are not synced.
102  *
103  * @todo How do we communicate ball colour change?
104  */
106 {
107  //! The tracking system origin for this ball.
109 
110  //! Device owning this ball.
111  struct xrt_device *xdev;
112 
113  //! Colour of the ball.
114  struct xrt_colour_rgb_f32 colour;
115 
116  /*!
117  * Push a IMU sample into the tracking system.
118  */
119  void (*push_imu)(struct xrt_tracked_psmv *,
120  timepoint_ns timestamp_ns,
121  struct xrt_tracking_sample *sample);
122 
123  /*!
124  * Called by the owning @ref xrt_device @ref xdev to get the pose of
125  * the ball in the tracking space at the given time.
126  *
127  * @todo Should we add a out_time argument as a way to signal min and
128  * maximum, and as such only do interpelation between different captured
129  * frames.
130  */
131  void (*get_tracked_pose)(struct xrt_tracked_psmv *,
132  enum xrt_input_name name,
133  struct time_state *timekeeper,
134  timepoint_ns when_ns,
135  struct xrt_space_relation *out_relation);
136 
137  /*!
138  * Destroy this tracked ball.
139  */
140  void (*destroy)(struct xrt_tracked_psmv *);
141 };
142 
143 /*!
144  * A tracked PSVR headset.
145  *
146  * @todo How do we communicate led lighting status?
147  */
149 {
150  //! The tracking system origin for this ball.
152 
153  //! Device owning this ball.
154  struct xrt_device *xdev;
155 
156  /*!
157  * Push a IMU sample into the tracking system.
158  */
159  void (*push_imu)(struct xrt_tracked_psvr *,
160  timepoint_ns timestamp_ns,
161  struct xrt_tracking_sample *sample);
162 
163  /*!
164  * Called by the owning @ref xrt_device @ref xdev to get the pose of
165  * the psvr in the tracking space at the given time.
166  */
167  void (*get_tracked_pose)(struct xrt_tracked_psvr *,
168  struct time_state *timekeeper,
169  timepoint_ns when_ns,
170  struct xrt_space_relation *out_relation);
171 
172  /*!
173  * Destroy this tracked psvr.
174  */
175  void (*destroy)(struct xrt_tracked_psvr *);
176 };
177 
178 
179 /*
180  *
181  * Helper functions.
182  *
183  */
184 
185 static inline void
186 xrt_tracked_psmv_get_tracked_pose(struct xrt_tracked_psmv *psmv,
187  enum xrt_input_name name,
188  struct time_state *timekeeper,
189  timepoint_ns when_ns,
190  struct xrt_space_relation *out_relation)
191 {
192  psmv->get_tracked_pose(psmv, name, timekeeper, when_ns, out_relation);
193 }
194 
195 static inline void
196 xrt_tracked_psmv_push_imu(struct xrt_tracked_psmv *psmv,
197  timepoint_ns timestamp_ns,
198  struct xrt_tracking_sample *sample)
199 {
200  psmv->push_imu(psmv, timestamp_ns, sample);
201 }
202 
203 static inline void
204 xrt_tracked_psmv_destroy(struct xrt_tracked_psmv **xtmv_ptr)
205 {
206  struct xrt_tracked_psmv *xtmv = *xtmv_ptr;
207  if (xtmv == NULL) {
208  return;
209  }
210 
211  xtmv->destroy(xtmv);
212  *xtmv_ptr = NULL;
213 }
214 
215 static inline void
216 xrt_tracked_psvr_get_tracked_pose(struct xrt_tracked_psvr *psvr,
217  struct time_state *timekeeper,
218  timepoint_ns when_ns,
219  struct xrt_space_relation *out_relation)
220 {
221  psvr->get_tracked_pose(psvr, timekeeper, when_ns, out_relation);
222 }
223 
224 static inline void
225 xrt_tracked_psvr_push_imu(struct xrt_tracked_psvr *psvr,
226  timepoint_ns timestamp_ns,
227  struct xrt_tracking_sample *sample)
228 {
229  psvr->push_imu(psvr, timestamp_ns, sample);
230 }
231 
232 static inline void
233 xrt_tracked_psvr_destroy(struct xrt_tracked_psvr **xtvr_ptr)
234 {
235  struct xrt_tracked_psvr *xtvr = *xtvr_ptr;
236  if (xtvr == NULL) {
237  return;
238  }
239 
240  xtvr->destroy(xtvr);
241  *xtvr_ptr = NULL;
242 }
243 
244 
245 /*!
246  * @}
247  */
248 
249 
250 #ifdef __cplusplus
251 }
252 #endif
Tracking factory.
Definition: xrt_tracking.h:71
struct xrt_frame_context * xfctx
Internal frame context, exposed for debugging purposes.
Definition: xrt_tracking.h:74
A tracking system or device origin.
Definition: xrt_tracking.h:53
char name[XRT_TRACKING_NAME_LEN]
For debugging.
Definition: xrt_tracking.h:56
void(* destroy)(struct xrt_tracked_psvr *)
Destroy this tracked psvr.
Definition: xrt_tracking.h:175
A 3 element vector with single floats.
Definition: xrt_defines.h:131
A pose composed of a position and orientation.
Definition: xrt_defines.h:229
void(* destroy)(struct xrt_tracked_psmv *)
Destroy this tracked ball.
Definition: xrt_tracking.h:140
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition: xrt_tracking.h:108
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:334
int64_t timepoint_ns
Definition: xrt_tracking.h:26
struct xrt_tracking_origin * origin
The tracking system origin for this ball.
Definition: xrt_tracking.h:151
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:159
Common defines and enums for XRT.
void(* get_tracked_pose)(struct xrt_tracked_psvr *, struct time_state *timekeeper, 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:167
Time-keeping state structure.
Definition: u_time.cpp:46
xrt_tracking_type
What kind of tracking system is this.
Definition: xrt_tracking.h:41
struct xrt_device * xdev
Device owning this ball.
Definition: xrt_tracking.h:111
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:87
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:119
A 3 element colour with floating point channels.
Definition: xrt_defines.h:191
void(* get_tracked_pose)(struct xrt_tracked_psmv *, enum xrt_input_name name, struct time_state *timekeeper, 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:131
A tracked PSVR headset.
Definition: xrt_tracking.h:148
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition: xrt_tracking.h:59
A single tracked PS Move controller, camera and ball are not synced.
Definition: xrt_tracking.h:105
IMU Sample.
Definition: xrt_tracking.h:94
struct xrt_pose offset
Read and written to by the state-tracker using the device(s) this tracking system is tracking...
Definition: xrt_tracking.h:65
A single HMD or input device.
Definition: xrt_device.h:203
struct xrt_device * xdev
Device owning this ball.
Definition: xrt_tracking.h:154
xrt_input_name
Name of a input with a baked in type.
Definition: xrt_defines.h:417