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

Committer:
manumaet
Date:
Thu Mar 05 12:18:37 2015 +0000
Revision:
44:2e0045042a59
Child:
45:01a33363bc21
Two way distance ranging with several anchors works now (calibration and onboard trilateration still ahead)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 44:2e0045042a59 1 // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
manumaet 44:2e0045042a59 2
manumaet 44:2e0045042a59 3 #ifndef MM2WAYRANGING_H
manumaet 44:2e0045042a59 4 #define MM2WAYRANGING_H
manumaet 44:2e0045042a59 5
manumaet 44:2e0045042a59 6 #include "mbed.h"
manumaet 44:2e0045042a59 7 #include "DW1000.h"
manumaet 44:2e0045042a59 8
manumaet 44:2e0045042a59 9 #define TIMEUNITS_TO_US (1/(128*499.2)) // conversion between the decawave timeunits (ca 15.65ps) to microseconds.
manumaet 44:2e0045042a59 10 #define US_TO_TIMEUNITS (128*499.2) // conversion between microseconds to the decawave timeunits (ca 15.65ps).
manumaet 44:2e0045042a59 11 #define MMRANGING_2POWER40 1099511627776 // decimal value of 2^40 to correct timeroverflow between timestamps
manumaet 44:2e0045042a59 12
manumaet 44:2e0045042a59 13 //Predefined delay for the critical answers in the ranging algorithm
manumaet 44:2e0045042a59 14 //HAS TO BE BIGGER THAN THE PROCESSING TIME OF THE FRAME ON THE NODE
manumaet 44:2e0045042a59 15 #define ANSWER_DELAY_US 900
manumaet 44:2e0045042a59 16 #define ANSWER_DELAY_TIMEUNITS 50000000 //Alternative: ANSWER_DELAY_US * (128*499.2)
manumaet 44:2e0045042a59 17
manumaet 44:2e0045042a59 18 class MM2WayRanging {
manumaet 44:2e0045042a59 19 public:
manumaet 44:2e0045042a59 20 MM2WayRanging(DW1000& DW);
manumaet 44:2e0045042a59 21
manumaet 44:2e0045042a59 22 void requestRanging(uint8_t destination);
manumaet 44:2e0045042a59 23 void requestRangingAll();
manumaet 44:2e0045042a59 24
manumaet 44:2e0045042a59 25 // TODO: Better capsulation on those?
manumaet 44:2e0045042a59 26 bool isAnchor;
manumaet 44:2e0045042a59 27 uint8_t address; // Identifies the nodes as source and destination in rangingframes
manumaet 44:2e0045042a59 28
manumaet 44:2e0045042a59 29 float roundtriptimes[10]; // Array containing the round trip times to the anchors or the timeout which occured
manumaet 44:2e0045042a59 30 float distances[10]; // Array containing the finally calculated Distances to the anchors
manumaet 44:2e0045042a59 31
manumaet 44:2e0045042a59 32 private:
manumaet 44:2e0045042a59 33 DW1000& dw;
manumaet 44:2e0045042a59 34 Timer LocalTimer;
manumaet 44:2e0045042a59 35
manumaet 44:2e0045042a59 36 void callbackRX();
manumaet 44:2e0045042a59 37 void callbackTX();
manumaet 44:2e0045042a59 38 void sendPingFrame(uint8_t destination);
manumaet 44:2e0045042a59 39 void sendDelayedAnswer(uint8_t destination, uint8_t type, uint64_t rxTimestamp);
manumaet 44:2e0045042a59 40 void sendTransferFrame(uint8_t destination, int timestamp);
manumaet 44:2e0045042a59 41
manumaet 44:2e0045042a59 42 int timediffRec;
manumaet 44:2e0045042a59 43 int timediffSend;
manumaet 44:2e0045042a59 44
manumaet 44:2e0045042a59 45 enum FrameType{
manumaet 44:2e0045042a59 46 PING=1,
manumaet 44:2e0045042a59 47 ANCHOR_RESPONSE,
manumaet 44:2e0045042a59 48 BEACON_RESPONSE,
manumaet 44:2e0045042a59 49 TRANSFER_FRAME
manumaet 44:2e0045042a59 50 };
manumaet 44:2e0045042a59 51
manumaet 44:2e0045042a59 52 struct RangingFrame {
manumaet 44:2e0045042a59 53 uint8_t source;
manumaet 44:2e0045042a59 54 uint8_t destination;
manumaet 44:2e0045042a59 55 uint8_t type;
manumaet 44:2e0045042a59 56 };
manumaet 44:2e0045042a59 57
manumaet 44:2e0045042a59 58 struct ExtendedRangingFrame : RangingFrame{
manumaet 44:2e0045042a59 59 int signedTime;
manumaet 44:2e0045042a59 60 };
manumaet 44:2e0045042a59 61
manumaet 44:2e0045042a59 62 RangingFrame rangingFrame; // buffer in class for sending a frame (not made locally because then we can recall in the interrupt what was sent)
manumaet 44:2e0045042a59 63 ExtendedRangingFrame transferFrame;
manumaet 44:2e0045042a59 64 ExtendedRangingFrame receivedFrame;
manumaet 44:2e0045042a59 65 uint64_t rxTimestamp;
manumaet 44:2e0045042a59 66 uint64_t senderTimestamps[10][3];
manumaet 44:2e0045042a59 67 uint64_t receiverTimestamps[10][3];
manumaet 44:2e0045042a59 68 bool acknowledgement[10]; // flag to indicate if ranging has succeeded
manumaet 44:2e0045042a59 69 uint32_t tofs[10]; // Array containing time of flights for each node (index is address of node)
manumaet 44:2e0045042a59 70
manumaet 44:2e0045042a59 71 };
manumaet 44:2e0045042a59 72
manumaet 44:2e0045042a59 73 #endif