From db4a50410c059f3c3109a05641a1cab246c50cdb Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Thu, 2 Sep 2021 19:18:53 -0500 Subject: [PATCH] d/survive: Use hand tracking if there aren't any controllers rebase-survive --- src/xrt/drivers/CMakeLists.txt | 4 +++ src/xrt/drivers/survive/survive_driver.c | 35 ++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt index 649979140..61138f705 100644 --- a/src/xrt/drivers/CMakeLists.txt +++ b/src/xrt/drivers/CMakeLists.txt @@ -277,6 +277,10 @@ if (XRT_BUILD_DRIVER_SURVIVE) add_library(drv_survive STATIC ${SURVIVE_SOURCE_FILES}) target_link_libraries(drv_survive PRIVATE xrt-interfaces aux_os aux_util aux_math aux_vive PkgConfig::SURVIVE) list(APPEND ENABLED_HEADSET_DRIVERS survive) + + if (XRT_BUILD_DRIVER_HANDTRACKING) + target_link_libraries(drv_survive PRIVATE drv_ht) + endif() endif() if(XRT_BUILD_DRIVER_ANDROID) diff --git a/src/xrt/drivers/survive/survive_driver.c b/src/xrt/drivers/survive/survive_driver.c index 8a87b1dfb..f03388344 100644 --- a/src/xrt/drivers/survive/survive_driver.c +++ b/src/xrt/drivers/survive/survive_driver.c @@ -5,6 +5,7 @@ * @brief Adapter to Libsurvive. * @author Christoph Haag * @author Jakob Bornecrantz + * @author Moses Turner * @ingroup drv_survive */ @@ -17,6 +18,7 @@ #include #include "math/m_api.h" +#include "tracking/t_tracking.h" #include "xrt/xrt_device.h" #include "util/u_debug.h" #include "util/u_device.h" @@ -28,7 +30,7 @@ #include "os/os_threading.h" -#include "../auxiliary/os/os_time.h" +#include "os/os_time.h" #include "xrt/xrt_prober.h" #include "survive_interface.h" @@ -43,6 +45,11 @@ #include "math/m_predict.h" #include "vive/vive_config.h" + +#include "../ht/ht_interface.h" +#include "../multi_wrapper/multi.h" +#include "xrt/xrt_config_drivers.h" + #include "survive_driver.h" // reading usb config takes libsurvive about 50ms per device @@ -1333,6 +1340,8 @@ survive_device_autoprobe(struct xrt_auto_prober *xap, out_xdevs[out_idx++] = &ss->hmd->base; } + bool found_controllers = false; + for (int i = 0; i < MAX_TRACKED_DEVICE_COUNT; i++) { if (out_idx == XRT_MAX_DEVICES_PER_PROBE - 1) { @@ -1343,9 +1352,32 @@ survive_device_autoprobe(struct xrt_auto_prober *xap, if (ss->controllers[i] != NULL) { out_xdevs[out_idx++] = &ss->controllers[i]->base; + found_controllers = true; } } +#ifdef XRT_BUILD_DRIVER_HANDTRACKING + // We want to hit this codepath when we find a HMD but no controllers. + if ((ss->hmd != NULL) && !found_controllers) { + struct t_stereo_camera_calibration *cal = NULL; + + struct xrt_pose head_in_left_cam; + vive_get_stereo_camera_calibration(&ss->hmd->hmd.config, &cal, &head_in_left_cam); + + struct xrt_device *ht = ht_device_create(xp, cal); + if (ht != NULL) { // Returns NULL if there's a problem and the hand tracker can't start. By no means a + // fatal error. + struct xrt_device *wrap = + multi_create_tracking_override(XRT_TRACKING_OVERRIDE_ATTACHED, ht, &ss->hmd->base, + XRT_INPUT_GENERIC_HEAD_POSE, &head_in_left_cam); + out_xdevs[out_idx++] = wrap; + } + // Don't need it anymore. And it's not even created unless we hit this codepath, which is somewhat hard. + t_stereo_camera_calibration_reference(&cal, NULL); + } +#endif + + survive_already_initialized = true; // Mutex before thread. @@ -1368,6 +1400,5 @@ survive_device_autoprobe(struct xrt_auto_prober *xap, } return 0; } - return out_idx; }