xrt: Expand tracking interface

This commit is contained in:
Jakob Bornecrantz 2019-06-24 19:06:45 +01:00
parent 65eeb19939
commit 387bc123f8
8 changed files with 237 additions and 33 deletions

View file

@ -240,7 +240,7 @@ u_device_allocate(enum u_device_alloc_flags flags,
// Tracking
size_t offset_tracking = total_size;
total_size += alloc_tracking ? sizeof(struct xrt_tracking) : 0;
total_size += alloc_tracking ? sizeof(struct xrt_tracking_origin) : 0;
// Do the allocation
char* ptr = U_TYPED_ARRAY_CALLOC(char, total_size);
@ -261,11 +261,12 @@ u_device_allocate(enum u_device_alloc_flags flags,
}
if (alloc_tracking) {
xdev->tracking = (struct xrt_tracking*)(ptr + offset_tracking);
xdev->tracking->type = XRT_TRACKING_TYPE_NONE;
xdev->tracking->offset.orientation.w = 1.0f;
snprintf(xdev->tracking->name, XRT_TRACKING_NAME_LEN, "%s",
"No tracking");
xdev->tracking_origin =
(struct xrt_tracking_origin*)(ptr + offset_tracking);
xdev->tracking_origin->type = XRT_TRACKING_TYPE_NONE;
xdev->tracking_origin->offset.orientation.w = 1.0f;
snprintf(xdev->tracking_origin->name, XRT_TRACKING_NAME_LEN,
"%s", "No tracking");
}
return xdev;

View file

@ -153,7 +153,7 @@ struct hydra_device;
*/
struct hydra_system
{
struct xrt_tracking base;
struct xrt_tracking_origin base;
struct os_hid_device *data_hid;
struct os_hid_device *command_hid;
@ -229,7 +229,7 @@ hydra_device(struct xrt_device *xdev)
}
static inline struct hydra_system *
hydra_system(struct xrt_tracking *xtrack)
hydra_system(struct xrt_tracking_origin *xtrack)
{
assert(xtrack);
struct hydra_system *ret = (struct hydra_system *)xtrack;
@ -493,7 +493,7 @@ hydra_device_update_inputs(struct xrt_device *xdev,
struct time_state *timekeeping)
{
struct hydra_device *hd = hydra_device(xdev);
struct hydra_system *hs = hydra_system(xdev->tracking);
struct hydra_system *hs = hydra_system(xdev->tracking_origin);
hydra_system_update(hs, timekeeping);
@ -542,7 +542,7 @@ hydra_device_get_tracked_pose(struct xrt_device *xdev,
struct xrt_space_relation *out_relation)
{
struct hydra_device *hd = hydra_device(xdev);
struct hydra_system *hs = hydra_system(xdev->tracking);
struct hydra_system *hs = hydra_system(xdev->tracking_origin);
hydra_system_update(hs, timekeeping);
@ -566,7 +566,7 @@ hydra_device_get_tracked_pose(struct xrt_device *xdev,
static void
hydra_system_remove_child(struct hydra_system *hs, struct hydra_device *hd)
{
assert(hydra_system(hd->base.tracking) == hs);
assert(hydra_system(hd->base.tracking_origin) == hs);
assert(hd->index == 0 || hd->index == 1);
// Make the device not point to the system
@ -611,7 +611,7 @@ static void
hydra_device_destroy(struct xrt_device *xdev)
{
struct hydra_device *hd = hydra_device(xdev);
struct hydra_system *hs = hydra_system(xdev->tracking);
struct hydra_system *hs = hydra_system(xdev->tracking_origin);
hydra_system_remove_child(hs, hd);
@ -668,8 +668,8 @@ hydra_found(struct xrt_prober *xp,
hs->devs[1] = U_DEVICE_ALLOCATE(struct hydra_device, flags, 10, 0);
// Populate the "tracking" member with the system.
hs->devs[0]->base.tracking = &(hs->base);
hs->devs[1]->base.tracking = &(hs->base);
hs->devs[0]->base.tracking_origin = &(hs->base);
hs->devs[1]->base.tracking_origin = &(hs->base);
hs->report_counter = -1;
hs->refs = 2;

View file

@ -189,7 +189,7 @@ struct xrt_device
struct xrt_hmd_parts *hmd;
//! Always set, pointing to the tracking system for this device.
struct xrt_tracking *tracking;
struct xrt_tracking_origin *tracking_origin;
//! Number of inputs.
size_t num_inputs;

View file

@ -28,6 +28,7 @@ struct xrt_fs;
struct xrt_frame_context;
struct xrt_prober;
struct xrt_prober_device;
struct xrt_tracking_factory;
/*!
* The maximum number of devices that a single "found" function called by the
@ -139,6 +140,9 @@ typedef void (*xrt_prober_list_video_cb)(struct xrt_prober *xp,
*/
struct xrt_prober
{
//! Factory for producing tracked objects.
struct xrt_tracking_factory *tracking;
int (*probe)(struct xrt_prober *xp);
int (*dump)(struct xrt_prober *xp);
int (*select)(struct xrt_prober *xp,

View file

@ -12,25 +12,43 @@
#define XRT_TRACKING_NAME_LEN 256
#include "xrt/xrt_defines.h"
#include "util/u_time.h"
#ifdef __cplusplus
extern "C" {
#endif
struct time_state;
struct time_state;
struct xrt_device;
struct xrt_tracking;
struct xrt_tracking_factory;
struct xrt_tracked_psmv;
struct xrt_tracked_psvr;
/*!
* @ingroup xrt_iface
* @{
*/
/*!
* What kind of tracking system is this.
*
* @todo Is none, Colour, IR, Magnetic the kind of type we need to know about?
*/
enum xrt_tracking_type
{
// The device(s) are never tracked.
XRT_TRACKING_TYPE_NONE,
// The device(s) are tracked by RGB camera(s).
XRT_TRACKING_TYPE_RGB,
};
/*!
* A tracking system or device origin.
*
* @ingroup xrt_iface
*/
struct xrt_tracking
struct xrt_tracking_origin
{
//! For debugging.
char name[XRT_TRACKING_NAME_LEN];
@ -45,6 +63,185 @@ struct xrt_tracking
struct xrt_pose offset;
};
/*!
* Tracking factory.
*/
struct xrt_tracking_factory
{
//! Internal frame context, exposed for debugging purposes.
struct xrt_frame_context *xfctx;
/*!
* Create a tracked PSMV ball.
*/
int (*create_tracked_psmv)(struct xrt_tracking_factory *,
struct xrt_device *xdev,
struct xrt_tracked_psmv **out_psmv);
/*!
* Create a tracked PSVR ball.
*/
int (*create_tracked_psvr)(struct xrt_tracking_factory *,
struct xrt_device *xdev,
struct xrt_tracked_psvr **out_psvr);
};
/*!
* IMU Sample.
*/
struct xrt_tracking_sample
{
struct xrt_vec3 accel_m_s2;
struct xrt_vec3 gyro_rad_secs;
};
/*!
* A single tracked PS Move controller, camera and ball are not synced.
*
* @todo How do we communicate ball colour change?
*/
struct xrt_tracked_psmv
{
//! The tracking system origin for this ball.
struct xrt_tracking_origin *origin;
//! Device owning this ball.
struct xrt_device *xdev;
//! Colour of the ball.
struct xrt_colour_rgb_f32 colour;
/*!
* Push a IMU sample into the tracking system.
*/
void (*push_imu)(struct xrt_tracked_psmv *,
time_duration_ns delta_ns,
struct xrt_tracking_sample *sample);
/*!
* Called by the owning @ref xrt_device @ref xdev to get the pose of
* the ball in the tracking space at the given time.
*
* @todo Should we add a out_time argument as a way to signal min and
* maximum, and as such only do interpelation between different captured
* frames.
*/
void (*get_tracked_pose)(struct xrt_tracked_psmv *,
struct time_state *timekeeper,
timepoint_ns when_ns,
struct xrt_space_relation *out_relation);
/*!
* Destroy this tracked ball.
*/
void (*destroy)(struct xrt_tracked_psmv *);
};
/*!
* A tracked PSVR headset.
*
* @todo How do we communicate led lighting status?
*/
struct xrt_tracked_psvr
{
//! The tracking system origin for this ball.
struct xrt_tracking_origin *origin;
//! Device owning this ball.
struct xrt_device *xdev;
/*!
* Push a IMU sample into the tracking system.
*/
void (*push_imu)(struct xrt_tracked_psvr *,
time_duration_ns delta_ns,
struct xrt_tracking_sample *sample);
/*!
* Called by the owning @ref xrt_device @ref xdev to get the pose of
* the psvr in the tracking space at the given time.
*/
void (*get_tracked_pose)(struct xrt_tracked_psvr *,
struct time_state *timekeeper,
timepoint_ns when_ns,
struct xrt_space_relation *out_relation);
/*!
* Destroy this tracked psvr.
*/
void (*destroy)(struct xrt_tracked_psvr *);
};
/*
*
* Helper functions.
*
*/
static inline void
xrt_tracked_psmv_get_tracked_pose(struct xrt_tracked_psmv *psmv,
struct time_state *timekeeper,
timepoint_ns when_ns,
struct xrt_space_relation *out_relation)
{
psmv->get_tracked_pose(psmv, timekeeper, when_ns, out_relation);
}
static inline void
xrt_tracked_psmv_push_imu(struct xrt_tracked_psmv *psmv,
time_duration_ns delta_ns,
struct xrt_tracking_sample *sample)
{
psmv->push_imu(psmv, delta_ns, sample);
}
static inline void
xrt_tracked_psmv_destroy(struct xrt_tracked_psmv **xtmv_ptr)
{
struct xrt_tracked_psmv *xtmv = *xtmv_ptr;
if (xtmv == NULL) {
return;
}
xtmv->destroy(xtmv);
*xtmv_ptr = NULL;
}
static inline void
xrt_tracked_psvr_get_tracked_pose(struct xrt_tracked_psvr *psvr,
struct time_state *timekeeper,
timepoint_ns when_ns,
struct xrt_space_relation *out_relation)
{
psvr->get_tracked_pose(psvr, timekeeper, when_ns, out_relation);
}
static inline void
xrt_tracked_psvr_push_imu(struct xrt_tracked_psvr *psvr,
time_duration_ns delta_ns,
struct xrt_tracking_sample *sample)
{
psvr->push_imu(psvr, delta_ns, sample);
}
static inline void
xrt_tracked_psvr_destroy(struct xrt_tracked_psvr **xtvr_ptr)
{
struct xrt_tracked_psvr *xtvr = *xtvr_ptr;
if (xtvr == NULL) {
return;
}
xtvr->destroy(xtvr);
*xtvr_ptr = NULL;
}
/*!
* @}
*/
#ifdef __cplusplus
}

View file

@ -164,7 +164,7 @@ oxr_session_get_view_pose_at(struct oxr_logger *log,
// get at least a slightly better position.
struct xrt_device *xdev = sess->sys->head;
struct xrt_pose *offset = &xdev->tracking->offset;
struct xrt_pose *offset = &xdev->tracking_origin->offset;
struct xrt_space_relation relation;
int64_t timestamp;

View file

@ -117,23 +117,25 @@ oxr_system_fill_in(struct oxr_logger *log,
" failed to probe device");
}
if (head->tracking->type == XRT_TRACKING_TYPE_NONE) {
if (head->tracking_origin->type == XRT_TRACKING_TYPE_NONE) {
// "nominal height" 1.6m
head->tracking->offset.position.x = 0.0f;
head->tracking->offset.position.y = 1.6f;
head->tracking->offset.position.z = 0.0f;
head->tracking_origin->offset.position.x = 0.0f;
head->tracking_origin->offset.position.y = 1.6f;
head->tracking_origin->offset.position.z = 0.0f;
}
if (left != NULL && left->tracking->type == XRT_TRACKING_TYPE_NONE) {
left->tracking->offset.position.x = -0.2f;
left->tracking->offset.position.y = 1.3f;
left->tracking->offset.position.z = -0.5f;
if (left != NULL &&
left->tracking_origin->type == XRT_TRACKING_TYPE_NONE) {
left->tracking_origin->offset.position.x = -0.2f;
left->tracking_origin->offset.position.y = 1.3f;
left->tracking_origin->offset.position.z = -0.5f;
}
if (right != NULL && right->tracking->type == XRT_TRACKING_TYPE_NONE) {
right->tracking->offset.position.x = 0.2f;
right->tracking->offset.position.y = 1.3f;
right->tracking->offset.position.z = -0.5f;
if (right != NULL &&
right->tracking_origin->type == XRT_TRACKING_TYPE_NONE) {
right->tracking_origin->offset.position.x = 0.2f;
right->tracking_origin->offset.position.y = 1.3f;
right->tracking_origin->offset.position.z = -0.5f;
}
// clang-format off

View file

@ -83,7 +83,7 @@ oxr_xdev_get_pose_at(struct oxr_logger *log,
struct xrt_pose *pose,
int64_t *timestamp)
{
struct xrt_pose *offset = &xdev->tracking->offset;
struct xrt_pose *offset = &xdev->tracking_origin->offset;
struct xrt_space_relation relation;
U_ZERO(&relation);