Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Sun Mar 01 20:19:38 2015 +0000
Revision:
41:0a3bb028d4ba
Parent:
40:5ce51b7e3118
before following exactly manual initializing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 27:71178fdb78e1 1 // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
manumaet 27:71178fdb78e1 2
manumaet 27:71178fdb78e1 3 #ifndef MMRANGING_H
manumaet 27:71178fdb78e1 4 #define MMRANGING_H
manumaet 27:71178fdb78e1 5
manumaet 27:71178fdb78e1 6 #include "mbed.h"
manumaet 27:71178fdb78e1 7 #include "DW1000.h"
manumaet 27:71178fdb78e1 8
manumaet 39:bb57aa77b015 9 #define MMRANGING_TIMEUNIT_US 1/(128*499.2) // conversion between LSB of TX and RX timestamps and microseconds
manumaet 39:bb57aa77b015 10 #define MMRANGING_TIMEUNIT_NS 1000/(128*499.2) // conversion between LSB of TX and RX timestamps and nanoseconds
manumaet 39:bb57aa77b015 11
manumaet 39:bb57aa77b015 12 #define MMRANGING_2POWER40 1099511627776 // decimal value of 2^40 to correct timeroverflow between timestamps
manumaet 27:71178fdb78e1 13
manumaet 41:0a3bb028d4ba 14 //#define EVENTS // to see debug output of occurring interrupt callbacks
manumaet 40:5ce51b7e3118 15
manumaet 27:71178fdb78e1 16 class MMRanging {
manumaet 28:a830131560e8 17 public:
manumaet 28:a830131560e8 18 MMRanging(DW1000& DW);
manumaet 36:883de6f9a73b 19 void requestRanging(uint8_t destination);
manumaet 41:0a3bb028d4ba 20 void requestRangingAll();
manumaet 28:a830131560e8 21 //private:
manumaet 28:a830131560e8 22 DW1000& dw;
manumaet 41:0a3bb028d4ba 23 Timer LocalTimer;
manumaet 28:a830131560e8 24
manumaet 30:4ecc69d3cf8d 25 void callbackRX();
manumaet 30:4ecc69d3cf8d 26 void callbackTX();
manumaet 36:883de6f9a73b 27 void sendRangingframe(uint8_t destination, uint8_t sequence_number, uint8_t type, uint64_t time_difference_receiver);
manumaet 41:0a3bb028d4ba 28 uint64_t timeDifference40Bit(uint64_t early, uint64_t late); // Method to calculate the difference between two 40-Bit timestamps correcting timer overflow reset occurring between the timestamps
manumaet 30:4ecc69d3cf8d 29
manumaet 41:0a3bb028d4ba 30 uint8_t address; // Identifies the nodes as source and destination in rangingframes
manumaet 41:0a3bb028d4ba 31 //struct __attribute__((packed, aligned(1))) rangingframe { // TODO: avoid structure padding, 32-Bit enough for time_difference_receiver => 8 Byte per frame instead of 16
manumaet 34:f56962030c5c 32 struct rangingframe {
manumaet 36:883de6f9a73b 33 uint8_t source;
manumaet 36:883de6f9a73b 34 uint8_t destination;
manumaet 36:883de6f9a73b 35 uint8_t sequence_number;
manumaet 36:883de6f9a73b 36 uint8_t type;
manumaet 31:6f76f3d518ac 37 uint64_t time_difference_receiver;
manumaet 36:883de6f9a73b 38 };
manumaet 36:883de6f9a73b 39
manumaet 39:bb57aa77b015 40 rangingframe TX; // buffer in class for sending a frame (not made locally because then we can recall in the interrupt what was sent)
manumaet 31:6f76f3d518ac 41 uint64_t rangingtimingsSender[10][2];
manumaet 31:6f76f3d518ac 42 uint64_t rangingtimingsReceiver[10][2];
manumaet 41:0a3bb028d4ba 43 bool acknowledgement[10]; // flag to indicate if ranging has succeeded
manumaet 39:bb57aa77b015 44 uint64_t tofs[10]; // Array containing time of flights for each node (index is address of node)
manumaet 41:0a3bb028d4ba 45 float roundtriptimes[10]; // Array containing the round trip times to the anchors or the timeout which occured
manumaet 41:0a3bb028d4ba 46 float distances[10]; // Array containing the finally calculated Distances to the anchors
manumaet 31:6f76f3d518ac 47
manumaet 28:a830131560e8 48 // draft for first test
manumaet 28:a830131560e8 49 bool receiver;
manumaet 28:a830131560e8 50 int event_i;
manumaet 28:a830131560e8 51 char event[10][20];
manumaet 28:a830131560e8 52 uint8_t counter;
manumaet 27:71178fdb78e1 53 };
manumaet 27:71178fdb78e1 54
manumaet 27:71178fdb78e1 55 #endif