From 30b38bd3e9579a0be57b33c70dad915981cbe975 Mon Sep 17 00:00:00 2001 From: Mylah Date: Wed, 29 Jan 2025 15:48:44 -0600 Subject: [PATCH] Add an option for palm from grip --- server/driver/configuration.cpp | 5 +++++ server/driver/configuration.h | 1 + server/driver/pose_list.cpp | 5 ++++- server/driver/pose_list.h | 6 ++++-- server/driver/wivrn_controller.cpp | 29 +++++++++++++++++++++++++++-- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 23b0ed28..c4a7ef03 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -110,6 +110,11 @@ configuration configuration::read_user_configuration() result.scale = *it; } + if (auto it = json.find("grip-surface"); it != json.end()) + { + result.grip_surface = *it; + } + if (auto it = json.find("bitrate"); it != json.end()) result.bitrate = *it; diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 60bfd9c8..20bfe01e 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -55,6 +55,7 @@ struct configuration std::optional encoder_passthrough; std::optional bitrate; std::optional> scale; + std::optional> grip_surface; std::vector application; bool tcp_only = false; service_publication publication = service_publication::avahi; diff --git a/server/driver/pose_list.cpp b/server/driver/pose_list.cpp index 1e9435fe..4c146d3e 100644 --- a/server/driver/pose_list.cpp +++ b/server/driver/pose_list.cpp @@ -18,6 +18,7 @@ */ #include "pose_list.h" +#include "math/m_api.h" #include "math/m_eigen_interop.hpp" #include "math/m_space.h" #include "math/m_vec3.h" @@ -69,7 +70,9 @@ bool pose_list::update_tracking(const from_headset::tracking & tracking, const c if (pose.device != device) continue; - return add_sample(tracking.production_timestamp, tracking.timestamp, convert_pose(pose), offset); + xrt_space_relation new_pose = convert_pose(pose); + math_quat_rotate(&new_pose.pose.orientation, &rotation_offset, &new_pose.pose.orientation); + return add_sample(tracking.production_timestamp, tracking.timestamp, new_pose, offset); } return true; } diff --git a/server/driver/pose_list.h b/server/driver/pose_list.h index 225ca361..2749e9d6 100644 --- a/server/driver/pose_list.h +++ b/server/driver/pose_list.h @@ -31,12 +31,14 @@ class pose_list : public history { public: const wivrn::device_id device; + const xrt_quat rotation_offset; static xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t); static xrt_space_relation extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t); - pose_list(wivrn::device_id id) : - device(id) {} + pose_list(wivrn::device_id id, xrt_quat rotation_quat = xrt_quat{0.0, 0.0, 0.0, 1.0}) : + device(id), + rotation_offset(rotation_quat) {} bool update_tracking(const wivrn::from_headset::tracking &, const clock_offset & offset); diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp index 99498d17..bee27d8f 100644 --- a/server/driver/wivrn_controller.cpp +++ b/server/driver/wivrn_controller.cpp @@ -18,10 +18,15 @@ */ #include "wivrn_controller.h" +#include "configuration.h" +#include "math/m_api.h" #include "wivrn_session.h" #include "util/u_logging.h" +#include #include +#include +#include #include #include @@ -214,13 +219,33 @@ static std::ofstream & tracking_dump() return res; } +static auto make_palm(int hand_id, bool palm_pose) +{ + std::optional> grip_surface = configuration::read_user_configuration().grip_surface; + if (palm_pose && !grip_surface) + { + return pose_list((hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM)); + } + else if (grip_surface) + { + std::array angles = grip_surface.value(); + float deg_2_rad = std::numbers::pi / 180.0; + xrt_vec3 rotation_angles = xrt_vec3{angles[0] * deg_2_rad, angles[1] * deg_2_rad, angles[2] * deg_2_rad}; + xrt_quat rotation_quat = XRT_QUAT_IDENTITY; + math_quat_from_euler_angles(&rotation_angles, &rotation_quat); + + return pose_list((hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP), rotation_quat); + } + return pose_list((hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM)); +} + wivrn_controller::wivrn_controller(int hand_id, xrt_device * hmd, wivrn::wivrn_session * cnx) : xrt_device{}, grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP), aim(hand_id == 0 ? device_id::LEFT_AIM : device_id::RIGHT_AIM), - palm(hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM), + palm(make_palm(hand_id, cnx->get_info().palm_pose)), joints(hand_id), cnx(cnx) { @@ -280,7 +305,7 @@ wivrn_controller::wivrn_controller(int hand_id, inputs[WIVRN_CONTROLLER_HAND_TRACKER].active = hand_tracking_supported; inputs[WIVRN_CONTROLLER_PALM_POSE].name = XRT_INPUT_GENERIC_PALM_POSE; - inputs[WIVRN_CONTROLLER_PALM_POSE].active = cnx->get_info().palm_pose; + inputs[WIVRN_CONTROLLER_PALM_POSE].active = cnx->get_info().palm_pose or palm.device == grip.device; output_count = 1; outputs = &haptic_output;