Anchor (esp32/uwb_anchor): - DW1000Ranging library (200m range, MODE_LONGDATA_RANGE_ACCURACY) - Unique addresses per anchor (anchor0/anchor1 build envs) - +RANGE output: anchor_id, tag_addr, range_mm, rssi - ESP-NOW receiver: forwards tag packets + priority E-STOP to Jetson - AT+ID? command Tag with Display (esp32/uwb_tag): - DW1000Ranging as tag, auto-discovers anchors - SSD1306 OLED: big distance, per-anchor ranges, RSSI bars, link status - ESP-NOW broadcast: range/heartbeat/estop packets - E-Stop on GPIO 0 (BOOT button), 10Hz TX while held - Display at 5Hz, ranging driven by DW1000Ranging.loop() Shared: - lib/DW1000/ extracted from mf_DW1000.zip (Makerfabs fork) - lib_extra_dirs for PlatformIO to find local library
53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
/**
|
|
*
|
|
* @todo
|
|
* - move strings to flash (less RAM consumption)
|
|
* - fix deprecated convertation form string to char* startAsAnchor
|
|
* - give example description
|
|
*/
|
|
#include <SPI.h>
|
|
#include "DW1000Ranging.h"
|
|
|
|
// connection pins
|
|
const uint8_t PIN_RST = 9; // reset pin
|
|
const uint8_t PIN_IRQ = 2; // irq pin
|
|
const uint8_t PIN_SS = SS; // spi select pin
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(1000);
|
|
//init the configuration
|
|
DW1000Ranging.initCommunication(PIN_RST, PIN_SS, PIN_IRQ); //Reset, CS, IRQ pin
|
|
//define the sketch as anchor. It will be great to dynamically change the type of module
|
|
DW1000Ranging.attachNewRange(newRange);
|
|
DW1000Ranging.attachBlinkDevice(newBlink);
|
|
DW1000Ranging.attachInactiveDevice(inactiveDevice);
|
|
//Enable the filter to smooth the distance
|
|
//DW1000Ranging.useRangeFilter(true);
|
|
|
|
//we start the module as an anchor
|
|
DW1000Ranging.startAsAnchor("82:17:5B:D5:A9:9A:E2:9C", DW1000.MODE_LONGDATA_RANGE_ACCURACY);
|
|
}
|
|
|
|
void loop() {
|
|
DW1000Ranging.loop();
|
|
}
|
|
|
|
void newRange() {
|
|
Serial.print("from: "); Serial.print(DW1000Ranging.getDistantDevice()->getShortAddress(), HEX);
|
|
Serial.print("\t Range: "); Serial.print(DW1000Ranging.getDistantDevice()->getRange()); Serial.print(" m");
|
|
Serial.print("\t RX power: "); Serial.print(DW1000Ranging.getDistantDevice()->getRXPower()); Serial.println(" dBm");
|
|
}
|
|
|
|
void newBlink(DW1000Device* device) {
|
|
Serial.print("blink; 1 device added ! -> ");
|
|
Serial.print(" short:");
|
|
Serial.println(device->getShortAddress(), HEX);
|
|
}
|
|
|
|
void inactiveDevice(DW1000Device* device) {
|
|
Serial.print("delete inactive device: ");
|
|
Serial.println(device->getShortAddress(), HEX);
|
|
}
|
|
|