Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Revision:
44:2e0045042a59
Child:
45:01a33363bc21
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MM2WayRanging/MM2WayRanging.h	Thu Mar 05 12:18:37 2015 +0000
@@ -0,0 +1,73 @@
+// by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
+
+#ifndef MM2WAYRANGING_H
+#define MM2WAYRANGING_H
+
+#include "mbed.h"
+#include "DW1000.h"
+
+#define TIMEUNITS_TO_US       (1/(128*499.2))               // conversion between the decawave timeunits (ca 15.65ps) to microseconds.
+#define US_TO_TIMEUNITS       (128*499.2)                   // conversion between microseconds to the decawave timeunits (ca 15.65ps).
+#define MMRANGING_2POWER40    1099511627776                 // decimal value of 2^40 to correct timeroverflow between timestamps
+
+//Predefined delay for the critical answers in the ranging algorithm
+//HAS TO BE BIGGER THAN THE PROCESSING TIME OF THE FRAME ON THE NODE
+#define ANSWER_DELAY_US             900
+#define ANSWER_DELAY_TIMEUNITS      50000000    //Alternative: ANSWER_DELAY_US * (128*499.2)
+
+class MM2WayRanging {
+    public:
+        MM2WayRanging(DW1000& DW);
+    
+        void requestRanging(uint8_t destination);
+        void requestRangingAll();
+
+        // TODO: Better capsulation on those?
+        bool isAnchor;
+        uint8_t address; // Identifies the nodes as source and destination in rangingframes
+
+        float roundtriptimes[10]; // Array containing the round trip times to the anchors or the timeout which occured
+        float distances[10]; // Array containing the finally calculated Distances to the anchors
+    
+    private:
+        DW1000& dw;
+        Timer LocalTimer;
+    
+        void callbackRX();
+        void callbackTX();
+        void sendPingFrame(uint8_t destination);
+        void sendDelayedAnswer(uint8_t destination, uint8_t type, uint64_t rxTimestamp);
+        void sendTransferFrame(uint8_t destination, int timestamp);
+    
+        int timediffRec;
+        int timediffSend;
+    
+        enum FrameType{
+            PING=1,
+            ANCHOR_RESPONSE,
+            BEACON_RESPONSE,
+            TRANSFER_FRAME
+        };
+    
+        struct RangingFrame {
+            uint8_t source;
+            uint8_t destination;
+            uint8_t type;
+        };
+    
+        struct ExtendedRangingFrame : RangingFrame{
+            int signedTime;
+        };
+    
+        RangingFrame rangingFrame;                  // buffer in class for sending a frame (not made locally because then we can recall in the interrupt what was sent)
+        ExtendedRangingFrame transferFrame;
+        ExtendedRangingFrame receivedFrame;
+        uint64_t rxTimestamp;
+        uint64_t senderTimestamps[10][3];
+        uint64_t receiverTimestamps[10][3];
+        bool acknowledgement[10];                   // flag to indicate if ranging has succeeded
+        uint32_t tofs[10];                          // Array containing time of flights for each node (index is address of node)
+
+};
+
+#endif
\ No newline at end of file