From 2d8c5002ec2938dbc51de1fc1c22730a25485994 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 24 Jan 2026 11:23:17 +0100 Subject: [PATCH] Add WIVRN_DUMP_* vars for dumping tracking data --- server/driver/pose_list.cpp | 48 +++++++++++++++++++++++++++++++++++++ server/driver/pose_list.h | 19 +++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/server/driver/pose_list.cpp b/server/driver/pose_list.cpp index 74c7f155..d4179106 100644 --- a/server/driver/pose_list.cpp +++ b/server/driver/pose_list.cpp @@ -24,9 +24,11 @@ #include "math/m_eigen_interop.hpp" #include "math/m_space.h" #include "math/m_vec3.h" +#include "os/os_time.h" #include "xrt/xrt_defines.h" #include #include +#include #include using namespace xrt::auxiliary::math; @@ -90,6 +92,14 @@ xrt_space_relation pose_list::extrapolate(const xrt_space_relation & a, const xr return res; } +pose_list::pose_list(wivrn::device_id id) : device(id) +{ + if (auto dump = std::getenv("WIVRN_DUMP"); dump and dump == std::string_view("list")) + std::cerr << "WIVRN_DUMP_" << magic_enum::enum_name(id) << std::endl; + if (auto dump = std::getenv(std::format("WIVRN_DUMP_{}", magic_enum::enum_name(id)).c_str())) + dumper.emplace(dump); +} + void pose_list::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) { if (source) @@ -192,6 +202,25 @@ void pose_list::add_sample(XrTime production_timestamp, XrTime timestamp, const std::lock_guard lock(mutex); positions.add_sample(position); orientations.add_sample(orientation); + + if (dumper) + { + debug_data item{ + .in = true, + .production_timestamp = production_timestamp, + .timestamp = timestamp, + .now = os_monotonic_get_ns(), + }; + if (position.y) + Eigen::Map>(item.position.data()) = *position.y; + if (position.dy) + Eigen::Map>(item.dposition.data()) = *position.dy; + if (orientation.y) + Eigen::Map>(item.orientation.data()) = *orientation.y; + if (orientation.dy) + Eigen::Map>(item.dorientation.data()) = *orientation.dy; + dumper->write(item); + } } std::pair pose_list::get_at(XrTime at_timestamp_ns) @@ -257,6 +286,25 @@ std::pair pose_list::get_at(XrTime at_timestamp_ns) } } + if (dumper) + { + debug_data item{ + .in = false, + .production_timestamp = position.production_timestamp, + .timestamp = at_timestamp_ns, + .now = os_monotonic_get_ns(), + }; + if (position.y) + Eigen::Map>(item.position.data()) = *position.y; + if (position.dy) + Eigen::Map>(item.dposition.data()) = *position.dy; + if (orientation.y) + Eigen::Map>(item.orientation.data()) = *orientation.y; + if (orientation.dy) + Eigen::Map>(item.dorientation.data()) = *orientation.dy; + dumper->write(item); + } + return {position.production_timestamp, ret}; } diff --git a/server/driver/pose_list.h b/server/driver/pose_list.h index b3664510..d64151a8 100644 --- a/server/driver/pose_list.h +++ b/server/driver/pose_list.h @@ -20,10 +20,12 @@ #pragma once #include "polynomial_interpolator.h" +#include "utils/csv_logger.h" #include "wivrn_packets.h" #include "xrt/xrt_defines.h" #include +#include namespace wivrn { @@ -39,14 +41,27 @@ class pose_list polynomial_interpolator<3> positions; polynomial_interpolator<4, true> orientations; + struct debug_data + { + bool in; // true: received data, false: data request + XrTime production_timestamp; + XrTime timestamp; + XrTime now; + std::array position; + std::array dposition; + std::array orientation; + std::array dorientation; + }; + + std::optional> dumper; + public: const wivrn::device_id device; 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); void update_tracking(const wivrn::from_headset::tracking &, const clock_offset & offset); void set_derived(pose_list * source, xrt_pose offset, bool force = false);