mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-17 19:20:13 +00:00
aux/math: use int64_t for timestamps in m_relation_history
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2298>
This commit is contained in:
parent
e298244516
commit
ae7dca3107
src/xrt
auxiliary
drivers/steamvr_lh
tests
|
@ -37,7 +37,7 @@ namespace os = xrt::auxiliary::os;
|
||||||
struct relation_history_entry
|
struct relation_history_entry
|
||||||
{
|
{
|
||||||
struct xrt_space_relation relation;
|
struct xrt_space_relation relation;
|
||||||
uint64_t timestamp;
|
int64_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr size_t BufLen = 4096;
|
static constexpr size_t BufLen = 4096;
|
||||||
|
@ -57,7 +57,7 @@ m_relation_history_create(struct m_relation_history **rh_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation const *in_relation, uint64_t timestamp)
|
m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation const *in_relation, int64_t timestamp)
|
||||||
{
|
{
|
||||||
XRT_TRACE_MARKER();
|
XRT_TRACE_MARKER();
|
||||||
struct relation_history_entry rhe;
|
struct relation_history_entry rhe;
|
||||||
|
@ -82,7 +82,7 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation
|
||||||
|
|
||||||
enum m_relation_history_result
|
enum m_relation_history_result
|
||||||
m_relation_history_get(const struct m_relation_history *rh,
|
m_relation_history_get(const struct m_relation_history *rh,
|
||||||
uint64_t at_timestamp_ns,
|
int64_t at_timestamp_ns,
|
||||||
struct xrt_space_relation *out_relation)
|
struct xrt_space_relation *out_relation)
|
||||||
{
|
{
|
||||||
XRT_TRACE_MARKER();
|
XRT_TRACE_MARKER();
|
||||||
|
@ -99,7 +99,7 @@ m_relation_history_get(const struct m_relation_history *rh,
|
||||||
// Find the first element *not less than* our value. the lambda we pass is the comparison
|
// Find the first element *not less than* our value. the lambda we pass is the comparison
|
||||||
// function, to compare against timestamps.
|
// function, to compare against timestamps.
|
||||||
const auto it =
|
const auto it =
|
||||||
std::lower_bound(b, e, at_timestamp_ns, [](const relation_history_entry &rhe, uint64_t timestamp) {
|
std::lower_bound(b, e, at_timestamp_ns, [](const relation_history_entry &rhe, int64_t timestamp) {
|
||||||
return rhe.timestamp < timestamp;
|
return rhe.timestamp < timestamp;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -183,11 +183,11 @@ m_relation_history_get(const struct m_relation_history *rh,
|
||||||
bool
|
bool
|
||||||
m_relation_history_estimate_motion(struct m_relation_history *rh,
|
m_relation_history_estimate_motion(struct m_relation_history *rh,
|
||||||
const struct xrt_space_relation *in_relation,
|
const struct xrt_space_relation *in_relation,
|
||||||
uint64_t timestamp,
|
int64_t timestamp,
|
||||||
struct xrt_space_relation *out_relation)
|
struct xrt_space_relation *out_relation)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint64_t last_time_ns;
|
int64_t last_time_ns;
|
||||||
struct xrt_space_relation last_relation;
|
struct xrt_space_relation last_relation;
|
||||||
if (!m_relation_history_get_latest(rh, &last_time_ns, &last_relation)) {
|
if (!m_relation_history_get_latest(rh, &last_time_ns, &last_relation)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -229,7 +229,7 @@ m_relation_history_estimate_motion(struct m_relation_history *rh,
|
||||||
|
|
||||||
bool
|
bool
|
||||||
m_relation_history_get_latest(const struct m_relation_history *rh,
|
m_relation_history_get_latest(const struct m_relation_history *rh,
|
||||||
uint64_t *out_time_ns,
|
int64_t *out_time_ns,
|
||||||
struct xrt_space_relation *out_relation)
|
struct xrt_space_relation *out_relation)
|
||||||
{
|
{
|
||||||
std::unique_lock<os::Mutex> lock(rh->mutex);
|
std::unique_lock<os::Mutex> lock(rh->mutex);
|
||||||
|
|
|
@ -60,9 +60,7 @@ m_relation_history_create(struct m_relation_history **rh);
|
||||||
* @public @memberof m_relation_history
|
* @public @memberof m_relation_history
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
m_relation_history_push(struct m_relation_history *rh,
|
m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation const *in_relation, int64_t timestamp);
|
||||||
struct xrt_space_relation const *in_relation,
|
|
||||||
uint64_t timestamp);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Interpolates or extrapolates to the desired timestamp.
|
* Interpolates or extrapolates to the desired timestamp.
|
||||||
|
@ -74,7 +72,7 @@ m_relation_history_push(struct m_relation_history *rh,
|
||||||
*/
|
*/
|
||||||
enum m_relation_history_result
|
enum m_relation_history_result
|
||||||
m_relation_history_get(const struct m_relation_history *rh,
|
m_relation_history_get(const struct m_relation_history *rh,
|
||||||
uint64_t at_timestamp_ns,
|
int64_t at_timestamp_ns,
|
||||||
struct xrt_space_relation *out_relation);
|
struct xrt_space_relation *out_relation);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -90,7 +88,7 @@ m_relation_history_get(const struct m_relation_history *rh,
|
||||||
bool
|
bool
|
||||||
m_relation_history_estimate_motion(struct m_relation_history *rh,
|
m_relation_history_estimate_motion(struct m_relation_history *rh,
|
||||||
const struct xrt_space_relation *in_relation,
|
const struct xrt_space_relation *in_relation,
|
||||||
uint64_t timestamp,
|
int64_t timestamp,
|
||||||
struct xrt_space_relation *out_relation);
|
struct xrt_space_relation *out_relation);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -106,7 +104,7 @@ m_relation_history_estimate_motion(struct m_relation_history *rh,
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
m_relation_history_get_latest(const struct m_relation_history *rh,
|
m_relation_history_get_latest(const struct m_relation_history *rh,
|
||||||
uint64_t *out_time_ns,
|
int64_t *out_time_ns,
|
||||||
struct xrt_space_relation *out_relation);
|
struct xrt_space_relation *out_relation);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -178,7 +176,7 @@ public:
|
||||||
* @copydoc m_relation_history_push
|
* @copydoc m_relation_history_push
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
push(xrt_space_relation const &relation, uint64_t ts) noexcept
|
push(xrt_space_relation const &relation, int64_t ts) noexcept
|
||||||
{
|
{
|
||||||
return m_relation_history_push(mPtr, &relation, ts);
|
return m_relation_history_push(mPtr, &relation, ts);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +185,7 @@ public:
|
||||||
* @copydoc m_relation_history_get
|
* @copydoc m_relation_history_get
|
||||||
*/
|
*/
|
||||||
Result
|
Result
|
||||||
get(uint64_t at_time_ns, xrt_space_relation *out_relation) const noexcept
|
get(int64_t at_time_ns, xrt_space_relation *out_relation) const noexcept
|
||||||
{
|
{
|
||||||
return m_relation_history_get(mPtr, at_time_ns, out_relation);
|
return m_relation_history_get(mPtr, at_time_ns, out_relation);
|
||||||
}
|
}
|
||||||
|
@ -196,7 +194,7 @@ public:
|
||||||
* @copydoc m_relation_history_get_latest
|
* @copydoc m_relation_history_get_latest
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
get_latest(uint64_t *out_time_ns, xrt_space_relation *out_relation) const noexcept
|
get_latest(int64_t *out_time_ns, xrt_space_relation *out_relation) const noexcept
|
||||||
{
|
{
|
||||||
return m_relation_history_get_latest(mPtr, out_time_ns, out_relation);
|
return m_relation_history_get_latest(mPtr, out_time_ns, out_relation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -762,7 +762,7 @@ flush_poses(TrackerSlam &t)
|
||||||
|
|
||||||
// Last relation
|
// Last relation
|
||||||
xrt_space_relation lr = XRT_SPACE_RELATION_ZERO;
|
xrt_space_relation lr = XRT_SPACE_RELATION_ZERO;
|
||||||
uint64_t lts;
|
int64_t lts;
|
||||||
t.slam_rels.get_latest(<s, &lr);
|
t.slam_rels.get_latest(<s, &lr);
|
||||||
xrt_vec3 lpos = lr.pose.position;
|
xrt_vec3 lpos = lr.pose.position;
|
||||||
xrt_quat lrot = lr.pose.orientation;
|
xrt_quat lrot = lr.pose.orientation;
|
||||||
|
@ -907,7 +907,7 @@ predict_pose(TrackerSlam &t, timepoint_ns when_ns, struct xrt_space_relation *ou
|
||||||
|
|
||||||
// Get last relation computed purely from SLAM data
|
// Get last relation computed purely from SLAM data
|
||||||
xrt_space_relation rel{};
|
xrt_space_relation rel{};
|
||||||
uint64_t rel_ts;
|
int64_t rel_ts;
|
||||||
bool empty = !t.slam_rels.get_latest(&rel_ts, &rel);
|
bool empty = !t.slam_rels.get_latest(&rel_ts, &rel);
|
||||||
|
|
||||||
// Stop if there is no previous relation to use for prediction
|
// Stop if there is no previous relation to use for prediction
|
||||||
|
|
|
@ -146,11 +146,11 @@ const std::unordered_map<std::string_view, InputClass> controller_classes{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t
|
int64_t
|
||||||
chrono_timestamp_ns()
|
chrono_timestamp_ns()
|
||||||
{
|
{
|
||||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
||||||
uint64_t ts = std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
int64_t ts = std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ ControllerDevice::update_hand_tracking(struct xrt_hand_joint_set *out)
|
||||||
auto curl_values = u_hand_tracking_curl_values{pinky, ring, middle, index, thumb};
|
auto curl_values = u_hand_tracking_curl_values{pinky, ring, middle, index, thumb};
|
||||||
|
|
||||||
struct xrt_space_relation hand_relation = {};
|
struct xrt_space_relation hand_relation = {};
|
||||||
uint64_t ts = chrono_timestamp_ns();
|
int64_t ts = chrono_timestamp_ns();
|
||||||
m_relation_history_get_latest(relation_hist, &ts, &hand_relation);
|
m_relation_history_get_latest(relation_hist, &ts, &hand_relation);
|
||||||
|
|
||||||
u_hand_sim_simulate_for_valve_index_knuckles(&curl_values, get_xrt_hand(), &hand_relation, out);
|
u_hand_sim_simulate_for_valve_index_knuckles(&curl_values, get_xrt_hand(), &hand_relation, out);
|
||||||
|
|
|
@ -57,7 +57,7 @@ TEST_CASE("m_relation_history")
|
||||||
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
||||||
|
|
||||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||||
uint64_t out_time = 0;
|
int64_t out_time = 0;
|
||||||
|
|
||||||
CHECK(m_relation_history_get_size(rh) == 0);
|
CHECK(m_relation_history_get_size(rh) == 0);
|
||||||
CHECK_FALSE(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
CHECK_FALSE(m_relation_history_get_latest(rh, &out_time, &out_relation));
|
||||||
|
@ -152,7 +152,7 @@ TEST_CASE("RelationHistory")
|
||||||
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
||||||
|
|
||||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||||
uint64_t out_time = 0;
|
int64_t out_time = 0;
|
||||||
|
|
||||||
CHECK(rh.size() == 0);
|
CHECK(rh.size() == 0);
|
||||||
CHECK_FALSE(rh.get_latest(&out_time, &out_relation));
|
CHECK_FALSE(rh.get_latest(&out_time, &out_relation));
|
||||||
|
|
Loading…
Reference in a new issue