Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: main.cpp
- Revision:
- 40:5ce51b7e3118
- Parent:
- 39:bb57aa77b015
- Child:
- 41:0a3bb028d4ba
diff -r bb57aa77b015 -r 5ce51b7e3118 main.cpp --- a/main.cpp Sun Feb 22 17:40:38 2015 +0000 +++ b/main.cpp Fri Feb 27 11:47:51 2015 +0000 @@ -8,9 +8,15 @@ DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ) MMRanging r(dw); // Ranging class for getting distances and later positions -char message[100] = ""; +Timer LocalTimer; +float time_before; + +int average[50]; +int average_index = 0; +float averaged; int main() { + LocalTimer.start(); pc.printf("DecaWave 0.2\r\nup and running!\r\n"); dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID()); @@ -19,13 +25,13 @@ pc.printf("System Configuration: %llX\r\n", dw.readRegister40(DW1000_SYS_CFG, 0)); pc.printf("Size of Rangingframe: %d\r\n", sizeof(r.TX)); - uint16_t setdelay = 32300;//768; // TODO: = 2^15 + uint16_t setdelay = 32768; // TODO: = 2^15 dw.writeRegister16(DW1000_TX_ANTD, 0, setdelay); pc.printf("Antenna Delay TX: %d\r\n", dw.readRegister16(DW1000_TX_ANTD, 0)); pc.printf("Antenna Delay RX: %d\r\n", dw.readRegister16(DW1000_LDE_CTRL, 0x1804)); //r.receiver = true; if (r.receiver) - r.address = 2; + r.address = 1; else r.address = 0; // sender node has address 0 pc.printf("Address: %d\r\n", r.address); @@ -33,16 +39,30 @@ while(1) { if (!r.receiver) { // Request ranging - r.requestRanging(1); // TODO: ask all available nodes! - wait(0.005); - r.requestRanging(2); - wait(0.005); - pc.printf("%lld\r\n", r.tofs[2]); // logging output + for (int i = 1; i <= 4; i++) { + r.acknowledgement[i] = false; + r.requestRanging(i); // TODO: ask all available nodes in MMRanging + time_before = LocalTimer.read(); + while(!r.acknowledgement[i] && LocalTimer.read() < time_before + 0.5); + pc.printf("%f, ", (r.tofs[i]*300/MMRANGING_TIMEUNIT_US / 2) - 0.5); + //pc.printf("%2.6fs\r\n", LocalTimer.read() - time_before); + } + pc.printf("\r\n"); // logging output } else { - pc.printf("%lld\r\n", r.rangingtimingsReceiver[0][1] - r.rangingtimingsReceiver[0][0]); + //pc.printf("%lld\r\n", r.timeDifference40Bit(r.rangingtimingsReceiver[0][0], r.rangingtimingsReceiver[0][1])); } - + #if 0 + pc.printf("Distance: %f\r\n", (r.tofs[2]*300/MMRANGING_TIMEUNIT_US / 2) - 0.5); + average[average_index] = r.tofs[2]; + average_index++; + if(average_index == 50) + average_index = 0; + for(int i = 0; i < 50; i++) + averaged += average[i]; + averaged /= 50; + pc.printf("Distance: %f\r\n", (averaged*300/MMRANGING_TIMEUNIT_US / 2) - 0.5); + #endif #if 0 // Output bars on console for(int i = 1; i < 3; i++) { @@ -56,7 +76,7 @@ } #endif - #if 0 // Output events for debugging + #ifdef EVENTS // Output interrupt callback events for debugging (defined in MMRanging.h) for(int j = 0; j < 10; j++) if(r.event[j][0] == '!') { pc.printf("%s\r\n", r.event[j]); @@ -68,6 +88,6 @@ //pc.printf("TX Control: %llX\r\n", dw.readRegister40(DW1000_TX_FCTRL, 0)); //pc.printf("\r\n"); wait(0.02); - //wait(0.1); + wait(0.2); } } \ No newline at end of file