From 8e24dda794fd126f93504d114d0176f2a3214744 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 4 Sep 2020 14:37:50 +0100 Subject: [PATCH] xrt: Remove out_timestamp argument to xrt_device::get_tracked_pose --- doc/changes/xrt/mr.521.md | 3 +++ src/xrt/compositor/main/comp_renderer.c | 4 +--- src/xrt/drivers/arduino/arduino_device.c | 4 ---- src/xrt/drivers/daydream/daydream_device.c | 3 --- src/xrt/drivers/dummy/dummy_hmd.c | 4 ---- src/xrt/drivers/hdk/hdk_device.cpp | 2 -- src/xrt/drivers/hydra/hydra_driver.c | 2 -- src/xrt/drivers/north_star/ns_hmd.c | 5 ----- src/xrt/drivers/ohmd/oh_device.c | 8 ++------ src/xrt/drivers/psmv/psmv_driver.c | 3 --- src/xrt/drivers/psvr/psvr_device.c | 6 ------ src/xrt/drivers/realsense/rs_6dof.c | 4 ---- src/xrt/drivers/vive/vive_controller.c | 4 ---- src/xrt/drivers/vive/vive_device.c | 3 --- src/xrt/include/xrt/xrt_device.h | 14 ++++---------- src/xrt/ipc/ipc_client_device.c | 4 +--- src/xrt/ipc/ipc_client_hmd.c | 4 +--- src/xrt/ipc/ipc_server_client.c | 5 +---- src/xrt/ipc/proto.json | 1 - src/xrt/state_trackers/oxr/oxr_xdev.c | 3 +-- 20 files changed, 14 insertions(+), 72 deletions(-) create mode 100644 doc/changes/xrt/mr.521.md diff --git a/doc/changes/xrt/mr.521.md b/doc/changes/xrt/mr.521.md new file mode 100644 index 000000000..5cddf5ea5 --- /dev/null +++ b/doc/changes/xrt/mr.521.md @@ -0,0 +1,3 @@ +Remove the `out_timestamp` argument to the `xrt_device::get_tracked_pose` +function, it's not needed anymore and the devices can do prediction better +as it knows more about it's tracking system the the state tracker. diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index 4441166f7..1c0f3ac3c 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -399,11 +399,9 @@ static void _get_view_projection(struct comp_renderer *r) { struct xrt_space_relation relation; - uint64_t out_timestamp; xrt_device_get_tracked_pose(r->c->xdev, XRT_INPUT_GENERIC_HEAD_POSE, - r->c->last_frame_time_ns, &out_timestamp, - &relation); + r->c->last_frame_time_ns, &relation); struct xrt_vec3 eye_relation = { 0.063000f, /* TODO: get actual ipd_meters */ diff --git a/src/xrt/drivers/arduino/arduino_device.c b/src/xrt/drivers/arduino/arduino_device.c index d267dbe06..89a8b3f3c 100644 --- a/src/xrt/drivers/arduino/arduino_device.c +++ b/src/xrt/drivers/arduino/arduino_device.c @@ -359,16 +359,12 @@ static void arduino_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct arduino_device *ad = arduino_device(xdev); - uint64_t now = os_monotonic_get_ns(); - (void)at_timestamp_ns; arduino_get_fusion_pose(ad, name, out_relation); - *out_relation_timestamp_ns = now; } diff --git a/src/xrt/drivers/daydream/daydream_device.c b/src/xrt/drivers/daydream/daydream_device.c index 648afdec5..03b7105a3 100644 --- a/src/xrt/drivers/daydream/daydream_device.c +++ b/src/xrt/drivers/daydream/daydream_device.c @@ -323,15 +323,12 @@ static void daydream_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct daydream_device *daydream = daydream_device(xdev); - uint64_t now = os_monotonic_get_ns(); (void)at_timestamp_ns; daydream_get_fusion_pose(daydream, name, out_relation); - *out_relation_timestamp_ns = now; } diff --git a/src/xrt/drivers/dummy/dummy_hmd.c b/src/xrt/drivers/dummy/dummy_hmd.c index 5555c0c3d..9b874a8cc 100644 --- a/src/xrt/drivers/dummy/dummy_hmd.c +++ b/src/xrt/drivers/dummy/dummy_hmd.c @@ -110,7 +110,6 @@ static void dummy_hmd_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct dummy_hmd *dh = dummy_hmd(xdev); @@ -120,9 +119,6 @@ dummy_hmd_get_tracked_pose(struct xrt_device *xdev, return; } - uint64_t now = os_monotonic_get_ns(); - - *out_relation_timestamp_ns = now; out_relation->pose = dh->pose; out_relation->relation_flags = (enum xrt_space_relation_flags)( XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | diff --git a/src/xrt/drivers/hdk/hdk_device.cpp b/src/xrt/drivers/hdk/hdk_device.cpp index e5145499e..89b5d1d81 100644 --- a/src/xrt/drivers/hdk/hdk_device.cpp +++ b/src/xrt/drivers/hdk/hdk_device.cpp @@ -206,7 +206,6 @@ static void hdk_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t requested_timestamp_ns, - uint64_t *out_actual_timestamp_ns, struct xrt_space_relation *out_relation) { struct hdk_device *hd = hdk_device(xdev); @@ -220,7 +219,6 @@ hdk_device_get_tracked_pose(struct xrt_device *xdev, // Adjusting for latency - 14ms, found empirically. now -= 14000000; - *out_actual_timestamp_ns = now; if (!hd->quat_valid) { out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; diff --git a/src/xrt/drivers/hydra/hydra_driver.c b/src/xrt/drivers/hydra/hydra_driver.c index efad07984..aaa73f9c1 100644 --- a/src/xrt/drivers/hydra/hydra_driver.c +++ b/src/xrt/drivers/hydra/hydra_driver.c @@ -543,7 +543,6 @@ static void hydra_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct hydra_device *hd = hydra_device(xdev); @@ -551,7 +550,6 @@ hydra_device_get_tracked_pose(struct xrt_device *xdev, hydra_system_update(hs); - *out_relation_timestamp_ns = hs->report_time; out_relation->pose = hd->state.pose; //! @todo how do we report this is not (necessarily) the same base space diff --git a/src/xrt/drivers/north_star/ns_hmd.c b/src/xrt/drivers/north_star/ns_hmd.c index bb1ee8325..14951f43a 100644 --- a/src/xrt/drivers/north_star/ns_hmd.c +++ b/src/xrt/drivers/north_star/ns_hmd.c @@ -72,7 +72,6 @@ static void ns_hmd_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct ns_hmd *ns = ns_hmd(xdev); @@ -81,7 +80,6 @@ ns_hmd_get_tracked_pose(struct xrt_device *xdev, // If the tracking device is created use it. if (ns->tracker != NULL) { xrt_device_get_tracked_pose(ns->tracker, name, at_timestamp_ns, - out_relation_timestamp_ns, out_relation); return; } @@ -91,9 +89,6 @@ ns_hmd_get_tracked_pose(struct xrt_device *xdev, return; } - uint64_t now = os_monotonic_get_ns(); - - *out_relation_timestamp_ns = now; out_relation->pose = ns->pose; out_relation->relation_flags = (enum xrt_space_relation_flags)( XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | diff --git a/src/xrt/drivers/ohmd/oh_device.c b/src/xrt/drivers/ohmd/oh_device.c index 7eb0a603b..a56929665 100644 --- a/src/xrt/drivers/ohmd/oh_device.c +++ b/src/xrt/drivers/ohmd/oh_device.c @@ -64,7 +64,6 @@ static void oh_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct oh_device *ohd = oh_device(xdev); @@ -80,7 +79,6 @@ oh_device_get_tracked_pose(struct xrt_device *xdev, uint64_t now = os_monotonic_get_ns(); //! @todo adjust for latency here - *out_relation_timestamp_ns = now; ohmd_device_getf(ohd->dev, OHMD_ROTATION_QUAT, &quat.x); ohmd_device_getf(ohd->dev, OHMD_POSITION_VECTOR, &pos.x); out_relation->pose.orientation = quat; @@ -119,7 +117,6 @@ oh_device_get_tracked_pose(struct xrt_device *xdev, /*! @todo this is a hack - should really get a timestamp on the * USB data and use that instead. */ - *out_relation_timestamp_ns = ohd->last_update; *out_relation = ohd->last_relation; OH_SPEW(ohd, "GET_TRACKED_POSE - no new data"); return; @@ -131,8 +128,7 @@ oh_device_get_tracked_pose(struct xrt_device *xdev, */ if (ohd->enable_finite_difference && !have_ang_vel) { // No angular velocity - float dt = - time_ns_to_s(*out_relation_timestamp_ns - ohd->last_update); + float dt = time_ns_to_s(now - ohd->last_update); if (ohd->last_update == 0) { // This is the first report, so just print a warning // instead of estimating ang vel. @@ -165,7 +161,7 @@ oh_device_get_tracked_pose(struct xrt_device *xdev, } // Update state within driver - ohd->last_update = *out_relation_timestamp_ns; + ohd->last_update = now; ohd->last_relation = *out_relation; } diff --git a/src/xrt/drivers/psmv/psmv_driver.c b/src/xrt/drivers/psmv/psmv_driver.c index 5cbd48e29..55807ac6b 100644 --- a/src/xrt/drivers/psmv/psmv_driver.c +++ b/src/xrt/drivers/psmv/psmv_driver.c @@ -933,7 +933,6 @@ static void psmv_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct xrt_space_graph xgs = {0}; @@ -941,8 +940,6 @@ psmv_device_get_tracked_pose(struct xrt_device *xdev, psmv_device_get_space_graph(xdev, name, at_timestamp_ns, &xgs); m_space_graph_resolve(&xgs, out_relation); - - *out_relation_timestamp_ns = at_timestamp_ns; } static void diff --git a/src/xrt/drivers/psvr/psvr_device.c b/src/xrt/drivers/psvr/psvr_device.c index f9d06c28d..9cd510bcd 100644 --- a/src/xrt/drivers/psvr/psvr_device.c +++ b/src/xrt/drivers/psvr/psvr_device.c @@ -915,7 +915,6 @@ static void psvr_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct psvr_device *psvr = psvr_device(xdev); @@ -939,14 +938,9 @@ psvr_device_get_tracked_pose(struct xrt_device *xdev, out_relation->relation_flags = (enum xrt_space_relation_flags)( XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT); - - - *out_relation_timestamp_ns = os_monotonic_get_ns(); } else { xrt_tracked_psvr_get_tracked_pose( psvr->tracker, at_timestamp_ns, out_relation); - - *out_relation_timestamp_ns = at_timestamp_ns; } //! @todo Move this to the tracker. diff --git a/src/xrt/drivers/realsense/rs_6dof.c b/src/xrt/drivers/realsense/rs_6dof.c index 27a859760..768f7a50a 100644 --- a/src/xrt/drivers/realsense/rs_6dof.c +++ b/src/xrt/drivers/realsense/rs_6dof.c @@ -250,7 +250,6 @@ static void rs_6dof_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct rs_6dof *rs = rs_6dof(xdev); @@ -260,9 +259,6 @@ rs_6dof_get_tracked_pose(struct xrt_device *xdev, return; } - uint64_t now = os_monotonic_get_ns(); - *out_relation_timestamp_ns = now; - os_thread_helper_lock(&rs->oth); out_relation->pose = rs->pose; os_thread_helper_unlock(&rs->oth); diff --git a/src/xrt/drivers/vive/vive_controller.c b/src/xrt/drivers/vive/vive_controller.c index 9f3d8ba7f..79ec34a9e 100644 --- a/src/xrt/drivers/vive/vive_controller.c +++ b/src/xrt/drivers/vive/vive_controller.c @@ -322,7 +322,6 @@ static void vive_controller_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct vive_controller_device *d = vive_controller_device(xdev); @@ -339,9 +338,6 @@ vive_controller_device_get_tracked_pose(struct xrt_device *xdev, // Clear out the relation. U_ZERO(out_relation); - uint64_t now = os_monotonic_get_ns(); - *out_relation_timestamp_ns = now; - os_thread_helper_lock(&d->controller_thread); // Don't do anything if we have stopped. diff --git a/src/xrt/drivers/vive/vive_device.c b/src/xrt/drivers/vive/vive_device.c index b3aca726f..c1e4c9e6d 100644 --- a/src/xrt/drivers/vive/vive_device.c +++ b/src/xrt/drivers/vive/vive_device.c @@ -94,7 +94,6 @@ static void vive_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct vive_device *d = vive_device(xdev); @@ -109,8 +108,6 @@ vive_device_get_tracked_pose(struct xrt_device *xdev, //! @todo Use this properly. (void)at_timestamp_ns; - uint64_t when = os_monotonic_get_ns(); - *out_relation_timestamp_ns = when; os_thread_helper_lock(&d->sensors_thread); diff --git a/src/xrt/include/xrt/xrt_device.h b/src/xrt/include/xrt/xrt_device.h index 997245829..a2b4db635 100644 --- a/src/xrt/include/xrt/xrt_device.h +++ b/src/xrt/include/xrt/xrt_device.h @@ -237,11 +237,9 @@ struct xrt_device void (*update_inputs)(struct xrt_device *xdev); /*! - * Get relationship of a tracked device to the device "base space". - * - * Right now the base space is assumed to be local space. - * - * This is very very WIP and will need to be made a lot more advanced. + * Get relationship of a tracked device to the tracking origin space as + * the base space. It is the responsibility of the device driver to do + * any prediction, there are helper functions available for this. * * The timestamps are system monotonic timestamps, such as returned by * os_monotonic_get_ns(). @@ -253,8 +251,6 @@ struct xrt_device * @param[in] at_timestamp_ns If the device can predict or has a history * of positions, this is when the caller * wants the pose to be from. - * @param[out] out_relation_timestamp_ns Timestamp when this relation - * was captured. * @param[out] out_relation The relation read from the device. * * @see xrt_input_name @@ -262,7 +258,6 @@ struct xrt_device void (*get_tracked_pose)(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation); /*! @@ -327,11 +322,10 @@ static inline void xrt_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t requested_timestamp_ns, - uint64_t *out_actual_timestamp_ns, struct xrt_space_relation *out_relation) { xdev->get_tracked_pose(xdev, name, requested_timestamp_ns, - out_actual_timestamp_ns, out_relation); + out_relation); } /*! diff --git a/src/xrt/ipc/ipc_client_device.c b/src/xrt/ipc/ipc_client_device.c index ffbf43084..80bc20b27 100644 --- a/src/xrt/ipc/ipc_client_device.c +++ b/src/xrt/ipc/ipc_client_device.c @@ -93,14 +93,12 @@ static void ipc_client_device_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct ipc_client_device *icd = ipc_client_device(xdev); xrt_result_t r = ipc_call_device_get_tracked_pose( - icd->ipc_c, icd->device_id, name, at_timestamp_ns, - out_relation_timestamp_ns, out_relation); + icd->ipc_c, icd->device_id, name, at_timestamp_ns, out_relation); if (r != XRT_SUCCESS) { IPC_DEBUG(icd->ipc_c, "IPC: Error sending input update!"); } diff --git a/src/xrt/ipc/ipc_client_hmd.c b/src/xrt/ipc/ipc_client_hmd.c index d118d39e3..6d1c1170f 100644 --- a/src/xrt/ipc/ipc_client_hmd.c +++ b/src/xrt/ipc/ipc_client_hmd.c @@ -93,14 +93,12 @@ static void ipc_client_hmd_get_tracked_pose(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, - uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation) { struct ipc_client_hmd *ich = ipc_client_hmd(xdev); xrt_result_t r = ipc_call_device_get_tracked_pose( - ich->ipc_c, ich->device_id, name, at_timestamp_ns, - out_relation_timestamp_ns, out_relation); + ich->ipc_c, ich->device_id, name, at_timestamp_ns, out_relation); if (r != XRT_SUCCESS) { IPC_DEBUG(ich->ipc_c, "IPC: Error calling tracked pose!"); } diff --git a/src/xrt/ipc/ipc_server_client.c b/src/xrt/ipc/ipc_server_client.c index 291a8725a..3a746805b 100644 --- a/src/xrt/ipc/ipc_server_client.c +++ b/src/xrt/ipc/ipc_server_client.c @@ -558,7 +558,6 @@ ipc_handle_device_get_tracked_pose(volatile struct ipc_client_state *ics, uint32_t id, enum xrt_input_name name, uint64_t at_timestamp, - uint64_t *out_timestamp, struct xrt_space_relation *out_relation) { @@ -581,7 +580,6 @@ ipc_handle_device_get_tracked_pose(volatile struct ipc_client_state *ics, // We have been disabled but the client hasn't called update. if (disabled && active_on_client) { U_ZERO(out_relation); - *out_timestamp = at_timestamp; return XRT_SUCCESS; } @@ -590,8 +588,7 @@ ipc_handle_device_get_tracked_pose(volatile struct ipc_client_state *ics, } // Get the pose. - xrt_device_get_tracked_pose(xdev, name, at_timestamp, out_timestamp, - out_relation); + xrt_device_get_tracked_pose(xdev, name, at_timestamp, out_relation); return XRT_SUCCESS; } diff --git a/src/xrt/ipc/proto.json b/src/xrt/ipc/proto.json index e32c96eab..327e58bb5 100644 --- a/src/xrt/ipc/proto.json +++ b/src/xrt/ipc/proto.json @@ -176,7 +176,6 @@ {"name": "at_timestamp", "type": "uint64_t"} ], "out": [ - {"name": "timestamp", "type": "uint64_t"}, {"name": "relation", "type": "struct xrt_space_relation"} ] }, diff --git a/src/xrt/state_trackers/oxr/oxr_xdev.c b/src/xrt/state_trackers/oxr/oxr_xdev.c index 944ff22b8..36f9359c6 100644 --- a/src/xrt/state_trackers/oxr/oxr_xdev.c +++ b/src/xrt/state_trackers/oxr/oxr_xdev.c @@ -93,10 +93,9 @@ oxr_xdev_get_space_graph(struct oxr_logger *log, // Convert at_time to monotonic and give to device. uint64_t at_timestamp_ns = time_state_ts_to_monotonic_ns(inst->timekeeping, at_time); - uint64_t dummy = 0; struct xrt_space_relation *rel = m_space_graph_reserve(xsg); - xrt_device_get_tracked_pose(xdev, name, at_timestamp_ns, &dummy, rel); + xrt_device_get_tracked_pose(xdev, name, at_timestamp_ns, rel); // Add in the offset from the tracking system. m_space_graph_add_pose(xsg, &xdev->tracking_origin->offset);