Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
MMRanging/MMRanging.h@40:5ce51b7e3118, 2015-02-27 (annotated)
- Committer:
- manumaet
- Date:
- Fri Feb 27 11:47:51 2015 +0000
- Revision:
- 40:5ce51b7e3118
- Parent:
- 39:bb57aa77b015
- Child:
- 41:0a3bb028d4ba
distance to 4 anchors works and is visible in MATLAB, before cleanup and calibration
Who changed what in which revision?
User | Revision | Line number | New 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 | 40:5ce51b7e3118 | 14 | //#define EVENTS // to see debug output of occuring 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 | 28:a830131560e8 | 20 | //private: |
manumaet | 28:a830131560e8 | 21 | DW1000& dw; |
manumaet | 28:a830131560e8 | 22 | |
manumaet | 30:4ecc69d3cf8d | 23 | void callbackRX(); |
manumaet | 30:4ecc69d3cf8d | 24 | void callbackTX(); |
manumaet | 36:883de6f9a73b | 25 | void sendRangingframe(uint8_t destination, uint8_t sequence_number, uint8_t type, uint64_t time_difference_receiver); |
manumaet | 39:bb57aa77b015 | 26 | uint64_t timeDifference40Bit(uint64_t early, uint64_t late); // Method to calculate the difference between two 40-Bit timestamps correcting timer overflow reset between the timestamps |
manumaet | 30:4ecc69d3cf8d | 27 | |
manumaet | 39:bb57aa77b015 | 28 | uint8_t address; // Identifies the node, source and destination in rangingframes |
manumaet | 34:f56962030c5c | 29 | struct rangingframe { |
manumaet | 36:883de6f9a73b | 30 | uint8_t source; |
manumaet | 36:883de6f9a73b | 31 | uint8_t destination; |
manumaet | 36:883de6f9a73b | 32 | uint8_t sequence_number; |
manumaet | 36:883de6f9a73b | 33 | uint8_t type; |
manumaet | 31:6f76f3d518ac | 34 | uint64_t time_difference_receiver; |
manumaet | 36:883de6f9a73b | 35 | }; |
manumaet | 36:883de6f9a73b | 36 | |
manumaet | 39:bb57aa77b015 | 37 | 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 | 38 | uint64_t rangingtimingsSender[10][2]; |
manumaet | 31:6f76f3d518ac | 39 | uint64_t rangingtimingsReceiver[10][2]; |
manumaet | 39:bb57aa77b015 | 40 | uint64_t tofs[10]; // Array containing time of flights for each node (index is address of node) |
manumaet | 40:5ce51b7e3118 | 41 | bool acknowledgement[10]; |
manumaet | 31:6f76f3d518ac | 42 | |
manumaet | 28:a830131560e8 | 43 | // draft for first test |
manumaet | 28:a830131560e8 | 44 | bool receiver; |
manumaet | 28:a830131560e8 | 45 | int event_i; |
manumaet | 28:a830131560e8 | 46 | char event[10][20]; |
manumaet | 28:a830131560e8 | 47 | uint8_t counter; |
manumaet | 27:71178fdb78e1 | 48 | }; |
manumaet | 27:71178fdb78e1 | 49 | |
manumaet | 27:71178fdb78e1 | 50 | #endif |