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.
45 
46  // The device(s) are tracked by RGB camera(s).
48 };
49 
50 /*!
51  * A tracking system or device origin.
52  */
54 {
55  //! For debugging.
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  timepoint_ns when_ns,
134  struct xrt_space_relation *out_relation);
135 
136  /*!
137  * Destroy this tracked ball.
138  */
139  void (*destroy)(struct xrt_tracked_psmv *);
140 };
141 
142 /*!
143  * A tracked PSVR headset.
144  *
145  * @todo How do we communicate led lighting status?
146  */
148 {
149  //! The tracking system origin for this ball.
151 
152  //! Device owning this ball.
153  struct xrt_device *xdev;
154 
155  /*!
156  * Push a IMU sample into the tracking system.
157  */
158  void (*push_imu)(struct xrt_tracked_psvr *,
159  timepoint_ns timestamp_ns,
160  struct xrt_tracking_sample *sample);
161 
162  /*!
163  * Called by the owning @ref xrt_device @ref xdev to get the pose of
164  * the psvr in the tracking space at the given time.
165  */
166  void (*get_tracked_pose)(struct xrt_tracked_psvr *,
167  timepoint_ns when_ns,
168  struct xrt_space_relation *out_relation);
169 
170  /*!
171  * Destroy this tracked psvr.
172  */
173  void (*destroy)(struct xrt_tracked_psvr *);
174 };
175 
176 
177 /*
178  *
179  * Helper functions.
180  *
181  */
182 
183 static inline void
184 xrt_tracked_psmv_get_tracked_pose(struct xrt_tracked_psmv *psmv,
185  enum xrt_input_name name,
186  timepoint_ns when_ns,
187  struct xrt_space_relation *out_relation)
188 {
189  psmv->get_tracked_pose(psmv, name, when_ns, out_relation);
190 }
191 
192 static inline void
193 xrt_tracked_psmv_push_imu(struct xrt_tracked_psmv *psmv,
194  timepoint_ns timestamp_ns,
195  struct xrt_tracking_sample *sample)
196 {
197  psmv->push_imu(psmv, timestamp_ns, sample);
198 }
199 
200 static inline void
201 xrt_tracked_psmv_destroy(struct xrt_tracked_psmv **xtmv_ptr)
202 {
203  struct xrt_tracked_psmv *xtmv = *xtmv_ptr;
204  if (xtmv == NULL) {
205  return;
206  }
207 
208  xtmv->destroy(xtmv);
209  *xtmv_ptr = NULL;
210 }
211 
212 static inline void
213 xrt_tracked_psvr_get_tracked_pose(struct xrt_tracked_psvr *psvr,
214  timepoint_ns when_ns,
215  struct xrt_space_relation *out_relation)
216 {
217  psvr->get_tracked_pose(psvr, when_ns, out_relation);
218 }
219 
220 static inline void
221 xrt_tracked_psvr_push_imu(struct xrt_tracked_psvr *psvr,
222  timepoint_ns timestamp_ns,
223  struct xrt_tracking_sample *sample)
224 {
225  psvr->push_imu(psvr, timestamp_ns, sample);
226 }
227 
228 static inline void
229 xrt_tracked_psvr_destroy(struct xrt_tracked_psvr **xtvr_ptr)
230 {
231  struct xrt_tracked_psvr *xtvr = *xtvr_ptr;
232  if (xtvr == NULL) {
233  return;
234  }
235 
236  xtvr->destroy(xtvr);
237  *xtvr_ptr = NULL;
238 }
239 
240 
241 /*!
242  * @}
243  */
244 
245 
246 #ifdef __cplusplus
247 }
248 #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:173
A 3 element vector with single floats.
Definition: xrt_defines.h:133
A pose composed of a position and orientation.
Definition: xrt_defines.h:231
void(* destroy)(struct xrt_tracked_psmv *)
Destroy this tracked ball.
Definition: xrt_tracking.h:139
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:131
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:336
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:150
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:158
Common defines and enums for XRT.
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
struct vive_imu_sample sample[3]
Definition: vive_protocol.h:210
A 3 element colour with floating point channels.
Definition: xrt_defines.h:193
Definition: xrt_tracking.h:47
Definition: xrt_tracking.h:44
A tracked PSVR headset.
Definition: xrt_tracking.h:147
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition: xrt_tracking.h:59
#define XRT_TRACKING_NAME_LEN
Definition: xrt_tracking.h:12
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
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:166
A single HMD or input device.
Definition: xrt_device.h:202
struct xrt_device * xdev
Device owning this ball.
Definition: xrt_tracking.h:153
xrt_input_name
Name of a input with a baked in type.
Definition: xrt_defines.h:421