This is the DW1000 driver and our self developed distance measurement application based on it. We do this as a semester thesis at ETH Zürich under the Automatic Control Laboratory in the Department of electrical engineering.

Dependencies:   mbed

main.cpp

Committer:
manumaet
Date:
2015-02-22
Revision:
39:bb57aa77b015
Parent:
38:8ef3b8d8b908
Child:
40:5ce51b7e3118

File content as of revision 39:bb57aa77b015:

// by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
#include "mbed.h"
#include "PC.h"                                     // Serial Port via USB for debugging with Terminal
#include "DW1000.h"                                 // our DW1000 device driver
#include "MMRanging.h"                              // our self developed raning application

PC          pc(USBTX, USBRX, 921600);               // USB UART Terminal
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] = "";

int main() {
    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());
    pc.printf("EUI register: %016llX\r\n", dw.getEUI());
    pc.printf("Voltage: %fV\r\n", dw.getVoltage());
    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
    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;
    else
        r.address = 0; // sender node has address 0
    pc.printf("Address: %d\r\n", r.address);
    wait(2);
    
    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
        } else {
            pc.printf("%lld\r\n", r.rangingtimingsReceiver[0][1] - r.rangingtimingsReceiver[0][0]);
        }
        
        
        
        #if 0 // Output bars on console
            for(int i = 1; i < 3; i++) {
                //pc.printf("%f ", r.tofs[j]*MMRANGING_TIMEUNIT_NS);
                pc.printf("%lld [", r.tofs[i]);
                int dots = r.tofs[i]*70/1400;
                if (abs(dots) < 10000)
                    for(int j = 0; j < dots; j++)
                        pc.printf("=");
                pc.printf("]\r\n");
            }
        #endif
        
        #if 0   // Output events for debugging
            for(int j = 0; j < 10; j++)
                if(r.event[j][0] == '!') {
                    pc.printf("%s\r\n", r.event[j]);
                    r.event[j][0] = 'X';
                }
            r.event_i = 0;
        #endif
        //pc.printf("Status: %llX\r\n", dw.getStatus());
        //pc.printf("TX Control: %llX\r\n", dw.readRegister40(DW1000_TX_FCTRL, 0));
        //pc.printf("\r\n");
        wait(0.02);
        //wait(0.1);
    }
}