Monado OpenXR Runtime
rift_s_tracker.h
Go to the documentation of this file.
1/*
2 * Copyright 2013, Fredrik Hultin.
3 * Copyright 2013, Jakob Bornecrantz.
4 * Copyright 2016 Philipp Zabel
5 * Copyright 2019-2022 Jan Schmidt
6 * SPDX-License-Identifier: BSL-1.0
7 */
8
9/*!
10 * @file
11 * @brief HMD tracker handling
12 * @author Jan Schmidt <jan@centricular.com>
13 * @ingroup drv_rift_s
14 */
15
16#pragma once
17
18#include "math/m_imu_3dof.h"
19#include "os/os_threading.h"
20#include "util/u_var.h"
21#include "xrt/xrt_defines.h"
22#include "xrt/xrt_device.h"
23
24#include "tracking/t_tracking.h"
25
26#include "rift_s_firmware.h"
27
28/* Oculus Rift S HMD Tracking */
29#ifndef RIFT_S_TRACKER_H
30#define RIFT_S_TRACKER_H
31
33
34enum rift_s_tracker_pose
35{
36 RIFT_S_TRACKER_POSE_IMU,
37 RIFT_S_TRACKER_POSE_LEFT_CAMERA,
38 RIFT_S_TRACKER_POSE_DEVICE,
39};
40
42{
43 struct xrt_device base;
44
45 //! Protects shared access to 3dof and pose storage
47
48 //! Don't process IMU / video until started
50
51 struct
52 {
53 //! Main fusion calculator.
55
56 //! The last angular velocity from the IMU, for prediction.
58
59 //! When did we get the last IMU sample, device clock
61
62 //! Last IMU sample local system clock
64 } fusion;
65
66 //! Fields related to camera-based tracking (SLAM and hand tracking)
67 struct
68 {
69 //! SLAM tracker.
70 //! @todo Right now, we are not consistent in how we interface with
71 //! trackers. In particular, we have a @ref xrt_tracked_slam field but not
72 //! an equivalent for hand tracking.
74
75 //! Set at start. Whether the SLAM tracker was initialized.
77
78 //! Set at start. Whether the hand tracker was initialized.
81
82 // Correction offset poses from firmware
83 struct xrt_pose device_from_imu;
85
86 //!< Estimated offset from HMD device timestamp to local monotonic clock
87 uint64_t seen_clock_observations;
88 bool have_hw2mono;
89 time_duration_ns hw2mono;
90 timepoint_ns last_frame_time;
91
92 //! Adjustment to apply to camera timestamps to bring them into the
93 // same 32-bit range as the IMU times
95
96 //! Whether to track the HMD with 6dof SLAM or fallback to the `fusion` 3dof tracker
98
99 //! Last tracked pose
101
102 /* Stereo calibration for the front 2 cameras */
103 struct t_stereo_camera_calibration *stereo_calib;
104 struct t_slam_calibration slam_calib;
105
106 /* Input sinks that the camera delivers SLAM frames to */
107 struct xrt_slam_sinks in_slam_sinks;
108
109 /* SLAM/HT sinks we deliver imu and frame data to */
110 struct xrt_slam_sinks slam_sinks;
111
112 struct xrt_device *handtracker;
113
114 struct
115 {
116 struct u_var_button hmd_screen_enable_btn;
117 struct u_var_button switch_tracker_btn;
118 char hand_status[128];
119 char slam_status[128];
120 } gui;
121};
122
123struct rift_s_tracker *
125 struct xrt_frame_context *xfctx,
126 struct rift_s_hmd_config *hmd_config);
127void
128rift_s_tracker_start(struct rift_s_tracker *t);
129void
130rift_s_tracker_destroy(struct rift_s_tracker *t);
131void
132rift_s_tracker_add_debug_ui(struct rift_s_tracker *t, void *root);
133
134struct xrt_slam_sinks *
135rift_s_tracker_get_slam_sinks(struct rift_s_tracker *t);
136struct xrt_device *
137rift_s_tracker_get_hand_tracking_device(struct rift_s_tracker *t);
138
139void
140rift_s_tracker_clock_update(struct rift_s_tracker *t, uint64_t device_timestamp_ns, timepoint_ns local_timestamp_ns);
141
142void
143rift_s_tracker_imu_update(struct rift_s_tracker *t,
144 uint64_t device_timestamp_ns,
145 const struct xrt_vec3 *accel,
146 const struct xrt_vec3 *gyro);
147
148void
149rift_s_tracker_push_slam_frames(struct rift_s_tracker *t,
150 uint64_t frame_ts_ns,
151 struct xrt_frame *frames[RIFT_S_CAMERA_COUNT]);
152void
153rift_s_tracker_get_tracked_pose(struct rift_s_tracker *t,
154 enum rift_s_tracker_pose pose,
155 uint64_t at_timestamp_ns,
156 struct xrt_space_relation *out_relation);
157
158#endif
int64_t timepoint_ns
Integer timestamp type.
Definition: u_time.h:70
int64_t time_duration_ns
Integer duration type in nanoseconds.
Definition: u_time.h:81
A IMU fusion specially made for 3dof devices.
Wrapper around OS threading native functions.
Oculus Rift S firmware parsing interface.
struct rift_s_tracker * rift_s_tracker_create(struct xrt_tracking_origin *origin, struct xrt_frame_context *xfctx, struct rift_s_hmd_config *hmd_config)
Procedure to setup trackers: 3dof, SLAM and hand tracking.
Definition: rift_s_tracker.c:322
Definition: m_imu_3dof.h:35
A wrapper around a native mutex.
Definition: os_threading.h:55
Definition: rift_s.h:56
Definition: rift_s_tracker.h:42
struct xrt_vec3 last_angular_velocity
The last angular velocity from the IMU, for prediction.
Definition: rift_s_tracker.h:57
struct xrt_tracked_slam * slam
SLAM tracker.
Definition: rift_s_tracker.h:73
bool slam_enabled
Set at start. Whether the SLAM tracker was initialized.
Definition: rift_s_tracker.h:76
struct xrt_pose left_cam_from_imu
Estimated offset from HMD device timestamp to local monotonic clock.
Definition: rift_s_tracker.h:84
struct rift_s_tracker::@170 tracking
Fields related to camera-based tracking (SLAM and hand tracking)
uint64_t last_imu_timestamp_ns
When did we get the last IMU sample, device clock.
Definition: rift_s_tracker.h:60
struct m_imu_3dof i3dof
Main fusion calculator.
Definition: rift_s_tracker.h:54
timepoint_ns last_imu_local_timestamp_ns
Last IMU sample local system clock.
Definition: rift_s_tracker.h:63
struct xrt_pose pose
Last tracked pose.
Definition: rift_s_tracker.h:100
int64_t camera_ts_offset
Adjustment to apply to camera timestamps to bring them into the.
Definition: rift_s_tracker.h:94
struct os_mutex mutex
Protects shared access to 3dof and pose storage.
Definition: rift_s_tracker.h:46
bool hand_enabled
Set at start. Whether the hand tracker was initialized.
Definition: rift_s_tracker.h:79
bool ready_for_data
Don't process IMU / video until started.
Definition: rift_s_tracker.h:49
bool slam_over_3dof
Whether to track the HMD with 6dof SLAM or fallback to the fusion 3dof tracker.
Definition: rift_s_tracker.h:97
Calibration information necessary for SLAM tracking.
Definition: t_tracking.h:636
Stereo camera calibration data to be given to trackers.
Definition: t_tracking.h:248
Simple pushable button.
Definition: u_var.h:79
A single HMD or input device.
Definition: xrt_device.h:241
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:108
Basic frame data structure - holds a pointer to buffer.
Definition: xrt_frame.h:25
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
Container of pointers to sinks that could be used for a SLAM system.
Definition: xrt_tracking.h:202
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:657
An adapter that wraps an external SLAM tracker to provide SLAM tracking.
Definition: xrt_tracking.h:294
A tracking system or device origin.
Definition: xrt_tracking.h:71
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Tracking API interface.
Variable tracking code.
Common defines and enums for XRT.
Header defining an xrt display or controller device.