Implement derived poses

Client can describe a pose to be derived from an other one, for instance
AIM can be derived from GRIP by applying an offset and rotation.
This reduces the amount of data that needs to be polled and transmitted
over the network.
This commit is contained in:
Patrick Nicolas
2025-01-31 15:35:28 +01:00
parent 8449e7eafc
commit a6c64f297d
10 changed files with 157 additions and 30 deletions
+3
View File
@@ -1180,6 +1180,9 @@ void scenes::stream::on_xr_event(const xr::event & event)
.view_index = uint8_t(event.visibility_mask_changed.viewIndex),
});
break;
case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED:
on_interaction_profile_changed(event.interaction_profile_changed);
break;
default:
break;
}
+2
View File
@@ -179,6 +179,8 @@ private:
void tracking();
void read_actions();
void on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &);
void setup(const to_headset::video_stream_description &);
void setup_reprojection_swapchain();
void exit();
+49
View File
@@ -198,6 +198,8 @@ void scenes::stream::tracking()
const bool hand_tracking = config.check_feature(feature::hand_tracking);
const bool face_tracking = config.check_feature(feature::face_tracking);
on_interaction_profile_changed({});
while (not exiting)
{
try
@@ -368,3 +370,50 @@ void scenes::stream::operator()(to_headset::tracking_control && packet)
tracking_control = packet;
tracking_control.min_offset = std::min(tracking_control.min_offset, tracking_control.max_offset);
}
void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged & event)
{
auto now = instance.now();
for (auto [target, space]: {
std::tuple{device_id::LEFT_AIM, application::space(xr::spaces::aim_left)},
{device_id::LEFT_PALM, application::space(xr::spaces::palm_left)},
{device_id::RIGHT_AIM, application::space(xr::spaces::aim_right)},
{device_id::RIGHT_PALM, application::space(xr::spaces::palm_right)},
})
{
device_id source;
XrSpace source_space = XR_NULL_HANDLE;
switch (target)
{
case device_id::LEFT_AIM:
case device_id::LEFT_PALM:
source = device_id::LEFT_GRIP;
source_space = application::space(xr::spaces::grip_left);
break;
case device_id::RIGHT_AIM:
case device_id::RIGHT_PALM:
source = device_id::RIGHT_GRIP;
source_space = application::space(xr::spaces::grip_right);
break;
default:
continue;
}
auto pose = locate_space(target, space, source_space, now);
if (pose.flags & from_headset::tracking::position_valid and pose.flags & from_headset::tracking::orientation_valid)
{
network_session->send_control(from_headset::derived_pose{
.source = source,
.target = target,
.relation = pose.pose,
});
}
else
{
network_session->send_control(from_headset::derived_pose{
.source = target,
.target = target,
});
}
}
}
+8
View File
@@ -215,6 +215,13 @@ struct trackings
std::vector<tracking> items;
};
struct derived_pose
{
device_id source;
device_id target;
XrPosef relation;
};
struct hand_tracking
{
enum flags : uint8_t
@@ -308,6 +315,7 @@ using packets = std::variant<
handshake,
tracking,
trackings,
derived_pose,
hand_tracking,
inputs,
timesync_response,
+32 -3
View File
@@ -65,18 +65,47 @@ xrt_space_relation pose_list::extrapolate(const xrt_space_relation & a, const xr
bool pose_list::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
std::shared_lock lock(derived_mutex);
if (source)
return false;
for (const auto & pose: tracking.device_poses)
{
if (pose.device != device)
continue;
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 add_sample(tracking.production_timestamp, tracking.timestamp, convert_pose(pose), offset);
}
return true;
}
void pose_list::set_derived(pose_list * source, xrt_pose offset, bool force)
{
std::lock_guard lock(derived_mutex);
if (derive_forced and not force)
return;
// TODO: check for loops?
if (source == this)
this->source = nullptr;
else
this->source = source;
this->offset = offset;
this->derive_forced = force;
}
std::tuple<std::chrono::nanoseconds, xrt_space_relation, device_id> pose_list::get_pose_at(XrTime at_timestamp_ns)
{
std::shared_lock lock(derived_mutex);
if (source)
{
auto res = source->get_pose_at(at_timestamp_ns);
math_pose_transform(&std::get<1>(res).pose, &offset, &std::get<1>(res).pose);
return res;
}
return std::tuple_cat(get_at(at_timestamp_ns), std::make_tuple(device));
}
xrt_space_relation pose_list::convert_pose(const from_headset::tracking::pose & pose)
{
xrt_space_relation res{};
+12 -4
View File
@@ -23,24 +23,32 @@
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
#include <shared_mutex>
namespace wivrn
{
struct clock_offset;
class pose_list : public history<pose_list, xrt_space_relation>
{
std::shared_mutex derived_mutex;
pose_list * source = nullptr;
xrt_pose offset;
bool derive_forced = false;
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, xrt_quat rotation_quat = XRT_QUAT_IDENTITY) :
device(id),
rotation_offset(rotation_quat) {}
pose_list(wivrn::device_id id) :
device(id) {}
bool update_tracking(const wivrn::from_headset::tracking &, const clock_offset & offset);
void set_derived(pose_list * source, xrt_pose offset, bool force = false);
std::tuple<std::chrono::nanoseconds, xrt_space_relation, device_id> get_pose_at(XrTime at_timestamp_ns);
static xrt_space_relation convert_pose(const wivrn::from_headset::tracking::pose &);
};
+43 -23
View File
@@ -19,6 +19,7 @@
#include "wivrn_controller.h"
#include "configuration.h"
#include "driver/xrt_cast.h"
#include "math/m_api.h"
#include "wivrn_session.h"
@@ -219,28 +220,13 @@ static std::ofstream & tracking_dump()
return res;
}
static auto make_palm(int hand_id, bool palm_pose)
{
if (auto grip_surface = configuration::read_user_configuration().grip_surface)
{
std::array<float, 3> angles = grip_surface.value();
float deg_2_rad = std::numbers::pi / 180.0;
xrt_vec3 rotation_angles{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(make_palm(hand_id, cnx->get_info().palm_pose)),
palm(hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM),
joints(hand_id),
cnx(cnx)
{
@@ -300,7 +286,20 @@ 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 or palm.device == grip.device;
inputs[WIVRN_CONTROLLER_PALM_POSE].active = cnx->get_info().palm_pose;
if (auto grip_surface = configuration::read_user_configuration().grip_surface)
{
std::array<float, 3> angles = grip_surface.value();
float deg_2_rad = std::numbers::pi / 180.0;
xrt_vec3 rotation_angles{angles[0] * deg_2_rad, angles[1] * deg_2_rad, angles[2] * deg_2_rad};
xrt_pose offset = XRT_POSE_IDENTITY;
math_quat_from_euler_angles(&rotation_angles, &offset.orientation);
palm.set_derived(&grip, offset, true);
cnx->set_enabled(palm.device, false);
inputs[WIVRN_CONTROLLER_PALM_POSE].active = true;
}
output_count = 1;
outputs = &haptic_output;
@@ -401,19 +400,20 @@ xrt_space_relation wivrn_controller::get_tracked_pose(xrt_input_name name, int64
{
std::chrono::nanoseconds extrapolation_time;
xrt_space_relation res;
device_id device;
switch (name)
{
case XRT_INPUT_TOUCH_AIM_POSE:
std::tie(extrapolation_time, res) = aim.get_at(at_timestamp_ns);
cnx->set_enabled(aim.device, true);
std::tie(extrapolation_time, res, device) = aim.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_TOUCH_GRIP_POSE:
std::tie(extrapolation_time, res) = grip.get_at(at_timestamp_ns);
cnx->set_enabled(grip.device, true);
std::tie(extrapolation_time, res, device) = grip.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_GENERIC_PALM_POSE:
std::tie(extrapolation_time, res) = palm.get_at(at_timestamp_ns);
cnx->set_enabled(palm.device, true);
std::tie(extrapolation_time, res, device) = palm.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
default:
U_LOG_W("Unknown input name requested");
@@ -462,6 +462,26 @@ std::pair<xrt_hand_joint_set, int64_t> wivrn_controller::get_hand_tracking(xrt_i
}
}
void wivrn_controller::set_derived_pose(const from_headset::derived_pose & derived)
{
auto list = [this](device_id id) -> pose_list * {
for (auto item: {&grip, &aim, &palm})
{
if (item->device == id)
return item;
}
return nullptr;
};
auto source = list(derived.source);
auto target = list(derived.target);
if (source and target)
{
target->set_derived(source, xrt_cast(derived.relation));
if (source != target)
cnx->set_enabled(derived.target, false);
}
}
void wivrn_controller::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
if (not aim.update_tracking(tracking, offset))
+1
View File
@@ -62,6 +62,7 @@ public:
void set_inputs(const from_headset::inputs &, const clock_offset &);
void set_derived_pose(const from_headset::derived_pose &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
void update_hand_tracking(const from_headset::hand_tracking &, const clock_offset &);
+6
View File
@@ -326,6 +326,12 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
fb_face2_tracker->update_tracking(tracking, offset);
}
void wivrn_session::operator()(from_headset::derived_pose && derived)
{
left_hand.set_derived_pose(derived);
right_hand.set_derived_pose(derived);
}
void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
{
auto offset = offset_est.get_offset();
+1
View File
@@ -153,6 +153,7 @@ public:
void operator()(from_headset::handshake &&) {}
void operator()(from_headset::trackings &&);
void operator()(const from_headset::tracking &);
void operator()(from_headset::derived_pose &&);
void operator()(from_headset::hand_tracking &&);
void operator()(from_headset::inputs &&);
void operator()(from_headset::timesync_response &&);