31#define LOG_GRAY_SPEW(refinement, ...) LOG_DEBUG(refinement, __VA_ARGS__)
33#define LOG_GRAY_SPEW(refinement, ...)
36#define TIME_BETWEEN_LED_SELECTIONS_NS (U_TIME_1MS_IN_NS * 2500LL)
39#define INVALID_GRAY_CODE_JUMP INT64_MAX
41#define INVALID_GRAY_CODE (0x4)
43#define GRAY_CODE_MATCHES_NEEDED 3
45#define GRAY_CODE_TIMEOUT_NS (U_TIME_1S_IN_NS * 10LL)
47#define BG_NUM_FRAMES T_LED_SYNC_BRIGHTNESS_CURVE_NUM_SAMPLES
49#define BG_STEP_NS (U_TIME_1US_IN_NS * 50)
51#define BG_TARGET_STEP 10.0f
53#define BG_OFFSET_GAIN 0.5f
55#define BG_DEADBAND_STEPS 0.25f
57#define BG_SKEW_WINDOW_SAMPLES 20
59#define BG_MAX_SKEW 1e-3
61#define BG_NO_MEASUREMENT_TIMEOUT_NS (U_TIME_1S_IN_NS * 13LL)
63#define BG_LED_ERROR_SMOOTHING 0.2
65#define BG_MODEL_PUBLISH_THRESHOLD_NS (U_TIME_1US_IN_NS * 3)
67#define BG_STABLE_MAX_RATE 2e-6
69#define BG_STABLE_DWELL_NS (U_TIME_1S_IN_NS * 15LL)
70#define BG_STABLE_DWELL_WARM_NS (U_TIME_1S_IN_NS * 3LL)
72#define STABLE_RECHECK_NS (U_TIME_1S_IN_NS * 100LL)
74#define STABLE_NOT_SEEN_TIMEOUT_NS (U_TIME_1S_IN_NS * 15LL)
96 if (jump_amount_ns == 0) {
97 LOG_DEBUG(refinement,
"Got the \"done\" gray code (%d), moving to next phase.", gray_code);
105 LOG_DEBUG(refinement,
"Accepting gray code %x after %d identical matches, moving %" PRIi64
"us", gray_code,
108 bool success = advance_clock_offset_pssense_locked(refinement, jump_amount_ns);
116 LOG_GRAY_SPEW(refinement,
"Decoded gray code! Got %x", decoded_gray_code);
119 bool invalid_code = decoded_gray_code != refinement->decode_gray.
decoded_gray_code ||
131 handle_successful_gray_decode(refinement, decoded_gray_code);
143 bool clear_slot = sample->sequence_id > refinement->leds_seen.
cur_sequence_id;
147 for (uint32_t camera_idx = 0; camera_idx < XRT_TRACKING_MAX_CAMS; camera_idx++) {
148 for (uint32_t led_idx = 0; led_idx < T_LED_SYNC_SELECTED_LEDS; led_idx++) {
149 size_t led_buffer_index =
150 T_LED_SYNC_GRAY_CODE_BUFFER_INDEX(camera_idx, sample->sequence_id, led_idx);
159 refinement->leds_seen.num_samples += 1;
162 uint32_t seen_led_idx =
163 T_LED_SYNC_SEEN_LED_BUFFER_INDEX(refinement->leds_seen.
cur_sequence_id = sample->sequence_id);
169 "LED sync depends on these being equal.");
171 for (uint32_t i = 0; i <
ARRAY_SIZE(sample->leds); i++) {
176 if (!sample->leds[i].observed) {
189 bool need_new_led_selection =
190 (sample->timestamp_ns - refinement->leds_seen.
last_selection_ns) > TIME_BETWEEN_LED_SELECTIONS_NS &&
208 size_t most_seen_index = 0;
209 float most_seen_value = -INFINITY;
210 size_t second_most_seen_index = 0;
211 float second_most_seen_value = -INFINITY;
212 for (uint32_t i = 0; i <
ARRAY_SIZE(leds_seen); i++) {
218 if (value > most_seen_value) {
219 second_most_seen_index = most_seen_index;
220 second_most_seen_value = most_seen_value;
223 most_seen_value = value;
224 }
else if (value > second_most_seen_value) {
225 second_most_seen_index = i;
226 second_most_seen_value = value;
230 uint8_t leds[4] = {0xFF, 0xFF, 0xFF, 0xFF};
231 if (most_seen_value > -INFINITY) {
232 leds[0] = most_seen_index;
234 if (second_most_seen_value > -INFINITY) {
235 leds[1] = second_most_seen_index;
238 LOG_GRAY_SPEW(refinement,
"Selected LEDs %d,%d", leds[0], leds[1]);
253 XRT_MAYBE_UNUSED
const uint16_t decoding_mask = 0x7FF;
254 const uint16_t header_mask = 0x7F8;
255 const uint16_t gray_code_mask = 0x7;
256 const uint16_t expected_header = 0x38;
259 for (
int i = 0; i < T_LED_SYNC_SELECTED_LEDS; i++) {
265 size_t led_buffer_index =
266 T_LED_SYNC_GRAY_CODE_BUFFER_INDEX(sample->camera_index, refinement->leds_seen.
cur_sequence_id, i);
269 refinement->decode_gray.
led_brightnesses[led_buffer_index] = sample->leds[led].greysum;
270 refinement->decode_gray.
led_facing_dots[led_buffer_index] = sample->leds[led].facing_dot;
276 uint16_t decoded_values[T_LED_SYNC_SELECTED_LEDS] = {0};
278 for (
int led = 0; led < T_LED_SYNC_SELECTED_LEDS; led++) {
279 float min_observed_brightness[XRT_TRACKING_MAX_CAMS];
280 float max_observed_brightness[XRT_TRACKING_MAX_CAMS] = {0};
281 for (uint32_t i = 0; i <
ARRAY_SIZE(min_observed_brightness); i++) {
282 min_observed_brightness[i] = INFINITY;
287 for (
size_t i = 0; i <
ARRAY_SIZE(best_camera_indices); i++) {
288 best_camera_indices[i] = -1;
293 float best_facing_dot = 1.0f;
294 float best_brightness = 0.0f;
296 for (
int camera_index = 0; camera_index < XRT_TRACKING_MAX_CAMS; camera_index++) {
298 size_t led_buffer_index = T_LED_SYNC_GRAY_CODE_BUFFER_INDEX(
301 float brightness = refinement->decode_gray.
led_brightnesses[led_buffer_index];
302 float facing_dot = refinement->decode_gray.
led_facing_dots[led_buffer_index];
304 if (brightness > 0.0f && facing_dot < 1) {
307 min_observed_brightness[camera_index] =
308 MIN(min_observed_brightness[camera_index], brightness);
309 max_observed_brightness[camera_index] =
310 MAX(max_observed_brightness[camera_index], brightness);
313 if (brightness > 0 && facing_dot < best_facing_dot) {
314 best_brightness = brightness;
315 best_facing_dot = facing_dot;
316 best_camera_indices[age] = camera_index;
320 brightnesses[age] = best_brightness;
326 decoded_values[led] >>= 1;
329 float threshold = 0.5f;
330 if (best_camera_indices[age] != -1) {
331 threshold = (min_observed_brightness[best_camera_indices[age]] +
332 max_observed_brightness[best_camera_indices[age]]) /
336 bool bit = brightnesses[age] > threshold;
338 LOG_GRAY_SPEW(refinement,
"brightness[%d][%d]: %f", led, age, brightnesses[age]);
344 if (decoded_values[0] == decoded_values[1]) {
345 uint16_t decoded_value = decoded_values[0];
348 assert((decoded_value & (~decoding_mask)) == 0);
350 uint16_t decoded_header = decoded_value & header_mask;
351 uint16_t decoded_gray_code = decoded_value & gray_code_mask;
353 if (decoded_header == expected_header) {
354 handle_decoded_gray_code(refinement, decoded_gray_code);
356 LOG_GRAY_SPEW(refinement,
"Decoding gray code failed! Got header %x and data %x",
357 decoded_header, decoded_gray_code);
360 LOG_GRAY_SPEW(refinement,
"Decoding gray code failed, the two LEDs didn't match, %d\t%d",
361 decoded_values[0], decoded_values[1]);
375 return &refinement->optimize_brightness_curve.
frames[camera_index][sequence_id % BG_NUM_FRAMES];
382 if (
frame->sequence_id != sequence_id) {
386 for (
int led = 0; led < T_LED_SYNC_SELECTED_LEDS; led++) {
387 if (
frame->brightness[led] <= 0.0f) {
401 if (memcmp(refinement->optimize_brightness_curve.
leds, leds, T_LED_SYNC_SELECTED_LEDS) != 0) {
402 memcpy(refinement->optimize_brightness_curve.
leds, leds, T_LED_SYNC_SELECTED_LEDS);
406 assert(sample->camera_index < XRT_TRACKING_MAX_CAMS);
409 frame->sequence_id = sample->sequence_id;
410 for (
int i = 0; i < T_LED_SYNC_SELECTED_LEDS; i++) {
411 bool seen = leds[i] != 0xFF && sample->leds[leds[i]].observed;
414 frame->brightness[i] = seen ? sample->leds[leds[i]].greysum : 0.0f;
415 frame->facing_dot[i] = seen ? sample->leds[leds[i]].facing_dot : 1.0f;
425 uint64_t last_sequence_id,
426 float out_brightness[T_LED_SYNC_SELECTED_LEDS][BG_NUM_FRAMES])
432 uint64_t first_sequence_id = last_sequence_id + 1 - BG_NUM_FRAMES;
434 int best_camera = -1;
435 float best_facing_dot = INFINITY;
437 for (uint32_t camera = 0; camera < XRT_TRACKING_MAX_CAMS; camera++) {
438 bool complete =
true;
439 float facing_dot = 0.0f;
441 for (uint64_t seq = first_sequence_id; seq <= last_sequence_id && complete; seq++) {
445 facing_dot +=
frame->facing_dot[0] +
frame->facing_dot[1];
448 if (complete && facing_dot < best_facing_dot) {
449 best_camera = (int)camera;
450 best_facing_dot = facing_dot;
454 if (best_camera < 0) {
458 for (
int i = 0; i < BG_NUM_FRAMES; i++) {
461 for (
int led = 0; led < T_LED_SYNC_SELECTED_LEDS; led++) {
462 out_brightness[led][i] =
frame->brightness[led];
473 static const int positions[] = {0, 1, 2, 3, 17, 18, 19};
474 static const bool expected[] = {
true,
false,
false,
true,
true,
false,
true};
476 for (
size_t i = 0; i <
ARRAY_SIZE(positions); i++) {
477 if (bits[(cycle_start + positions[i]) % BG_NUM_FRAMES] != expected[i]) {
489 bool bits[T_LED_SYNC_SELECTED_LEDS][BG_NUM_FRAMES];
491 for (
int led = 0; led < T_LED_SYNC_SELECTED_LEDS; led++) {
492 float min = brightness[led][0];
493 float max = brightness[led][0];
494 for (
int i = 1; i < BG_NUM_FRAMES; i++) {
495 min =
MIN(min, brightness[led][i]);
496 max =
MAX(max, brightness[led][i]);
500 float threshold = (min + max) / 2.0f;
501 for (
int i = 0; i < BG_NUM_FRAMES; i++) {
502 bits[led][i] = brightness[led][i] > threshold;
506 for (
int cycle_start = 0; cycle_start < BG_NUM_FRAMES; cycle_start++) {
508 for (
int led = 0; led < T_LED_SYNC_SELECTED_LEDS; led++) {
509 all_ok = all_ok &&
bg_marker_ok(bits[led], cycle_start);
527 float min = INFINITY;
528 float max = -INFINITY;
529 for (
int k = first; k <= last; k++) {
530 float value = brightness[(cycle_start + k) % BG_NUM_FRAMES];
531 min =
MIN(min, value);
532 max =
MAX(max, value);
534 float mid = (min + max) / 2.0f;
536 float weighted_sum = 0.0f;
537 float total_weight = 0.0f;
538 for (
int k = first; k <= last; k++) {
539 float weight = fmaxf(mid - brightness[(cycle_start + k) % BG_NUM_FRAMES], 0.0f);
540 weighted_sum += (float)k * weight;
541 total_weight += weight;
545 if (total_weight <= 0.0f) {
562 double elapsed_ns = (double)(refinement->last_exposure_ns - delta->anchor_ns);
563 double drift_ns = elapsed_ns - (double)frames * delta->
base_period_ns;
567 if (reanchor_period) {
571 LOG_DEBUG(refinement,
"Clock model drifted %.0fns from the LEDs over %" PRIu64
" frames", drift_ns,
576 delta->anchor_ns = refinement->last_exposure_ns;
598 double period_ns = refinement->period_estimate.
period_ns;
607 LOG_DEBUG(refinement,
"BG rebased onto %.1fns, skew %f ppm", period_ns, delta->
skew * 1e6);
617 delta->window_start_ns = now_ns;
621 double t = (double)(now_ns - delta->window_start_ns);
626 delta->sum_tt += t * t;
628 delta->sum_td += t * d;
635 double denom = n * delta->sum_tt - delta->sum_t * delta->sum_t;
636 bool converged =
false;
638 double slope = (n * delta->sum_td - delta->sum_t * delta->sum_d) / denom;
645 uint32_t windows_needed = delta->
been_stable ? 1 : 2;
646 if (!converged || delta->
num_windows < windows_needed) {
653 delta->sum_t = delta->sum_tt = delta->sum_d = delta->sum_td = 0.0;
662 if (!delta->has_led_error) {
664 delta->has_led_error =
true;
696 refinement->delta_sync.
led_error_ns -= (double)servo_ns;
698 bool sent = advance_clock_offset_pssense_locked(refinement, servo_ns);
707 bg_store_frame(refinement, sample);
709 float brightness[T_LED_SYNC_SELECTED_LEDS][BG_NUM_FRAMES];
710 if (!
bg_read_window(refinement, sample->sequence_id, brightness)) {
714 for (
int i = 0; i < BG_NUM_FRAMES; i++) {
715 LOG_GRAY_SPEW(refinement,
"BG [%d] %f %f", i, brightness[0][i], brightness[1][i]);
719 if (cycle_start < 0) {
738 LOG_GRAY_SPEW(refinement,
"BG error %f steps, skew %f ppm", error_steps, refinement->delta_sync.
skew * 1e6);
762 LOG_DEBUG(refinement,
"Waited %lf seconds without valid gray decode, resetting.",
779 bool applied = advance_clock_offset_pssense_locked(refinement, 0);
791 LOG_DEBUG(refinement,
"No BG measurement for %fms, resyncing",
time_ns_to_ms_f(since_measurement_ns));
799 if (converged_since_ns != 0 && now_ns - converged_since_ns > dwell_ns && !refinement->
has_sample_for_driver) {
#define CLAMP(X, A, B)
X clamped to the range [A, B].
Definition m_api.h:78
#define MAX(A, B)
Maximum of A and B.
Definition m_api.h:70
#define MIN(A, B)
Minimum of A and B.
Definition m_api.h:61
static int64_t os_monotonic_get_ns(void)
Return a monotonic clock in nanoseconds.
Definition os_time.h:317
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
static double time_ns_to_ms_f(time_duration_ns ns)
Convert nanoseconds to double float milliseconds, useful for printing.
Definition u_time.h:121
static double time_ns_to_s(time_duration_ns ns)
Convert nanoseconds duration to double seconds.
Definition u_time.h:97
int64_t time_duration_ns
Integer duration type in nanoseconds.
Definition u_time.h:88
Internal routines for LED sync code.
static time_duration_ns model_clock_offset_ns(struct t_led_sync_refinement *refinement, time_duration_ns clock_offset_ns)
The host->device offset to publish, corrected by the LEDs' offset from the exposure so it follows the...
Definition led_sync_internal.h:63
#define MAX_SAMPLE_LATENCY
The amount of frames to not see it for consider a device "not found" during an active search.
Definition led_sync_internal.h:32
C interface to math library.
#define INVALID_GRAY_CODE
This gray code isn't in the official table.
Definition pssense_gray_code.h:41
#define BG_DEADBAND_STEPS
Errors within this are left to the cycle trim, wide enough that measurement noise doesn't trigger sen...
Definition pssense_gray_code.h:55
#define BG_MODEL_PUBLISH_THRESHOLD_NS
How far the clock model may move before it's republished, every publish resends the LED settings.
Definition pssense_gray_code.h:65
static void delta_sync_rebase(struct t_led_sync_refinement *refinement, timepoint_ns now_ns)
Moves the base onto the latest trusted period estimate, the skew takes up the difference so the cycle...
Definition pssense_gray_code.h:595
static void delta_sync_set_skew(struct t_led_sync_refinement *refinement, timepoint_ns now_ns, double skew)
Moves to a new skew, re-basing the clock model at now_ns so host->device conversion stays continuous.
Definition pssense_gray_code.h:581
static void bg_update_led_error(struct t_led_sync_refinement *refinement, time_duration_ns error_ns)
Smooths the LEDs' measured offset from the exposure, which the published clock model takes out.
Definition pssense_gray_code.h:658
static void bg_update_skew(struct t_led_sync_refinement *refinement, timepoint_ns now_ns, time_duration_ns error_ns)
Fits the phase deviation against time over a window of measurements and adds the slope to the skew.
Definition pssense_gray_code.h:612
static void bg_send_correction(struct t_led_sync_refinement *refinement, time_duration_ns servo_ns)
Sends a servo correction along with the current cycle trim, unless the driver hasn't taken the last s...
Definition pssense_gray_code.h:688
#define BG_STABLE_MAX_RATE
The fitted rate has to stay under this to enter STABLE, in ns per ns.
Definition pssense_gray_code.h:67
static int bg_find_cycle_start(float brightness[T_LED_SYNC_SELECTED_LEDS][T_LED_SYNC_BRIGHTNESS_CURVE_NUM_SAMPLES])
Finds where the cycle starts in the window, by both LEDs showing the marker there....
Definition pssense_gray_code.h:487
static void delta_sync_maintain_clock(struct t_led_sync_refinement *refinement, timepoint_ns now_ns)
Keeps the clock model on the latest period estimate and republishes it, needs no measurements.
Definition pssense_gray_code.h:747
#define BG_MAX_SKEW
Clamp on the estimated clock skew, in ns per ns.
Definition pssense_gray_code.h:59
static bool bg_read_window(struct t_led_sync_refinement *refinement, uint64_t last_sequence_id, float out_brightness[T_LED_SYNC_SELECTED_LEDS][T_LED_SYNC_BRIGHTNESS_CURVE_NUM_SAMPLES])
Reads the window ending at last_sequence_id, oldest first, from the camera facing the LEDs best.
Definition pssense_gray_code.h:424
#define BG_SKEW_WINDOW_SAMPLES
BG measurements per skew least-squares window.
Definition pssense_gray_code.h:57
#define GRAY_CODE_MATCHES_NEEDED
How many identical gray codes do we need to decode in a row to accept it.
Definition pssense_gray_code.h:43
#define BG_OFFSET_GAIN
Proportional gain for the BG clock-offset servo.
Definition pssense_gray_code.h:53
#define STABLE_RECHECK_NS
How long STABLE runs unmeasured before BG checks the LEDs again.
Definition pssense_gray_code.h:72
static bool bg_frame_usable(const struct t_led_sync_frame *frame, uint64_t sequence_id)
Whether frame was recorded for sequence_id and saw all the selected LEDs.
Definition pssense_gray_code.h:380
static bool bg_marker_ok(const bool bits[T_LED_SYNC_BRIGHTNESS_CURVE_NUM_SAMPLES], int cycle_start)
Whether the BG marker (1001 at the start of the cycle, 101 at the end) is at cycle_start.
Definition pssense_gray_code.h:471
#define BG_TARGET_STEP
The frame the dip of the BG curve should be centered on when in sync.
Definition pssense_gray_code.h:51
#define INVALID_GRAY_CODE_JUMP
The jump amount for an invalid code.
Definition pssense_gray_code.h:39
#define BG_NO_MEASUREMENT_TIMEOUT_NS
How long BG may go without an accepted measurement before the lock is given up.
Definition pssense_gray_code.h:61
static bool bg_measure_error_steps(const float brightness[T_LED_SYNC_BRIGHTNESS_CURVE_NUM_SAMPLES], int cycle_start, float *out_error_steps)
How far the dip of the curve is from BG_TARGET_STEP, from the centroid of the frames below the midpoi...
Definition pssense_gray_code.h:522
#define BG_LED_ERROR_SMOOTHING
Smoothing gain on the LEDs' measured offset from the exposure, trading measurement noise against lag.
Definition pssense_gray_code.h:63
#define BG_STEP_NS
Each frame of the BG curve is shifted this much further than the last.
Definition pssense_gray_code.h:49
static const time_duration_ns gray_code_jumps_ns[]
A table of how much time to jump for each gray code.
Definition pssense_gray_code.h:77
static void delta_sync_reanchor(struct t_led_sync_refinement *refinement, bool reanchor_period)
Corrects the clock model's drift from the LED cycle since the anchor, the LEDs follow the camera so t...
Definition pssense_gray_code.h:555
#define BG_STABLE_DWELL_NS
How long the rate has to stay converged before STABLE, first time and coming back from it.
Definition pssense_gray_code.h:69
#define GRAY_CODE_TIMEOUT_NS
How long to wait without an accepted gray code before resetting back to phase 1.
Definition pssense_gray_code.h:45
static bool bg_model_stale(struct t_led_sync_refinement *refinement)
Whether the clock model has moved far enough from what the driver has to be worth republishing.
Definition pssense_gray_code.h:673
Definition u_pacing_compositor.c:59
Definition t_constellation.h:378
Clock sync from BROAD on: the LED cycle, the clock model kept on it, and BG's offset servo and skew f...
Definition t_led_sync_refinement.h:210
uint32_t num_windows
Skew windows fitted since BG was entered.
Definition t_led_sync_refinement.h:233
timepoint_ns converged_since_ns
When the fitted rate last started staying under the STABLE gate, 0 if it isn't.
Definition t_led_sync_refinement.h:235
bool trim_pending
The skew changed and the new cycle still has to be sent.
Definition t_led_sync_refinement.h:228
timepoint_ns epoch_ns
Host time the published offset is valid at, the skew extrapolates from here.
Definition t_led_sync_refinement.h:216
uint32_t num_samples
Least-squares window of the phase deviation against time.
Definition t_led_sync_refinement.h:242
uint64_t anchor_sequence_id
The camera frame the clock model last matched the LED cycle at, its drift is measured from here.
Definition t_led_sync_refinement.h:212
double base_period_ns
The frame period the LED cycle is trimmed from, set when BROAD starts and moved onto each trusted est...
Definition t_led_sync_refinement.h:226
double skew
Estimated clock skew, device vs host, in ns per ns.
Definition t_led_sync_refinement.h:218
double led_error_ns
Smoothed offset of the LEDs from the exposure, as the servo correction that would center them.
Definition t_led_sync_refinement.h:222
bool been_stable
Whether this sync has reached STABLE, BG comes back from it warm.
Definition t_led_sync_refinement.h:237
timepoint_ns stable_entry_ns
Host time STABLE was entered.
Definition t_led_sync_refinement.h:239
timepoint_ns last_measurement_ns
Host time of the last accepted measurement, for the no-data watchdog.
Definition t_led_sync_refinement.h:230
time_duration_ns servo_integral_ns
Sum of all servo corrections this BG session.
Definition t_led_sync_refinement.h:220
One camera's view of the selected LEDs in one frame, brightness is the blob's greysum,...
Definition t_led_sync_refinement.h:191
double period_ns
The last trusted estimate, 0 until there is one.
Definition t_led_sync_refinement.h:205
Definition t_led_sync_refinement.h:248
uint64_t last_exposure_sequence_id
The latest timing event's frame and exposure time.
Definition t_led_sync_refinement.h:274
timepoint_ns last_selection_ns
The time when we last selected the set of LEDs.
Definition t_led_sync_refinement.h:337
uint32_t frames_since_last_visually_seen
The amount of frames since the controller was last visually seen.
Definition t_led_sync_refinement.h:310
struct t_led_sync_seen_led buf[XRT_CONSTELLATION_MAX_LEDS_PER_DEVICE *5]
The seen LEDs ring buffer.
Definition t_led_sync_refinement.h:346
timepoint_ns last_accepted_gray_code_ns
The last time we had an accepted gray code (or the start of this phase).
Definition t_led_sync_refinement.h:378
bool has_sample_for_driver
Whether we have a sample ready to be sent to the driver/device.
Definition t_led_sync_refinement.h:282
bool sample_applied
Whether the sample has been applied.
Definition t_led_sync_refinement.h:286
uint64_t window_start_sequence_id
The first frame the next measurement may use.
Definition t_led_sync_refinement.h:386
struct t_led_sync_sample sample_for_driver
The sample to be sent to the driver/device on it's next convenience.
Definition t_led_sync_refinement.h:284
uint8_t leds[2]
The LEDs frames were recorded for.
Definition t_led_sync_refinement.h:384
struct t_led_sync_frame frames[XRT_TRACKING_MAX_CAMS][20]
Ring buffer of the last T_LED_SYNC_BRIGHTNESS_CURVE_NUM_SAMPLES frames per camera.
Definition t_led_sync_refinement.h:388
float led_brightnesses[11 *XRT_TRACKING_MAX_CAMS *2]
A ring buffer storing the last T_LED_SYNC_GRAY_CODE_SIZE_BITS bits of the brightness sequence per cam...
Definition t_led_sync_refinement.h:362
bool applied_gray_start
Whether or not we have applied the final cycle position or not.
Definition t_led_sync_refinement.h:353
time_duration_ns current_clock_offset_ns
The current estimated latency offset between the device and the host, in nanoseconds.
Definition t_led_sync_refinement.h:299
uint32_t cur_sequence_id
The index into the seen LEDs ring buffer.
Definition t_led_sync_refinement.h:334
float led_facing_dots[11 *XRT_TRACKING_MAX_CAMS *2]
A ring buffer storing the last T_LED_SYNC_GRAY_CODE_SIZE_BITS bits of the sequence,...
Definition t_led_sync_refinement.h:371
uint8_t decoded_gray_code
The gray code we're trying.
Definition t_led_sync_refinement.h:376
uint32_t matching_decodes
How many decodes we've had that match in a row, see GRAY_CODE_MATCHES_NEEDED.
Definition t_led_sync_refinement.h:374
uint8_t leds[4]
The LEDs to enable, or 0xff if we don't have a selection.
Definition t_led_sync_refinement.h:125
A sample read out from the driver, to pass to the device in question.
Definition t_led_sync_refinement.h:130
time_duration_ns host_device_clock_offset_ns
The clock offset from the host timestamp to the device.
Definition t_led_sync_refinement.h:136
Definition t_led_sync_refinement.h:182
float accum_facing_dot
How "facing" the camera it was.
Definition t_led_sync_refinement.h:186
uint8_t accum_seen_count
How many times it's been seen.
Definition t_led_sync_refinement.h:184
#define XRT_CONSTELLATION_MAX_LEDS_PER_DEVICE
The maximum number of LEDs that a single device can have.
Definition t_constellation.h:37
A routine to automatically refine latency offsets of LED blink times using constellation samples.
@ T_LED_SYNC_SAMPLE_TIMESTAMP_MODE_HOST_DEVICE_CLOCK_OFFSET
Used when the LED sync refinement is fully deriving the clock offset, latency included.
Definition t_led_sync_refinement.h:99
@ T_LED_SYNC_SAMPLE_PSSENSE_MODE_BROAD
"BROAD", blink certain LEDs in an 11-frame Gray code to refine where we are in the offset faster than...
Definition t_led_sync_refinement.h:110
@ T_LED_SYNC_SAMPLE_PSSENSE_MODE_PRESCAN
"PRESCAN", used to scan for an initial offset to then refine.
Definition t_led_sync_refinement.h:105
#define T_LED_SYNC_SEEN_LEDS_ACCUMULATION_BUFFER_SIZE
How many elements are in the seen LEDs ring buffer.
Definition t_led_sync_refinement.h:28
@ T_LED_SYNC_PHASE_OPTIMIZE_BRIGHTNESS_CURVE
Trying to optimize the brightness curve for the correct time offset.
Definition t_led_sync_refinement.h:172
@ T_LED_SYNC_PHASE_FIND_INITIAL_OFFSET
Trying to find some offset that gets us in sync at all.
Definition t_led_sync_refinement.h:164
@ T_LED_SYNC_PHASE_STABLE
PS Sense only, BG has converged so the LEDs hold sync on the trimmed cycle until BG checks them again...
Definition t_led_sync_refinement.h:178
#define T_LED_SYNC_GRAY_CODE_SIZE_BITS
The amount of bits in the full gray code we're decoding.
Definition t_led_sync_refinement.h:30
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.
#define U_TIME_1US_IN_NS
The number of nanoseconds in a microsecond.
Definition u_time.h:61
#define ARRAY_SIZE(a)
Array size helper.
Definition xrt_compiler.h:59