The open source OpenXR runtime
at prediction-2 165 lines 4.0 kB view raw
1// Copyright 2019-2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief vive device header 6 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 7 * @ingroup drv_vive 8 */ 9 10#pragma once 11 12#include "xrt/xrt_device.h" 13#include "os/os_threading.h" 14#include "util/u_logging.h" 15#include "util/u_debug.h" 16#include "util/u_time.h" 17#include "util/u_var.h" 18#include "math/m_imu_3dof.h" 19#include "math/m_relation_history.h" 20 21#include "vive/vive_config.h" 22 23#include "vive_lighthouse.h" 24#include "xrt/xrt_tracking.h" 25 26#ifdef __cplusplus 27extern "C" { 28#endif 29 30/*! 31 * @implements xrt_device 32 */ 33struct vive_device 34{ 35 struct xrt_device base; 36 struct os_hid_device *mainboard_dev; 37 struct os_hid_device *sensors_dev; 38 struct os_hid_device *watchman_dev; 39 40 struct lighthouse_watchman watchman; 41 42 struct os_thread_helper sensors_thread; 43 struct os_thread_helper watchman_thread; 44 struct os_thread_helper mainboard_thread; 45 46 struct 47 { 48 timepoint_ns last_sample_ts_ns; 49 uint32_t last_sample_ticks; 50 uint8_t sequence; 51 } imu; 52 53 struct 54 { 55 uint16_t ipd; 56 uint16_t lens_separation; 57 uint16_t proximity; 58 uint8_t button; 59 uint8_t audio_button; 60 } board; 61 62 enum u_logging_level log_level; 63 bool disconnect_notified; 64 65 struct 66 { 67 struct u_var_button switch_tracker_btn; 68 char hand_status[128]; 69 char slam_status[128]; 70 } gui; 71 72 struct vive_config config; 73 74 struct 75 { 76 //! Protects all members of the `fusion` substruct. 77 struct os_mutex mutex; 78 79 //! Main fusion calculator. 80 struct m_imu_3dof i3dof; 81 82 //! Prediction 83 struct m_relation_history *relation_hist; 84 } fusion; 85 86 //! Fields related to camera-based tracking (SLAM and hand tracking) 87 struct 88 { 89 //! SLAM tracker. 90 struct xrt_tracked_slam *slam; 91 92 //! Set at start. Whether the SLAM tracker was initialized. 93 bool slam_enabled; 94 95 //! Set at start. Whether the hand tracker was initialized. 96 bool hand_enabled; 97 98 //! SLAM systems track the IMU pose, enabling this corrects it to middle of the eyes 99 bool imu2me; 100 } tracking; 101 102 /*! 103 * Offset for tracked pose offsets (applies to both fusion and SLAM). 104 * Applied when getting the tracked poses, so is effectively a offset 105 * to increase or decrease prediction. 106 */ 107 struct u_var_draggable_f32 tracked_offset_ms; 108 109 struct xrt_pose P_imu_me; //!< IMU to head/display/middle-of-eyes transform in OpenXR coords 110 111 //! Whether to track the HMD with 6dof SLAM or fallback to the 3dof tracker 112 bool slam_over_3dof; 113 114 //! In charge of managing raw samples, redirects them for tracking 115 struct vive_source *source; 116 117 //! Last tracked pose 118 struct xrt_pose pose; 119 120 //! Additional offset to apply to `pose` 121 struct xrt_pose offset; 122}; 123 124 125/*! 126 * Summary of the status of various trackers. 127 * 128 * @todo Creation flow is a bit broken for now, in the future this info should be closer 129 * to the tracker creation code, thus avoiding the need to pass it around like this. 130 */ 131struct vive_tracking_status 132{ 133 bool slam_wanted; 134 bool slam_supported; 135 bool slam_enabled; 136 137 //! Has Monado been built with the correct libraries to do optical hand tracking? 138 bool hand_supported; 139 140 //! Did we find controllers? 141 bool controllers_found; 142 143 //! If this is set to ON, we always do optical hand tracking even if controllers were found. 144 //! If this is set to AUTO, we do optical hand tracking only if no controllers were found. 145 //! If this is set to OFF, we don't do optical hand tracking. 146 enum debug_tristate_option hand_wanted; 147 148 //! Computed in target_builder_lighthouse.c based on the past three 149 bool hand_enabled; 150}; 151 152void 153vive_set_trackers_status(struct vive_device *d, struct vive_tracking_status status); 154 155struct vive_device * 156vive_device_create(struct os_hid_device *mainboard_dev, 157 struct os_hid_device *sensors_dev, 158 struct os_hid_device *watchman_dev, 159 enum VIVE_VARIANT variant, 160 struct vive_tracking_status tstatus, 161 struct vive_source *vs); 162 163#ifdef __cplusplus 164} 165#endif