Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DecaWave by
main.cpp@44:2e0045042a59, 2015-03-05 (annotated)
- Committer:
- manumaet
- Date:
- Thu Mar 05 12:18:37 2015 +0000
- Revision:
- 44:2e0045042a59
- Parent:
- 43:d89fe237a684
- Child:
- 45:01a33363bc21
Two way distance ranging with several anchors works now (calibration and onboard trilateration still ahead)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| manumaet | 24:6f25ba679490 | 1 | // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015 |
| manumaet | 0:f50e671ffff7 | 2 | #include "mbed.h" |
| manumaet | 26:a65c6f26c458 | 3 | #include "PC.h" // Serial Port via USB for debugging with Terminal |
| manumaet | 27:71178fdb78e1 | 4 | #include "DW1000.h" // our DW1000 device driver |
| manumaet | 44:2e0045042a59 | 5 | #include "MM2WayRanging.h" // our self developed ranging application |
| manumaet | 44:2e0045042a59 | 6 | |
| manumaet | 44:2e0045042a59 | 7 | #define myprintf pc.printf // to make the code adaptable to other outputs that support printf |
| manumaet | 44:2e0045042a59 | 8 | |
| manumaet | 44:2e0045042a59 | 9 | PC pc(USBTX, USBRX, 921600); // USB UART Terminal |
| manumaet | 44:2e0045042a59 | 10 | DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ) |
| manumaet | 44:2e0045042a59 | 11 | MM2WayRanging node(dw); // Instance of the two way ranging algorithm |
| manumaet | 0:f50e671ffff7 | 12 | |
| manumaet | 44:2e0045042a59 | 13 | void rangeAndDisplayAll(){ |
| manumaet | 44:2e0045042a59 | 14 | node.requestRangingAll(); // Request ranging to all anchors |
| manumaet | 44:2e0045042a59 | 15 | for (int i = 1; i <= 4; i++) { // Output Results |
| manumaet | 44:2e0045042a59 | 16 | myprintf("D: %f, ", node.distances[i]); |
| manumaet | 44:2e0045042a59 | 17 | myprintf("T:%f", node.roundtriptimes[i]); |
| manumaet | 44:2e0045042a59 | 18 | myprintf("\r\n"); |
| manumaet | 44:2e0045042a59 | 19 | } |
| manumaet | 44:2e0045042a59 | 20 | myprintf("\r\n\n"); |
| manumaet | 44:2e0045042a59 | 21 | } |
| manumaet | 6:d5864a1b9e17 | 22 | |
| manumaet | 0:f50e671ffff7 | 23 | int main() { |
| manumaet | 44:2e0045042a59 | 24 | pc.printf("\r\nDecaWave 1.0 up and running!\r\n"); // Splashscreen |
| manumaet | 30:4ecc69d3cf8d | 25 | dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection |
| manumaet | 28:a830131560e8 | 26 | pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID()); |
| manumaet | 28:a830131560e8 | 27 | pc.printf("EUI register: %016llX\r\n", dw.getEUI()); |
| manumaet | 38:8ef3b8d8b908 | 28 | pc.printf("Voltage: %fV\r\n", dw.getVoltage()); |
| manumaet | 34:f56962030c5c | 29 | |
| manumaet | 44:2e0045042a59 | 30 | node.isAnchor = true; // declare as anchor or beacon |
| manumaet | 44:2e0045042a59 | 31 | if (node.isAnchor) { |
| manumaet | 44:2e0045042a59 | 32 | node.address = 1; |
| manumaet | 44:2e0045042a59 | 33 | myprintf("This node is Anchor node %d \r\n", node.address); |
| manumaet | 44:2e0045042a59 | 34 | } else { |
| manumaet | 44:2e0045042a59 | 35 | node.address = 0; |
| manumaet | 44:2e0045042a59 | 36 | myprintf("This node is a Beacon. "); |
| manumaet | 44:2e0045042a59 | 37 | } |
| manumaet | 32:041dd02e0e3b | 38 | |
| manumaet | 0:f50e671ffff7 | 39 | while(1) { |
| manumaet | 44:2e0045042a59 | 40 | if (!node.isAnchor) |
| manumaet | 44:2e0045042a59 | 41 | rangeAndDisplayAll(); |
| manumaet | 44:2e0045042a59 | 42 | else |
| manumaet | 44:2e0045042a59 | 43 | myprintf(".\r"); |
| manumaet | 44:2e0045042a59 | 44 | wait(0.3); |
| manumaet | 0:f50e671ffff7 | 45 | } |
| manumaet | 0:f50e671ffff7 | 46 | } |
