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

Revision:
45:01a33363bc21
Parent:
44:2e0045042a59
Child:
46:6398237672a0
--- a/main.cpp	Thu Mar 05 12:18:37 2015 +0000
+++ b/main.cpp	Sun Mar 08 15:59:14 2015 +0000
@@ -12,14 +12,72 @@
 
 void rangeAndDisplayAll(){
     node.requestRangingAll();                       // Request ranging to all anchors
-    for (int i = 1; i <= 4; i++) {                  // Output Results
-        myprintf("D: %f, ", node.distances[i]);
-        myprintf("T:%f", node.roundtriptimes[i]);
-        myprintf("\r\n");
+    for (int i = 1; i <= 5; i++) {                  // Output Results
+        myprintf("%f, ", node.distances[i]);
+        //myprintf("T:%f", node.roundtriptimes[i]);
+        //myprintf("\r\n");
     }
-    myprintf("\r\n\n");
+    myprintf("\r\n");
 }
 
+void calibrationRanging(int destination){
+
+    const int numberOfRangings = 100;
+    float rangings[numberOfRangings];
+    int index = 0;
+    float mean = 0;
+    float start, stop;
+
+    Timer localTimer;
+    localTimer.start();
+
+    start = localTimer.read();
+
+    while (1) {
+
+        node.requestRanging(destination);
+        if(node.overflow){
+            myprintf("Overflow! Measured: %f\r\n", node.distances[destination]);
+        }
+
+        if (node.distances[destination] == -1) {
+            myprintf("Measurement timed out\r\n");
+            wait(0.001);
+            continue;
+        }
+
+        if (node.distances[destination] < 100) {
+            rangings[index] = node.distances[destination];
+            //myprintf("%f\r\n", node.distances[destination]);
+            index++;
+
+            if (index == numberOfRangings) {
+            stop = localTimer.read();
+
+                for (int i = 0; i < numberOfRangings - 1; i++)
+                    rangings[numberOfRangings - 1] += rangings[i];
+
+                mean = rangings[numberOfRangings - 1] / numberOfRangings;
+                myprintf("\r\n\r\nMean %i: %f\r\n", destination, mean);
+                myprintf("Elapsed Time for %i: %f\r\n", numberOfRangings, stop - start);
+
+                mean = 0;
+                index = 0;
+
+                //wait(2);
+
+                start = localTimer.read();
+            }
+        }
+
+        else myprintf("%f\r\n", node.distances[destination]);
+
+    }
+
+}
+
+// -----------------------------------------------------------------------------------------------
+
 int main() {
     pc.printf("\r\nDecaWave 1.0   up and running!\r\n");            // Splashscreen
     dw.setEUI(0xFAEDCD01FAEDCD01);                                  // basic methods called to check if we have a working SPI connection
@@ -27,7 +85,8 @@
     pc.printf("EUI register: %016llX\r\n", dw.getEUI());
     pc.printf("Voltage: %fV\r\n", dw.getVoltage());
     
-    node.isAnchor = true;                                           // declare as anchor or beacon
+    node.isAnchor = false;
+                                               // declare as anchor or beacon
     if (node.isAnchor) {
         node.address = 1;
         myprintf("This node is Anchor node %d \r\n", node.address);
@@ -37,10 +96,15 @@
     }
     
     while(1) {
-        if (!node.isAnchor)
+        if (!node.isAnchor){
             rangeAndDisplayAll();
-        else
+            //calibrationRanging(4);
+
+
+            
+        }else
             myprintf(".\r");
-        wait(0.3);
+            
+            wait(0.3);
     }
 }
\ No newline at end of file