Monado OpenXR Runtime
wmr_hmd.h
Go to the documentation of this file.
1// Copyright 2018, Philipp Zabel.
2// Copyright 2020-2021, N Madsen.
3// Copyright 2020-2023, Collabora, Ltd.
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief Interface to the WMR HMD driver code.
8 * @author Philipp Zabel <philipp.zabel@gmail.com>
9 * @author nima01 <nima_zero_one@protonmail.com>
10 * @author Jakob Bornecrantz <jakob@collabora.com>
11 * @author Nova King <technobaboo@proton.me>
12 * @ingroup drv_wmr
13 */
14
15#pragma once
16
17#include "tracking/t_tracking.h"
18#include "xrt/xrt_device.h"
19#include "xrt/xrt_frame.h"
20#include "xrt/xrt_prober.h"
21#include "os/os_threading.h"
22#include "math/m_imu_3dof.h"
23#include "util/u_logging.h"
25#include "util/u_var.h"
26
27#include "wmr_protocol.h"
28#include "wmr_config.h"
29#include "wmr_camera.h"
30#include "wmr_common.h"
31#include "wmr_hmd_controller.h"
32
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/* Support 2 controllers on HP Reverb G2 */
39#define WMR_MAX_CONTROLLERS 2
40
41struct wmr_hmd;
42
44{
45 enum wmr_headset_type hmd_type;
46
47 //! String by which we recognise the device
48 const char *dev_id_str;
49 //! Friendly ID string for debug
50 const char *debug_name;
51
52 int (*init_func)(struct wmr_hmd *wh);
53 void (*deinit_func)(struct wmr_hmd *wh);
54 void (*screen_enable_func)(struct wmr_hmd *wh, bool enable);
55};
56
58{
59 //! Inverse affine transform to move from (undistorted) pixels
60 //! to image plane / normalised image coordinates
62
63 //! tan(angle) FoV min/max for X and Y in the input texture
65 struct xrt_vec2 tex_y_range;
66};
67
68/*!
69 * @implements xrt_device
70 */
71struct wmr_hmd
72{
73 struct xrt_device base;
74
75 const struct wmr_headset_descriptor *hmd_desc;
76
77 //! firmware configuration block, with device names etc
79
80 //! Config data parsed from the firmware JSON
82
83 //! Packet reading thread.
85
86 enum u_logging_level log_level;
87
88 int32_t left_view_y_offset, right_view_y_offset;
89
90 /*!
91 * This is the Hololens Sensors device, this is where we get all of the
92 * IMU data and read the config from.
93 *
94 * During start it is owned by the thread creating the device, after
95 * init it is owned by the reading thread. Read/write access is
96 * protected by the hid_lock
97 */
98
100 struct os_mutex hid_lock;
101
102 /*!
103 * This is the vendor specific companion device of the Hololens Sensors.
104 * When activated, it will report the physical IPD adjustment and proximity
105 * sensor status of the headset. It also allows enabling/disabling the HMD
106 * screen on Reverb G1/G2.
107 */
109
110 //! Current desired HMD screen state.
112 //! Latest raw IPD value read from the device.
113 uint16_t raw_ipd;
114 //! Latest proximity sensor value read from the device.
116
117 //! Distortion related parameters
119
120 struct hololens_sensors_packet packet;
121
122 struct
123 {
124 //! Protects all members of the `fusion` substruct.
126
127 //! Main fusion calculator.
129
130 //! The last angular velocity from the IMU, for prediction.
132
133 //! When did we get the last IMU sample, in CPU time.
135 } fusion;
136
137 //! Fields related to camera-based tracking (SLAM and hand tracking)
138 struct
139 {
140 //! Source of video/IMU data for tracking
141 struct xrt_fs *source;
142
143 //! Context for @ref source
145
146 //! SLAM tracker.
147 //! @todo Right now, we are not consistent in how we interface with
148 //! trackers. In particular, we have a @ref xrt_tracked_slam field but not
149 //! an equivalent for hand tracking.
151
152 //! Calibration data for SLAM
154
155 //! Set at start. Whether the SLAM tracker was initialized.
157
158 //! Set at start. Whether the hand tracker was initialized.
160
161 //! SLAM systems track the IMU pose, enabling this corrects it to middle of the eyes
162 bool imu2me;
164
165 //! Whether to track the HMD with 6dof SLAM or fallback to the `fusion` 3dof tracker
167
168 //! Last tracked pose
170
171 //! Additional offset to apply to `pose`
173
174 //! Average 4 IMU samples before sending them to the trackers
176
177 /*!
178 * Offset for tracked pose offsets (applies to both fusion and SLAM).
179 * Applied when getting the tracked poses, so is effectively a offset
180 * to increase or decrease prediction.
181 */
183
184 struct
185 {
186 struct u_var_button hmd_screen_enable_btn;
187 struct u_var_button switch_tracker_btn;
188 char hand_status[128];
189 char slam_status[128];
190 } gui;
191
192 /* Tunnelled controller devices (Reverb G2, Odyssey+) handling */
193 struct os_mutex controller_status_lock;
194 struct os_cond controller_status_cond;
195 bool have_left_controller_status;
196 bool have_right_controller_status;
197
198 struct wmr_hmd_controller_connection *controller[WMR_MAX_CONTROLLERS];
199};
200
201static inline struct wmr_hmd *
202wmr_hmd(struct xrt_device *p)
203{
204 return (struct wmr_hmd *)p;
205}
206
207void
208wmr_hmd_create(enum wmr_headset_type hmd_type,
209 struct os_hid_device *hid_holo,
210 struct os_hid_device *hid_ctrl,
211 struct xrt_prober_device *dev_holo,
212 enum u_logging_level log_level,
213 struct xrt_device **out_hmd,
214 struct xrt_device **out_handtracker,
215 struct xrt_device **out_left_controller,
216 struct xrt_device **out_right_controller);
217
218bool
219wmr_hmd_send_controller_packet(struct wmr_hmd *hmd, const uint8_t *buffer, uint32_t buf_size);
220int
221wmr_hmd_read_sync_from_controller(struct wmr_hmd *hmd, uint8_t *buffer, uint32_t buf_size, int timeout_ms);
222#ifdef __cplusplus
223}
224#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:43
wmr_headset_type
Headset type, used to select different control and init/shutdown procedures.
Definition: wmr_common.h:29
A IMU fusion specially made for 3dof devices.
Wrapper around OS threading native functions.
Definition: wmr_protocol.h:79
Definition: m_imu_3dof.h:35
A wrapper around a native conditional variable.
Definition: os_threading.h:189
Representing a single hid interface on a device.
Definition: os_hid.h:29
A wrapper around a native mutex.
Definition: os_threading.h:55
All in one helper that handles locking, waiting for change and starting a thread.
Definition: os_threading.h:453
Calibration information necessary for SLAM tracking.
Definition: t_tracking.h:636
Simple pushable button.
Definition: u_var.h:79
Draggable single precision float information.
Definition: u_var.h:120
Definition: wmr_protocol.h:90
Definition: wmr_hmd.h:44
const char * debug_name
Friendly ID string for debug.
Definition: wmr_hmd.h:50
const char * dev_id_str
String by which we recognise the device.
Definition: wmr_hmd.h:48
Definition: wmr_config.h:166
Definition: wmr_hmd_controller.h:24
Definition: wmr_hmd.h:58
struct xrt_vec2 tex_x_range
tan(angle) FoV min/max for X and Y in the input texture
Definition: wmr_hmd.h:64
struct xrt_matrix_3x3 inv_affine_xform
Inverse affine transform to move from (undistorted) pixels to image plane / normalised image coordina...
Definition: wmr_hmd.h:61
Definition: wmr_hmd.h:72
struct wmr_config_header config_hdr
firmware configuration block, with device names etc
Definition: wmr_hmd.h:78
bool slam_enabled
Set at start. Whether the SLAM tracker was initialized.
Definition: wmr_hmd.h:156
struct m_imu_3dof i3dof
Main fusion calculator.
Definition: wmr_hmd.h:128
struct u_var_draggable_f32 tracked_offset_ms
Offset for tracked pose offsets (applies to both fusion and SLAM).
Definition: wmr_hmd.h:182
bool hand_enabled
Set at start. Whether the hand tracker was initialized.
Definition: wmr_hmd.h:159
struct wmr_hmd_config config
Config data parsed from the firmware JSON.
Definition: wmr_hmd.h:81
struct xrt_fs * source
Source of video/IMU data for tracking.
Definition: wmr_hmd.h:141
struct os_thread_helper oth
Packet reading thread.
Definition: wmr_hmd.h:84
struct os_hid_device * hid_hololens_sensors_dev
This is the Hololens Sensors device, this is where we get all of the IMU data and read the config fro...
Definition: wmr_hmd.h:99
bool average_imus
Average 4 IMU samples before sending them to the trackers.
Definition: wmr_hmd.h:175
uint64_t last_imu_timestamp_ns
When did we get the last IMU sample, in CPU time.
Definition: wmr_hmd.h:134
struct wmr_hmd::@209 tracking
Fields related to camera-based tracking (SLAM and hand tracking)
struct xrt_vec3 last_angular_velocity
The last angular velocity from the IMU, for prediction.
Definition: wmr_hmd.h:131
struct xrt_pose offset
Additional offset to apply to pose
Definition: wmr_hmd.h:172
struct xrt_pose pose
Last tracked pose.
Definition: wmr_hmd.h:169
uint16_t raw_ipd
Latest raw IPD value read from the device.
Definition: wmr_hmd.h:113
struct xrt_frame_context xfctx
Context for source.
Definition: wmr_hmd.h:144
bool hmd_screen_enable
Current desired HMD screen state.
Definition: wmr_hmd.h:111
struct t_slam_calibration slam_calib
Calibration data for SLAM.
Definition: wmr_hmd.h:153
bool slam_over_3dof
Whether to track the HMD with 6dof SLAM or fallback to the fusion 3dof tracker.
Definition: wmr_hmd.h:166
uint8_t proximity_sensor
Latest proximity sensor value read from the device.
Definition: wmr_hmd.h:115
struct xrt_tracked_slam * slam
SLAM tracker.
Definition: wmr_hmd.h:150
struct os_hid_device * hid_control_dev
This is the vendor specific companion device of the Hololens Sensors.
Definition: wmr_hmd.h:108
struct wmr_hmd_distortion_params distortion_params[2]
Distortion related parameters.
Definition: wmr_hmd.h:118
struct os_mutex mutex
Protects all members of the fusion substruct.
Definition: wmr_hmd.h:125
bool imu2me
SLAM systems track the IMU pose, enabling this corrects it to middle of the eyes.
Definition: wmr_hmd.h:162
A single HMD or input device.
Definition: xrt_device.h:241
struct xrt_hmd_parts * hmd
Null if this device does not interface with the users head.
Definition: xrt_device.h:253
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:108
Frameserver that generates frames.
Definition: xrt_frameserver.h:70
A tightly packed 3x3 matrix of floats.
Definition: xrt_defines.h:533
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A probed device, may or may not be opened.
Definition: xrt_prober.h:85
An adapter that wraps an external SLAM tracker to provide SLAM tracking.
Definition: xrt_tracking.h:294
A 2 element vector with single floats.
Definition: xrt_defines.h:250
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Tracking API interface.
Code to generate disortion meshes.
Basic logging functionality.
Variable tracking code.
Interface to read WMR cameras.
Defines and constants related to WMR driver code.
WMR and MS HoloLens configuration structures.
void wmr_hmd_create(enum wmr_headset_type hmd_type, struct os_hid_device *hid_holo, struct os_hid_device *hid_ctrl, struct xrt_prober_device *dev_holo, enum u_logging_level log_level, struct xrt_device **out_hmd, struct xrt_device **out_handtracker, struct xrt_device **out_left_controller, struct xrt_device **out_right_controller)
Definition: wmr_hmd.c:1930
Implementation of tunnelled controller connection, that translates messages passing via an HP G2 or S...
WMR and MS HoloLens protocol constants, structures and helpers header.
Header defining an xrt display or controller device.
Data frame header.
Common interface to probe for devices.