From 217dee2ce3b55913a14e7b08eed0915c843ea9b3 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 2 Dec 2021 15:11:11 -0600 Subject: [PATCH] a/math: Add m_relation_history_result return from m_relation_history_get --- src/xrt/auxiliary/math/m_relation_history.cpp | 9 +++- src/xrt/auxiliary/math/m_relation_history.h | 46 ++++++++++++++----- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/xrt/auxiliary/math/m_relation_history.cpp b/src/xrt/auxiliary/math/m_relation_history.cpp index 3dc67eb1a..ad3d2501a 100644 --- a/src/xrt/auxiliary/math/m_relation_history.cpp +++ b/src/xrt/auxiliary/math/m_relation_history.cpp @@ -80,11 +80,13 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation os_mutex_unlock(&rh->mutex); } -void +enum m_relation_history_result m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation *out_relation, uint64_t at_timestamp_ns) { XRT_TRACE_MARKER(); os_mutex_lock(&rh->mutex); + m_relation_history_result ret = M_RELATION_HISTORY_RESULT_INVALID; + if (rh->has_first_sample == 0) { // Do nothing. You push nothing to the buffer you get nothing from the buffer. goto end; @@ -104,6 +106,7 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation U_LOG_T("Extrapolating %f s after the head of the buffer!", delta_s); m_predict_relation(&rh->impl[0]->relation, delta_s, out_relation); + ret = M_RELATION_HISTORY_RESULT_PREDICTED; goto end; } else if (at_timestamp_ns < oldest_in_buffer) { @@ -114,6 +117,8 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation double delta_s = time_ns_to_s(diff_prediction_ns); U_LOG_T("Extrapolating %f s before the tail of the buffer!", delta_s); m_predict_relation(&rh->impl[rh->impl.length() - 1]->relation, delta_s, out_relation); + ret = M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED; + goto end; } U_LOG_T("Interpolating within buffer!"); @@ -196,9 +201,11 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation m_vec3_lerp(before.angular_velocity, after.angular_velocity, amount_to_lerp); out_relation->linear_velocity = m_vec3_lerp(before.linear_velocity, after.linear_velocity, amount_to_lerp); + ret = M_RELATION_HISTORY_RESULT_INTERPOLATED; } end: os_mutex_unlock(&rh->mutex); + return ret; } void diff --git a/src/xrt/auxiliary/math/m_relation_history.h b/src/xrt/auxiliary/math/m_relation_history.h index 0ae3be083..f275788a5 100644 --- a/src/xrt/auxiliary/math/m_relation_history.h +++ b/src/xrt/auxiliary/math/m_relation_history.h @@ -7,44 +7,68 @@ * @author Moses Turner * @ingroup drv_ht */ +#pragma once #include "xrt/xrt_defines.h" -struct m_relation_history; #ifdef __cplusplus extern "C" { #endif -/*! - * Creates an opaque relation_history object. +/** + * @brief Opaque type for storing the history of a space relation in a ring buffer * * @ingroup aux_util */ +struct m_relation_history; + +/** + * @brief Describes how the resulting space relation for the desired time stamp was generated. + * + * @relates m_relation_history + */ +enum m_relation_history_result +{ + M_RELATION_HISTORY_RESULT_INVALID = 0, //!< The supplied timestamp was invalid (0) or buffer was empty + M_RELATION_HISTORY_RESULT_EXACT, //!< The exact desired timestamp was found + M_RELATION_HISTORY_RESULT_INTERPOLATED, //!< The desired timestamp was between two entries + M_RELATION_HISTORY_RESULT_PREDICTED, //!< The desired timestamp was newer than the most recent entry + M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED, //!< The desired timestamp was older than the oldest entry +}; + +/*! + * @brief Creates an opaque relation_history object. + * + * @public @memberof m_relation_history + */ void m_relation_history_create(struct m_relation_history **rh); /*! - * Pushes a new pose to the history - if the history is full, it will also pop a pose out of the other side of the - * buffer. + * Pushes a new pose to the history. * - * @ingroup aux_util + * If the history is full, it will also pop a pose out of the other side of the buffer. + * + * @public @memberof m_relation_history */ void m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation *in_relation, uint64_t ts); /*! - * Interpolates or extrapolates to the desired timestamp. Read-only operation - doesn't remove anything from the buffer - * or anything like that - you can call this as often as you want. + * @brief Interpolates or extrapolates to the desired timestamp. * - * @ingroup aux_util + * Read-only operation - doesn't remove anything from the buffer or anything like that - you can call this as often as + * you want. + * + * @public @memberof m_relation_history */ -void +enum m_relation_history_result m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation *out_relation, uint64_t at_time_ns); /*! * Destroys an opaque relation_history object. * - * @ingroup aux_util + * @public @memberof m_relation_history */ void m_relation_history_destroy(struct m_relation_history **rh);