From 2a78201a2dc923fdf7a34b33ca98e93231522eeb Mon Sep 17 00:00:00 2001 From: salty Date: Sat, 14 Mar 2026 13:01:04 -0400 Subject: [PATCH] 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. --- esp32/uwb_anchor/src/main.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/esp32/uwb_anchor/src/main.cpp b/esp32/uwb_anchor/src/main.cpp index e423b6e..c9ae1ed 100644 --- a/esp32/uwb_anchor/src/main.cpp +++ b/esp32/uwb_anchor/src/main.cpp @@ -195,8 +195,21 @@ void setup(void) { /* ── 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) { serial_poll(); espnow_process(); - DW1000Ranging.loop(); + + uint32_t slot = (millis() / SLOT_MS) % NUM_ANCHORS_TOTAL; + if (slot == ANCHOR_ID) { + DW1000Ranging.loop(); + } }