fix: time-division multiplexing for 2-anchor collision avoidance

Each anchor only runs DW1000Ranging during its 50ms time slot.
Anchor 0 responds in even slots, anchor 1 in odd slots.
Prevents RF collisions that caused wild range readings.
This commit is contained in:
salty 2026-03-14 13:01:04 -04:00
parent 9ed3e06fb8
commit 2a78201a2d

View File

@ -195,8 +195,21 @@ void setup(void) {
/* ── Loop ───────────────────────────────────────────────────────── */ /* ── Loop ───────────────────────────────────────────────────────── */
/*
* Time-division multiplexing: 2 anchors share the same channel.
* Each anchor only responds during its time slot to avoid RF collisions.
* Slot duration = 50ms each anchor gets 10 Hz effective rate.
* Anchor 0 responds during even slots, anchor 1 during odd slots.
*/
#define SLOT_MS 50
#define NUM_ANCHORS_TOTAL 2
void loop(void) { void loop(void) {
serial_poll(); serial_poll();
espnow_process(); espnow_process();
DW1000Ranging.loop();
uint32_t slot = (millis() / SLOT_MS) % NUM_ANCHORS_TOTAL;
if (slot == ANCHOR_ID) {
DW1000Ranging.loop();
}
} }