12#include "xrt/xrt_config_build.h"
39#include <ceres/context.h>
44#include <shared_mutex>
49#define CT_TRACE(ct, ...) U_LOG_IFL_T(ct->log_level, __VA_ARGS__)
50#define CT_DEBUG(ct, ...) U_LOG_IFL_D(ct->log_level, __VA_ARGS__)
51#define CT_INFO(ct, ...) U_LOG_IFL_I(ct->log_level, __VA_ARGS__)
52#define CT_WARN(ct, ...) U_LOG_IFL_W(ct->log_level, __VA_ARGS__)
53#define CT_ERROR(ct, ...) U_LOG_IFL_E(ct->log_level, __VA_ARGS__)
55#define MIN_ROT_ERROR DEG_TO_RAD(30)
56#define MIN_POS_ERROR 0.10
68constellation_tracker_camera_destroy(
t_blob_sink *tbs);
71constellation_tracker_camera_slow_thread(
void *ptr);
74constellation_tracker_camera_fast_thread(
void *ptr);
83namespace xrt::tracking::constellation {
85using namespace xrt::tracking::constellation::optimizer;
87namespace os = xrt::auxiliary::os;
98 xrt_pose Tcv_cam_device XRT_POSE_IDENTITY;
99 float average_blob_brightness;
100 RawPoseCovarianceMatrix covariance;
113 t_constellation_device_id_t
device_id{XRT_CONSTELLATION_INVALID_DEVICE_ID};
132 uint64_t sequence_id{};
133 int64_t timestamp_ns{};
134 t_blob blobs[XRT_CONSTELLATION_MAX_BLOBS_PER_FRAME]{};
135 uint32_t blob_count{};
140 std::array<DeviceState, XRT_CONSTELLATION_MAX_DEVICES> device_states{};
141 uint32_t device_count{};
143 uint32_t mosaic_index;
144 uint32_t camera_index;
147 std::optional<DeviceState *>
148 getDeviceState(t_constellation_device_id_t device_id);
151 putDeviceState(t_constellation_device_id_t device_id);
160 t_constellation_device_id_t device_id,
164 toBlobObservation() const &
167 .source = this->source,
169 .sequence_id = this->sequence_id,
170 .timestamp_ns = this->timestamp_ns,
171 .blobs =
const_cast<t_blob *
>(this->blobs),
172 .num_blobs = this->blob_count,
180 toBlobObservation() && =
delete;
182 toBlobObservation() const && = delete;
189 bool draw_blobs{
true};
191 bool draw_blob_ids{
false};
193 bool draw_blob_device_ids{
true};
195 bool draw_blob_led_ids{
false};
198 bool draw_prior{
false};
200 bool draw_found{
false};
204 setupDebugTracking(
void *root);
209 RawPoseCovarianceMatrix covariance;
216 .
push_blobs = constellation_tracker_camera_push_blobs,
217 .destroy = constellation_tracker_camera_destroy,
222 std::weak_ptr<CameraMosaic> mosaic;
237 std::optional<CameraSample> sample{std::nullopt};
242 } slow_processing_thread_data;
251 std::optional<CameraSample> sample{std::nullopt};
256 } fast_processing_thread_data;
264 bool has_concrete_pose;
267 std::atomic<uint32_t> shallow_searches_failed{0};
277 std::weak_ptr<CameraMosaic> mosaic,
288 operator=(
const Camera &) =
delete;
290 operator=(
Camera &&) =
delete;
292 std::optional<xrt_pose>
300 tryDevicePose(
Device *device,
303 const std::optional<xrt_space_relation> &Tcv_cam_device_prior,
304 const xrt_pose &Tcv_cam_device_candidate);
307 tryDeviceBlobRecovery(
Device *device,
310 const std::optional<xrt_space_relation> &Tcv_cam_device_prior);
328 std::optional<OldOptimizationData *> was_optimized);
338 std::vector<std::unique_ptr<Camera>> cameras;
351 std::optional<xrt_pose>
377 t_constellation_device_id_t id;
380 std::atomic<bool> enabled{
false};
385 std::unique_ptr<sensor_fusion::SensorFusion> sensor_fusion{};
393 xrt_vec3 prior_pos_error{MIN_POS_ERROR, MIN_POS_ERROR, MIN_POS_ERROR};
394 xrt_vec3 prior_rot_error{MIN_ROT_ERROR, MIN_ROT_ERROR, MIN_ROT_ERROR};
395 float gravity_error_rad{MIN_ROT_ERROR};
397 mutable os::Mutex data_lock;
400 std::optional<DeviceLastPose> last_known_pose;
408 t_constellation_device_id_t
id);
416 operator=(
const Device &) =
delete;
418 operator=(
Device &&) =
delete;
438 .
break_apart = constellation_tracker_node_break_apart,
439 .destroy = constellation_tracker_node_destroy,
442 .
name =
"Constellation Tracker",
446 .orientation = XRT_QUAT_IDENTITY,
447 .position = {.x = 0, .y = 1.2, .z = 0},
462 bool single_threaded{
false};
463 bool deterministic{
false};
465 std::vector<std::shared_ptr<CameraMosaic>> mosaics;
468 std::unique_ptr<ceres::Context> ceres_context{};
470 std::shared_mutex device_lock;
471 std::vector<std::unique_ptr<Device>> devices;
472 t_constellation_device_id_t next_device_id{0};
474 std::unique_ptr<DataRecorder> data_recorder{};
476 mutable os::Mutex rig_calibration_lock{};
478 bool running_calibration{
false};
479 std::unique_ptr<rig_calibration::RigCalibration> rig_calibration{};
481#ifdef XRT_FEATURE_RERUN
482 std::unique_ptr<struct RerunContext> rerun_stream{};
493 Get(t_constellation_tracker *tracker)
511 needSensorCalibration();
514 checkSensorCalibration();
517 setupVariableTracking();
519 t_constellation_device_id_t
523 removeDevice(t_constellation_device_id_t device_id);
Ab-initio blob<->LED correspondence search.
u_logging_level
Logging level enum.
Definition u_logging.h:45
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
#define container_of(ptr, type, field)
Get the holder from a pointer to a field.
Definition xrt_compiler.h:298
@ XRT_TRACKING_TYPE_CONSTELLATION
The device(s) are tracked through a constellation of lights as seen by cameras.
Definition xrt_tracking.h:72
LED search model management code.
C interface to math library.
Metrics for constellation tracking poses.
RANSAC PnP pose refinement.
Constellation tracker rig calibration.
Constellation tracker sensor fusion.
Definition t_rift_blobwatch.c:85
Definition camera_model.h:21
Definition correspondence_search.h:95
Definition u_pacing_compositor.c:58
All in one helper that handles locking, waiting for change and starting a thread.
Definition os_threading.h:500
Definition pose_metrics.h:105
Definition pose_metrics.h:79
Definition t_constellation.h:102
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:134
void(* push_blobs)(struct t_blob_sink *tbs, struct t_blob_observation *observation)
Push a set of blobs into the sink.
Definition t_constellation.h:142
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:51
Definition t_constellation.h:185
Essential calibration data for a single camera, or single lens/sensor of a stereo camera.
Definition t_tracking.h:269
Definition led_search_model.h:40
A constellation tracker camera mosaic is a set of cameras that may or may not be physically attached,...
Definition t_constellation_tracker.h:60
A constellation tracker camera is a single camera that the constellation tracker will use to track de...
Definition t_constellation_tracker.h:34
Parameters for adding a device to the constellation tracker.
Definition t_constellation_tracker.h:79
A constellation tracker device is a device that the constellation tracker will attempt to track in 6d...
Definition t_constellation.h:396
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:311
Definition t_constellation_tracker.h:104
A constellation tracker tracking source is an arbitrary source of tracking data for the constellation...
Definition t_constellation.h:254
Allows more safely to debug sink inputs and outputs.
Definition u_sink.h:214
Definition t_constellation_tracker_internal.hpp:213
os::Mutex processing_lock
Locks all processing data.
Definition t_constellation_tracker_internal.hpp:259
uint32_t index
The index in the mosaic.
Definition t_constellation_tracker_internal.hpp:231
ConstellationTracker * tracker
The owner tracker, so we can retrieve it from the blob sink callback.
Definition t_constellation_tracker_internal.hpp:221
Definition t_constellation_tracker_internal.hpp:336
uint32_t index
The index of this mosaic in the tracker.
Definition t_constellation_tracker_internal.hpp:340
Definition t_constellation_tracker_internal.hpp:128
std::optional< xrt_pose > Txr_world_cam
The camera's position in the constellation tracker's tracking origin.
Definition t_constellation_tracker_internal.hpp:138
Definition t_constellation_tracker_internal.hpp:186
Definition t_constellation_tracker_internal.hpp:435
Definition t_constellation_tracker_internal.hpp:453
Definition t_constellation_tracker_dataset.hpp:124
Definition t_constellation_tracker_internal.hpp:367
Definition t_constellation_tracker_internal.hpp:372
ConstellationTracker * tracker
The owner tracker, so we can retrieve it from the IMU sink callback.
Definition t_constellation_tracker_internal.hpp:383
Definition t_constellation_tracker_internal.hpp:356
Definition t_constellation_tracker_internal.hpp:111
std::optional< xrt_space_relation > Tcv_cam_device_predicted
The predicted pose of the device relative to the camera at the time of the sample.
Definition t_constellation_tracker_internal.hpp:118
t_constellation_device_id_t device_id
The ID of the device.
Definition t_constellation_tracker_internal.hpp:113
std::optional< xrt_pose > Txr_world_device_prior
The predicted pose of the device in the world at the time of the sample.
Definition t_constellation_tracker_internal.hpp:116
std::optional< FoundDevicePose > found_pose
The final found pose of the device in this specific sample.
Definition t_constellation_tracker_internal.hpp:121
bool needs_slow_processing
Whether the device needs to have the slow processing thread run over it.
Definition t_constellation_tracker_internal.hpp:124
Definition t_constellation_tracker_internal.hpp:97
bool handled
Whether a found pose was already handled, this is present so that if a single sample is torn between ...
Definition t_constellation_tracker_internal.hpp:107
Definition t_constellation_tracker_internal.hpp:208
A interface object used for destroying a frame graph.
Definition xrt_frame.h:87
void(* break_apart)(struct xrt_frame_node *node)
Called first in when the graph is being destroyed, remove any references frames and other objects and...
Definition xrt_frame.h:94
IMU Sample.
Definition xrt_tracking.h:143
An object to send IMU samples to.
Definition xrt_tracking.h:184
A pose composed of a position and orientation.
Definition xrt_defines.h:522
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:713
A tracking system or device origin.
Definition xrt_tracking.h:87
char name[256]
For debugging.
Definition xrt_tracking.h:89
A 3 element vector with single floats.
Definition xrt_defines.h:310
Header defining the tracking system integration in Monado.
Header defining the constellation tracker parameters and functions.
xrt_frame helpers for scribbling onto frames.
Basic logging functionality.
xrt_frame_sink converters and other helpers.
Slightly higher level thread safe helpers.
C++ helpers for weak pointers.
Header defining the tracking system integration in Monado.