Monado OpenXR Runtime
vive_config.h
Go to the documentation of this file.
1 // Copyright 2020-2023, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief vive json header
6  * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
7  * @author Moses Turner <moses@collabora.com>
8  * @ingroup aux_vive
9  */
10 
11 #pragma once
12 
13 #include "xrt/xrt_compiler.h"
14 #include "xrt/xrt_defines.h"
15 
16 #include "util/u_logging.h"
17 #include "util/u_distortion_mesh.h"
18 
19 
20 // public documentation
21 #define INDEX_MIN_IPD 0.058
22 #define INDEX_MAX_IPD 0.07
23 
24 // https://vr-compare.com/headset/htcvive
25 // #define VIVE_MIN_IPD 0.061
26 // #define VIVE_MAX_IPD 0.072
27 
28 // steamvr goes from ~60 to 75
29 #define VIVE_MIN_IPD 0.060
30 #define VIVE_MAX_IPD 0.075
31 
32 // arbitrary default values
33 #define DEFAULT_HAPTIC_FREQ 150.0f
34 #define MIN_HAPTIC_DURATION 0.05f
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 
41 /*!
42  * Headset variant.
43  *
44  * @ingroup aux_vive
45  */
47 {
48  VIVE_UNKNOWN = 0,
49  VIVE_VARIANT_VIVE,
50  VIVE_VARIANT_PRO,
51  VIVE_VARIANT_INDEX,
52  VIVE_VARIANT_PRO2,
53 };
54 
55 /*!
56  * Controller variant.
57  *
58  * @ingroup aux_vive
59  */
61 {
62  CONTROLLER_VIVE_WAND,
63  CONTROLLER_INDEX_LEFT,
64  CONTROLLER_INDEX_RIGHT,
65  CONTROLLER_TRACKER_GEN1,
66  CONTROLLER_TRACKER_GEN2,
67  CONTROLLER_TRACKER_GEN3,
68  CONTROLLER_TRACKER_TUNDRA,
69  CONTROLLER_UNKNOWN
70 };
71 
72 /*!
73  * A calibrated camera on an Index.
74  *
75  * @ingroup aux_vive
76  */
78 {
79  // Note! All the values in this struct are directly pasted in from the JSON values.
80  // As such, in my opinion, plus_x, plus_z and position are all "wrong" - all the code I've had to write that
81  // uses this struct flips the signs of plus_x, plus_z, and the signs of the X- and Z-components of position.
82  // I have no idea why those sign flips were necessary - I suppose Valve/HTC just made some weird decisions when
83  // making the config file schemas. I figure it would be very confusing to try to "fix" these values as I'm
84  // parsing them, so if you're writing code downstream of this, beware and expect the values in here to be
85  // exactly the same as those in the compressed JSON. -Moses
86  struct
87  {
88  struct xrt_vec3 plus_x;
89  struct xrt_vec3 plus_z;
90  struct xrt_vec3 position; // looks like from head pose
91  } extrinsics;
92 
93  //! Pose in tracking space.
94  struct xrt_pose trackref;
95 
96  //! Pose in head space.
97  struct xrt_pose headref;
98 
99  struct
100  {
101  double distortion[4]; // Kannala-Brandt
102  double center_x;
103  double center_y;
104 
105  double focal_x;
106  double focal_y;
107  struct xrt_size image_size_pixels;
108  } intrinsics;
109 };
110 
111 /*!
112  * A single lighthouse senosor point and normal, in IMU space.
113  *
114  * @ingroup aux_vive
115  */
116 struct lh_sensor
117 {
118  struct xrt_vec3 pos;
119  uint32_t _pad0;
120  struct xrt_vec3 normal;
121  uint32_t _pad1;
122 };
123 
124 /*!
125  * A lighthouse consisting of sensors.
126  *
127  * All sensors are placed in IMU space.
128  *
129  * @ingroup aux_vive
130  */
131 struct lh_model
132 {
133  struct lh_sensor *sensors;
134  size_t sensor_count;
135 };
136 
137 /*!
138  * headset config.
139  *
140  * @ingroup aux_vive
141  */
143 {
144  //! log level accessed by the config parser
146 
147  enum VIVE_VARIANT variant;
148 
149  struct
150  {
151  double acc_range;
152  double gyro_range;
153  struct xrt_vec3 acc_bias;
154  struct xrt_vec3 acc_scale;
155  struct xrt_vec3 gyro_bias;
156  struct xrt_vec3 gyro_scale;
157 
158  //! IMU position in tracking space.
159  struct xrt_pose trackref;
160  } imu;
161 
162  struct
163  {
164  double lens_separation;
165  double persistence;
166  int eye_target_height_in_pixels;
167  int eye_target_width_in_pixels;
168 
169  struct xrt_quat rot[2];
170 
171  //! Head position in tracking space.
172  struct xrt_pose trackref;
173  //! Head position in IMU space.
174  struct xrt_pose imuref;
175  } display;
176 
177  struct
178  {
179  uint32_t display_firmware_version;
180  uint32_t firmware_version;
181  uint8_t hardware_revision;
182  uint8_t hardware_version_micro;
183  uint8_t hardware_version_minor;
184  uint8_t hardware_version_major;
185  char mb_serial_number[32];
186  char model_number[32];
187  char device_serial_number[32];
188  } firmware;
189 
190  struct
191  {
192  struct u_vive_values values[2];
193  struct xrt_fov fov[2];
194  } distortion;
195 
196  struct
197  {
198  //! The two cameras.
199  struct index_camera view[2];
200 
201  //! Left view in right camera space.
202  struct xrt_pose left_in_right;
203 
204  //! The same but in OpenCV camera space.
205  struct xrt_pose opencv;
206 
207  //! Have we loaded the config.
208  bool valid;
209  } cameras;
210 
211  struct lh_model lh;
212 };
213 
214 /*!
215  * Controller config.
216  *
217  * @ingroup aux_vive
218  */
220 {
221  enum u_logging_level log_level;
222 
223  enum VIVE_CONTROLLER_VARIANT variant;
224 
225  struct
226  {
227  uint32_t firmware_version;
228  uint8_t hardware_revision;
229  uint8_t hardware_version_micro;
230  uint8_t hardware_version_minor;
231  uint8_t hardware_version_major;
232  char mb_serial_number[32];
233  char model_number[32];
234  char device_serial_number[32];
235  } firmware;
236 
237  struct
238  {
239  double acc_range;
240  double gyro_range;
241  struct xrt_vec3 acc_bias;
242  struct xrt_vec3 acc_scale;
243  struct xrt_vec3 gyro_bias;
244  struct xrt_vec3 gyro_scale;
245 
246  //! IMU position in tracking space.
247  struct xrt_pose trackref;
248  } imu;
249 };
250 
251 
252 /*
253  *
254  * Functions.
255  *
256  */
257 
258 /*!
259  * Parse a headset config.
260  *
261  * @ingroup aux_vive
262  */
263 bool
264 vive_config_parse(struct vive_config *d, char *json_string, enum u_logging_level log_level);
265 
266 /*!
267  * Free any allocated resources on this config.
268  *
269  * @ingroup aux_vive
270  */
271 void
272 vive_config_teardown(struct vive_config *config);
273 
274 /*!
275  * Parse a controller config.
276  *
277  * @ingroup aux_vive
278  */
279 bool
280 vive_config_parse_controller(struct vive_controller_config *d, char *json_string, enum u_logging_level log_level);
281 
282 
283 #ifdef __cplusplus
284 } // extern "C"
285 #endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
void vive_config_teardown(struct vive_config *config)
Free any allocated resources on this config.
Definition: vive_config.c:579
bool vive_config_parse(struct vive_config *d, char *json_string, enum u_logging_level log_level)
Parse a headset config.
Definition: vive_config.c:404
VIVE_CONTROLLER_VARIANT
Controller variant.
Definition: vive_config.h:61
bool vive_config_parse_controller(struct vive_controller_config *d, char *json_string, enum u_logging_level log_level)
Parse a controller config.
Definition: vive_config.c:596
VIVE_VARIANT
Headset variant.
Definition: vive_config.h:47
static Eigen::Map< const Eigen::Vector3f > position(const struct xrt_pose &pose)
Return a Eigen type wrapping a pose's position (const).
Definition: m_eigen_interop.hpp:217
A calibrated camera on an Index.
Definition: vive_config.h:78
struct xrt_pose headref
Pose in head space.
Definition: vive_config.h:97
struct xrt_pose trackref
Pose in tracking space.
Definition: vive_config.h:94
A lighthouse consisting of sensors.
Definition: vive_config.h:132
A single lighthouse senosor point and normal, in IMU space.
Definition: vive_config.h:117
Values to create a distortion mesh from Vive configuration values.
Definition: u_distortion_mesh.h:70
headset config.
Definition: vive_config.h:143
struct xrt_pose imuref
Head position in IMU space.
Definition: vive_config.h:174
bool valid
Have we loaded the config.
Definition: vive_config.h:208
enum u_logging_level log_level
log level accessed by the config parser
Definition: vive_config.h:145
struct xrt_pose opencv
The same but in OpenCV camera space.
Definition: vive_config.h:205
struct xrt_pose trackref
IMU position in tracking space.
Definition: vive_config.h:159
struct index_camera view[2]
The two cameras.
Definition: vive_config.h:199
struct xrt_pose left_in_right
Left view in right camera space.
Definition: vive_config.h:202
Controller config.
Definition: vive_config.h:220
struct xrt_pose trackref
IMU position in tracking space.
Definition: vive_config.h:247
Describes a projection matrix fov.
Definition: xrt_defines.h:486
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A quaternion with single floats.
Definition: xrt_defines.h:216
Image size.
Definition: xrt_defines.h:409
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Code to generate disortion meshes.
Basic logging functionality.
Header holding common defines.
Common defines and enums for XRT.