mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
d/vive: Implement 3DoF/SLAM switching button and pose offset
This commit is contained in:
parent
f0ceb40f6a
commit
13d90bff77
|
@ -117,7 +117,12 @@ vive_device_get_3dof_tracked_pose(struct xrt_device *xdev,
|
||||||
m_relation_history_get(d->fusion.relation_hist, at_timestamp_ns, &relation);
|
m_relation_history_get(d->fusion.relation_hist, at_timestamp_ns, &relation);
|
||||||
os_mutex_unlock(&d->fusion.mutex);
|
os_mutex_unlock(&d->fusion.mutex);
|
||||||
|
|
||||||
|
relation.relation_flags = XRT_SPACE_RELATION_BITMASK_ALL; // Needed after history_get
|
||||||
|
relation.pose.position = d->pose.position;
|
||||||
|
relation.linear_velocity = (struct xrt_vec3){0, 0, 0};
|
||||||
|
|
||||||
*out_relation = relation;
|
*out_relation = relation;
|
||||||
|
d->pose = out_relation->pose;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Specific pose corrections for Basalt and a Valve Index headset
|
//! Specific pose corrections for Basalt and a Valve Index headset
|
||||||
|
@ -174,6 +179,7 @@ vive_device_get_tracked_pose(struct xrt_device *xdev,
|
||||||
} else {
|
} else {
|
||||||
vive_device_get_3dof_tracked_pose(xdev, name, at_timestamp_ns, out_relation);
|
vive_device_get_3dof_tracked_pose(xdev, name, at_timestamp_ns, out_relation);
|
||||||
}
|
}
|
||||||
|
math_pose_transform(&d->offset, &out_relation->pose, &out_relation->pose);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -757,11 +763,40 @@ vive_sensors_run_thread(void *ptr)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vive_device_switch_hmd_tracker(void *d_ptr)
|
||||||
|
{
|
||||||
|
DRV_TRACE_MARKER();
|
||||||
|
|
||||||
|
struct vive_device *d = (struct vive_device *)d_ptr;
|
||||||
|
d->slam_over_3dof = !d->slam_over_3dof;
|
||||||
|
struct u_var_button *btn = &d->gui.switch_tracker_btn;
|
||||||
|
|
||||||
|
if (d->slam_over_3dof) { // Use SLAM
|
||||||
|
snprintf(btn->label, sizeof(btn->label), "Switch to 3DoF Tracking");
|
||||||
|
} else { // Use 3DoF
|
||||||
|
snprintf(btn->label, sizeof(btn->label), "Switch to SLAM Tracking");
|
||||||
|
os_mutex_lock(&d->fusion.mutex);
|
||||||
|
m_imu_3dof_reset(&d->fusion.i3dof);
|
||||||
|
d->fusion.i3dof.rot = d->pose.orientation;
|
||||||
|
os_mutex_unlock(&d->fusion.mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vive_device_setup_ui(struct vive_device *d)
|
vive_device_setup_ui(struct vive_device *d)
|
||||||
{
|
{
|
||||||
u_var_add_root(d, "Vive Device", true);
|
u_var_add_root(d, "Vive Device", true);
|
||||||
|
|
||||||
|
u_var_add_gui_header(d, NULL, "Tracking");
|
||||||
|
if (d->tracking.slam_enabled) {
|
||||||
|
d->gui.switch_tracker_btn.cb = vive_device_switch_hmd_tracker;
|
||||||
|
d->gui.switch_tracker_btn.ptr = d;
|
||||||
|
u_var_add_button(d, &d->gui.switch_tracker_btn, "Switch to 3DoF Tracking");
|
||||||
|
}
|
||||||
|
u_var_add_pose(d, &d->pose, "Tracked Pose");
|
||||||
|
u_var_add_pose(d, &d->offset, "Pose Offset");
|
||||||
|
|
||||||
u_var_add_gui_header(d, &d->gui.fusion, "3DoF Tracking");
|
u_var_add_gui_header(d, &d->gui.fusion, "3DoF Tracking");
|
||||||
m_imu_3dof_add_vars(&d->fusion.i3dof, d, "");
|
m_imu_3dof_add_vars(&d->fusion.i3dof, d, "");
|
||||||
u_var_add_gui_header(d, &d->gui.calibration, "Calibration");
|
u_var_add_gui_header(d, &d->gui.calibration, "Calibration");
|
||||||
|
@ -965,6 +1000,9 @@ vive_device_create(struct os_hid_device *mainboard_dev,
|
||||||
os_thread_helper_init(&d->sensors_thread);
|
os_thread_helper_init(&d->sensors_thread);
|
||||||
os_thread_helper_init(&d->watchman_thread);
|
os_thread_helper_init(&d->watchman_thread);
|
||||||
|
|
||||||
|
d->pose = (struct xrt_pose)XRT_POSE_IDENTITY;
|
||||||
|
d->offset = (struct xrt_pose)XRT_POSE_IDENTITY;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (watchman_dev != NULL) {
|
if (watchman_dev != NULL) {
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
#include "xrt/xrt_device.h"
|
#include "xrt/xrt_device.h"
|
||||||
#include "os/os_threading.h"
|
#include "os/os_threading.h"
|
||||||
#include "util/u_logging.h"
|
#include "util/u_logging.h"
|
||||||
#include "util/u_distortion_mesh.h"
|
#include "util/u_time.h"
|
||||||
|
#include "util/u_var.h"
|
||||||
#include "math/m_imu_3dof.h"
|
#include "math/m_imu_3dof.h"
|
||||||
#include "math/m_relation_history.h"
|
#include "math/m_relation_history.h"
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ struct vive_device
|
||||||
{
|
{
|
||||||
bool calibration;
|
bool calibration;
|
||||||
bool fusion;
|
bool fusion;
|
||||||
|
struct u_var_button switch_tracker_btn;
|
||||||
char hand_status[128];
|
char hand_status[128];
|
||||||
char slam_status[128];
|
char slam_status[128];
|
||||||
} gui;
|
} gui;
|
||||||
|
@ -98,7 +100,11 @@ struct vive_device
|
||||||
//! Whether to track the HMD with 6dof SLAM or fallback to the 3dof tracker
|
//! Whether to track the HMD with 6dof SLAM or fallback to the 3dof tracker
|
||||||
bool slam_over_3dof;
|
bool slam_over_3dof;
|
||||||
|
|
||||||
|
//! Last tracked pose
|
||||||
struct xrt_pose pose;
|
struct xrt_pose pose;
|
||||||
|
|
||||||
|
//! Additional offset to apply to `pose`
|
||||||
|
struct xrt_pose offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue