Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Sun Feb 22 17:40:38 2015 +0000
Revision:
39:bb57aa77b015
Parent:
38:8ef3b8d8b908
Child:
40:5ce51b7e3118
setup to find the 40 bit overflow in the timestamps, seems to be fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 24:6f25ba679490 1 // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
manumaet 0:f50e671ffff7 2 #include "mbed.h"
manumaet 26:a65c6f26c458 3 #include "PC.h" // Serial Port via USB for debugging with Terminal
manumaet 27:71178fdb78e1 4 #include "DW1000.h" // our DW1000 device driver
manumaet 27:71178fdb78e1 5 #include "MMRanging.h" // our self developed raning application
manumaet 0:f50e671ffff7 6
manumaet 26:a65c6f26c458 7 PC pc(USBTX, USBRX, 921600); // USB UART Terminal
manumaet 30:4ecc69d3cf8d 8 DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ)
manumaet 28:a830131560e8 9 MMRanging r(dw); // Ranging class for getting distances and later positions
manumaet 14:8041c9b68406 10
manumaet 28:a830131560e8 11 char message[100] = "";
manumaet 6:d5864a1b9e17 12
manumaet 0:f50e671ffff7 13 int main() {
manumaet 27:71178fdb78e1 14 pc.printf("DecaWave 0.2\r\nup and running!\r\n");
manumaet 30:4ecc69d3cf8d 15 dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
manumaet 28:a830131560e8 16 pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID());
manumaet 28:a830131560e8 17 pc.printf("EUI register: %016llX\r\n", dw.getEUI());
manumaet 38:8ef3b8d8b908 18 pc.printf("Voltage: %fV\r\n", dw.getVoltage());
manumaet 38:8ef3b8d8b908 19 pc.printf("System Configuration: %llX\r\n", dw.readRegister40(DW1000_SYS_CFG, 0));
manumaet 38:8ef3b8d8b908 20 pc.printf("Size of Rangingframe: %d\r\n", sizeof(r.TX));
manumaet 34:f56962030c5c 21
manumaet 38:8ef3b8d8b908 22 uint16_t setdelay = 32300;//768; // TODO: = 2^15
manumaet 34:f56962030c5c 23 dw.writeRegister16(DW1000_TX_ANTD, 0, setdelay);
manumaet 34:f56962030c5c 24 pc.printf("Antenna Delay TX: %d\r\n", dw.readRegister16(DW1000_TX_ANTD, 0));
manumaet 34:f56962030c5c 25 pc.printf("Antenna Delay RX: %d\r\n", dw.readRegister16(DW1000_LDE_CTRL, 0x1804));
manumaet 39:bb57aa77b015 26 //r.receiver = true;
manumaet 36:883de6f9a73b 27 if (r.receiver)
manumaet 38:8ef3b8d8b908 28 r.address = 2;
manumaet 36:883de6f9a73b 29 else
manumaet 36:883de6f9a73b 30 r.address = 0; // sender node has address 0
manumaet 36:883de6f9a73b 31 pc.printf("Address: %d\r\n", r.address);
manumaet 36:883de6f9a73b 32 wait(2);
manumaet 32:041dd02e0e3b 33
manumaet 0:f50e671ffff7 34 while(1) {
manumaet 36:883de6f9a73b 35 if (!r.receiver) { // Request ranging
manumaet 36:883de6f9a73b 36 r.requestRanging(1); // TODO: ask all available nodes!
manumaet 36:883de6f9a73b 37 wait(0.005);
manumaet 38:8ef3b8d8b908 38 r.requestRanging(2);
manumaet 38:8ef3b8d8b908 39 wait(0.005);
manumaet 39:bb57aa77b015 40 pc.printf("%lld\r\n", r.tofs[2]); // logging output
manumaet 39:bb57aa77b015 41 } else {
manumaet 39:bb57aa77b015 42 pc.printf("%lld\r\n", r.rangingtimingsReceiver[0][1] - r.rangingtimingsReceiver[0][0]);
manumaet 36:883de6f9a73b 43 }
manumaet 36:883de6f9a73b 44
manumaet 39:bb57aa77b015 45
manumaet 38:8ef3b8d8b908 46
manumaet 39:bb57aa77b015 47 #if 0 // Output bars on console
manumaet 38:8ef3b8d8b908 48 for(int i = 1; i < 3; i++) {
manumaet 38:8ef3b8d8b908 49 //pc.printf("%f ", r.tofs[j]*MMRANGING_TIMEUNIT_NS);
manumaet 38:8ef3b8d8b908 50 pc.printf("%lld [", r.tofs[i]);
manumaet 38:8ef3b8d8b908 51 int dots = r.tofs[i]*70/1400;
manumaet 38:8ef3b8d8b908 52 if (abs(dots) < 10000)
manumaet 38:8ef3b8d8b908 53 for(int j = 0; j < dots; j++)
manumaet 38:8ef3b8d8b908 54 pc.printf("=");
manumaet 38:8ef3b8d8b908 55 pc.printf("]\r\n");
manumaet 38:8ef3b8d8b908 56 }
manumaet 38:8ef3b8d8b908 57 #endif
manumaet 36:883de6f9a73b 58
manumaet 39:bb57aa77b015 59 #if 0 // Output events for debugging
manumaet 36:883de6f9a73b 60 for(int j = 0; j < 10; j++)
manumaet 36:883de6f9a73b 61 if(r.event[j][0] == '!') {
manumaet 36:883de6f9a73b 62 pc.printf("%s\r\n", r.event[j]);
manumaet 36:883de6f9a73b 63 r.event[j][0] = 'X';
manumaet 36:883de6f9a73b 64 }
manumaet 36:883de6f9a73b 65 r.event_i = 0;
manumaet 36:883de6f9a73b 66 #endif
manumaet 39:bb57aa77b015 67 //pc.printf("Status: %llX\r\n", dw.getStatus());
manumaet 39:bb57aa77b015 68 //pc.printf("TX Control: %llX\r\n", dw.readRegister40(DW1000_TX_FCTRL, 0));
manumaet 38:8ef3b8d8b908 69 //pc.printf("\r\n");
manumaet 39:bb57aa77b015 70 wait(0.02);
manumaet 39:bb57aa77b015 71 //wait(0.1);
manumaet 0:f50e671ffff7 72 }
manumaet 0:f50e671ffff7 73 }