12#include "xrt/xrt_config_build.h"
32#include <shared_mutex>
45#define CT_TRACE(ct, ...) U_LOG_IFL_T(ct->log_level, __VA_ARGS__)
46#define CT_DEBUG(ct, ...) U_LOG_IFL_D(ct->log_level, __VA_ARGS__)
47#define CT_INFO(ct, ...) U_LOG_IFL_I(ct->log_level, __VA_ARGS__)
48#define CT_WARN(ct, ...) U_LOG_IFL_W(ct->log_level, __VA_ARGS__)
49#define CT_ERROR(ct, ...) U_LOG_IFL_E(ct->log_level, __VA_ARGS__)
51#define MIN_ROT_ERROR DEG_TO_RAD(30)
52#define MIN_POS_ERROR 0.10
64constellation_tracker_camera_destroy(
t_blob_sink *tbs);
67constellation_tracker_camera_slow_thread(
void *ptr);
70constellation_tracker_camera_fast_thread(
void *ptr);
79namespace xrt::tracking::constellation {
81namespace os = xrt::auxiliary::os;
86struct ConstellationTracker;
92 xrt_pose Tcv_cam_device XRT_POSE_IDENTITY;
93 float average_blob_brightness;
99 t_constellation_device_id_t
device_id{XRT_CONSTELLATION_INVALID_DEVICE_ID};
116 int64_t timestamp_ns{};
117 t_blob blobs[XRT_CONSTELLATION_MAX_BLOBS_PER_FRAME]{};
118 uint32_t blob_count{};
123 std::array<DeviceState, XRT_CONSTELLATION_MAX_DEVICES> device_states{};
124 uint32_t device_count{};
126 uint32_t mosaic_index;
127 uint32_t camera_index;
130 std::optional<DeviceState *>
131 GetDeviceState(t_constellation_device_id_t device_id);
134 PutDeviceState(t_constellation_device_id_t device_id);
138 CameraSample() =
default;
141 MarkMatchingBlobs(ConstellationTracker *ct,
143 t_constellation_device_id_t device_id,
147 ToBlobObservation() const &
150 .source = this->source,
152 .timestamp_ns = this->timestamp_ns,
153 .blobs =
const_cast<t_blob *
>(this->blobs),
154 .num_blobs = this->blob_count,
161 ToBlobObservation() && =
delete;
163 ToBlobObservation() const && = delete;
170 bool draw_blobs{
true};
172 bool draw_blob_ids{
false};
174 bool draw_blob_device_ids{
true};
176 bool draw_blob_led_ids{
false};
179 bool draw_prior{
false};
181 bool draw_found{
false};
185 SetupDebugTracking(
void *root);
192 .
push_blobs = constellation_tracker_camera_push_blobs,
193 .destroy = constellation_tracker_camera_destroy,
198 std::weak_ptr<CameraMosaic> mosaic;
213 std::optional<CameraSample> sample{std::nullopt};
218 } slow_processing_thread_data;
227 std::optional<CameraSample> sample{std::nullopt};
232 } fast_processing_thread_data;
240 bool has_concrete_pose;
250 Camera(ConstellationTracker *tracker,
251 std::weak_ptr<CameraMosaic> mosaic,
259 Camera(
const Camera &) =
delete;
260 Camera(Camera &&) =
delete;
262 operator=(
const Camera &) =
delete;
264 operator=(Camera &&) =
delete;
266 std::optional<xrt_pose>
270 DeferSampleToSlowThread(CameraSample &sample);
274 TryDevicePose(std::unique_ptr<Device> &device,
275 CameraSample &sample,
276 DeviceState &device_state,
278 std::optional<xrt_pose> &Tcv_world_device_prior,
279 xrt_pose &Tcv_world_device_candidate);
282 TryDeviceBlobRecovery(std::unique_ptr<Device> &device,
283 CameraSample &sample,
284 DeviceState &device_state,
286 std::optional<xrt_pose> &Tcv_world_device_prior);
289 SlowSampleProcess(CameraSample &sample);
293 FastSampleProcess(CameraSample &sample);
296 PushPose(CameraSample &camera_sample,
297 DeviceState &device_state,
298 std::unique_ptr<Device> &device,
305 DebugScribbleSample(CameraSample &sample,
bool fast);
311 std::vector<std::unique_ptr<Camera>> cameras;
324 std::optional<xrt_pose>
334 t_constellation_device_id_t id;
342 xrt_vec3 prior_pos_error{MIN_POS_ERROR, MIN_POS_ERROR, MIN_POS_ERROR};
343 xrt_vec3 prior_rot_error{MIN_ROT_ERROR, MIN_ROT_ERROR, MIN_ROT_ERROR};
344 float gravity_error_rad{MIN_ROT_ERROR};
346 mutable os::Mutex data_lock;
349 std::optional<xrt_pose> Txr_world_device_last_known;
356 t_constellation_device_id_t
id);
367 .
break_apart = constellation_tracker_node_break_apart,
368 .destroy = constellation_tracker_node_destroy,
371 .
name =
"Constellation Tracker",
373 .initial_offset = XRT_POSE_IDENTITY,
387 bool single_threaded{
false};
389 std::vector<std::shared_ptr<CameraMosaic>> mosaics;
391 std::shared_mutex device_lock;
392 std::vector<std::unique_ptr<Device>> devices;
393 t_constellation_device_id_t next_device_id{0};
395 std::unique_ptr<DataRecorder> data_recorder{};
397#ifdef XRT_FEATURE_RERUN
398 std::unique_ptr<struct RerunContext> rerun_stream{};
402 static ConstellationTracker *
405 return static_cast<ConstellationTracker *
>(
container_of(node, ConstellationTrackerBase, node));
408 static ConstellationTracker *
409 Get(t_constellation_tracker *tracker)
411 return reinterpret_cast<ConstellationTracker *
>(tracker);
416 ~ConstellationTracker();
419 ConstellationTracker(
const ConstellationTracker &) =
delete;
420 ConstellationTracker(ConstellationTracker &&) =
delete;
421 ConstellationTracker &
422 operator=(
const ConstellationTracker &) =
delete;
423 ConstellationTracker &
424 operator=(ConstellationTracker &&) =
delete;
427 SetupVariableTracking();
429 t_constellation_device_id_t
433 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
@ U_LOGGING_WARN
Warning messages: indicating a potential problem.
Definition u_logging.h:49
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:238
@ XRT_TRACKING_TYPE_CONSTELLATION
The device(s) are tracked through a constellation of lights as seen by cameras.
Definition xrt_tracking.h:63
LED search model management code.
C interface to math library.
Metrics for constellation tracking poses.
RANSAC PnP pose refinement.
Definition t_rift_blobwatch.c:88
Definition camera_model.h:19
Definition correspondence_search.h:92
All in one helper that handles locking, waiting for change and starting a thread.
Definition os_threading.h:499
Definition pose_metrics.h:89
Definition pose_metrics.h:63
Definition t_constellation.h:80
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:101
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:109
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:37
Definition t_constellation.h:152
Essential calibration data for a single camera, or single lens/sensor of a stereo camera.
Definition t_tracking.h:236
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:339
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:266
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:221
Allows more safely to debug sink inputs and outputs.
Definition u_sink.h:214
Definition t_constellation_tracker_internal.hpp:189
os::Mutex processing_lock
Locks all processing data.
Definition t_constellation_tracker_internal.hpp:235
ConstellationTracker * tracker
The owner tracker, so we can retrieve it from the blob sink callback.
Definition t_constellation_tracker_internal.hpp:197
size_t index
The index in the mosaic.
Definition t_constellation_tracker_internal.hpp:207
Definition t_constellation_tracker_internal.hpp:309
size_t index
The index of this mosaic in the tracker.
Definition t_constellation_tracker_internal.hpp:313
Definition t_constellation_tracker_internal.hpp:112
std::optional< xrt_pose > Txr_world_cam
The camera's position in the constellation tracker's tracking origin.
Definition t_constellation_tracker_internal.hpp:121
Definition t_constellation_tracker_internal.hpp:167
Definition t_constellation_tracker_internal.hpp:364
Definition t_constellation_tracker_internal.hpp:378
Definition t_constellation_tracker_internal.hpp:329
Definition t_constellation_tracker_internal.hpp:97
t_constellation_device_id_t device_id
The ID of the device.
Definition t_constellation_tracker_internal.hpp:99
std::optional< xrt_pose > Txr_world_device_prior
The "predicted" pose, which is the pose the device expects itself to be at at the time of the blobser...
Definition t_constellation_tracker_internal.hpp:102
std::optional< FoundDevicePose > found_pose
The final found pose of the device in this specific sample.
Definition t_constellation_tracker_internal.hpp:105
bool needs_slow_processing
Whether the device needs to have the slow processing thread run over it.
Definition t_constellation_tracker_internal.hpp:108
Definition t_constellation_tracker_internal.hpp:91
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
A pose composed of a position and orientation.
Definition xrt_defines.h:492
A tracking system or device origin.
Definition xrt_tracking.h:78
char name[256]
For debugging.
Definition xrt_tracking.h:80
A 3 element vector with single floats.
Definition xrt_defines.h:289
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.