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.
main.cpp@0:99928431bb44, 2015-07-07 (annotated)
- Committer:
- millanea
- Date:
- Tue Jul 07 09:36:12 2015 +0000
- Revision:
- 0:99928431bb44
First commit. Committing the entire project such that it can be published.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
millanea | 0:99928431bb44 | 1 | /* |
millanea | 0:99928431bb44 | 2 | * Author: Alex Millane (millanea@ethz.ch) |
millanea | 0:99928431bb44 | 3 | * Matthias Grob |
millanea | 0:99928431bb44 | 4 | * Manuel Stalder |
millanea | 0:99928431bb44 | 5 | * Date: 04/06/2015 |
millanea | 0:99928431bb44 | 6 | * Purpose: Implements nodes which form a localization network. |
millanea | 0:99928431bb44 | 7 | * Localization is performed using Decawave DW1000 ranging |
millanea | 0:99928431bb44 | 8 | * UWB radios. Additionally initial measurements from the |
millanea | 0:99928431bb44 | 9 | * px4 flight controller are used. The project implements |
millanea | 0:99928431bb44 | 10 | * three nodes: |
millanea | 0:99928431bb44 | 11 | * - Beacon: Initiates message transmissions, calculates |
millanea | 0:99928431bb44 | 12 | ranges and sends them to the observer node. |
millanea | 0:99928431bb44 | 13 | - Anchor: Received ranging messages and sends calculated |
millanea | 0:99928431bb44 | 14 | time of flight values to the Beacon. |
millanea | 0:99928431bb44 | 15 | - Observer: Receives calculated ranges from the beacon and |
millanea | 0:99928431bb44 | 16 | passes them out over a serial connection to a |
millanea | 0:99928431bb44 | 17 | host performing estimation. Additionally passes |
millanea | 0:99928431bb44 | 18 | mavlink messages out over the same serial connection. |
millanea | 0:99928431bb44 | 19 | */ |
millanea | 0:99928431bb44 | 20 | |
millanea | 0:99928431bb44 | 21 | // Includes |
millanea | 0:99928431bb44 | 22 | #include "mbed.h" |
millanea | 0:99928431bb44 | 23 | #include "DW1000.h" |
millanea | 0:99928431bb44 | 24 | #include "MM2WayRanging.h" |
millanea | 0:99928431bb44 | 25 | #include "Node.h" |
millanea | 0:99928431bb44 | 26 | #include "Beacon.h" |
millanea | 0:99928431bb44 | 27 | #include "Anchor.h" |
millanea | 0:99928431bb44 | 28 | #include "Observer.h" |
millanea | 0:99928431bb44 | 29 | #include "debug.h" |
millanea | 0:99928431bb44 | 30 | |
millanea | 0:99928431bb44 | 31 | // Initializing hardware devices |
millanea | 0:99928431bb44 | 32 | Serial serialUSB(USBTX, USBRX) ; // UART2 |
millanea | 0:99928431bb44 | 33 | Serial serial1(PA_9,PA_10) ; // UART1 |
millanea | 0:99928431bb44 | 34 | Serial serial6(PA_11,PA_12) ; // UART6 |
millanea | 0:99928431bb44 | 35 | |
millanea | 0:99928431bb44 | 36 | // Observer Defines |
millanea | 0:99928431bb44 | 37 | Serial& mavlinkIn = serial6 ; |
millanea | 0:99928431bb44 | 38 | Serial& framesOut = serial1 ; |
millanea | 0:99928431bb44 | 39 | |
millanea | 0:99928431bb44 | 40 | // Ranging related objects |
millanea | 0:99928431bb44 | 41 | DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ) |
millanea | 0:99928431bb44 | 42 | MM2WayRanging ranging(dw); // Instance of the two way ranging algorithm |
millanea | 0:99928431bb44 | 43 | |
millanea | 0:99928431bb44 | 44 | // Node factory function |
millanea | 0:99928431bb44 | 45 | Node& createNode( NodeType nodeType ) ; |
millanea | 0:99928431bb44 | 46 | |
millanea | 0:99928431bb44 | 47 | // Main programm |
millanea | 0:99928431bb44 | 48 | int main() { |
millanea | 0:99928431bb44 | 49 | |
millanea | 0:99928431bb44 | 50 | // Setting the baud rates of the serial connections |
millanea | 0:99928431bb44 | 51 | serialUSB.baud(57600) ; |
millanea | 0:99928431bb44 | 52 | serial1.baud(57600) ; |
millanea | 0:99928431bb44 | 53 | serial6.baud(57600) ; |
millanea | 0:99928431bb44 | 54 | |
millanea | 0:99928431bb44 | 55 | // Debug start up messages |
millanea | 0:99928431bb44 | 56 | debugprintf("Alex Ranging\r\n") ; |
millanea | 0:99928431bb44 | 57 | dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection |
millanea | 0:99928431bb44 | 58 | debugprintf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID()); |
millanea | 0:99928431bb44 | 59 | debugprintf("EUI register: %016llX\r\n", dw.getEUI()); |
millanea | 0:99928431bb44 | 60 | debugprintf("Voltage: %fV\r\n", dw.getVoltage()); |
millanea | 0:99928431bb44 | 61 | |
millanea | 0:99928431bb44 | 62 | // Setting the node parameters |
millanea | 0:99928431bb44 | 63 | NodeType nodeType = OBSERVER ; //ANCHOR ; BEACON ; OBSERVER ; |
millanea | 0:99928431bb44 | 64 | uint8_t nodeAddress = 5 ; |
millanea | 0:99928431bb44 | 65 | |
millanea | 0:99928431bb44 | 66 | // Creating the node |
millanea | 0:99928431bb44 | 67 | Node& node = createNode( nodeType ) ; |
millanea | 0:99928431bb44 | 68 | node.setAddress(nodeAddress) ; |
millanea | 0:99928431bb44 | 69 | |
millanea | 0:99928431bb44 | 70 | // Executing the application |
millanea | 0:99928431bb44 | 71 | while(1){ |
millanea | 0:99928431bb44 | 72 | // Calling the node functionality |
millanea | 0:99928431bb44 | 73 | node.execute() ; |
millanea | 0:99928431bb44 | 74 | } |
millanea | 0:99928431bb44 | 75 | |
millanea | 0:99928431bb44 | 76 | } |
millanea | 0:99928431bb44 | 77 | |
millanea | 0:99928431bb44 | 78 | // Node factory function |
millanea | 0:99928431bb44 | 79 | Node& createNode( NodeType nodeType ) { |
millanea | 0:99928431bb44 | 80 | |
millanea | 0:99928431bb44 | 81 | // Creating different node types dependant on argument |
millanea | 0:99928431bb44 | 82 | if( nodeType == ANCHOR ){ |
millanea | 0:99928431bb44 | 83 | Anchor* anchor = new Anchor( ranging, dw ) ; |
millanea | 0:99928431bb44 | 84 | return *anchor ; |
millanea | 0:99928431bb44 | 85 | } |
millanea | 0:99928431bb44 | 86 | else if( nodeType == BEACON ){ |
millanea | 0:99928431bb44 | 87 | Beacon* beacon = new Beacon( ranging, dw ) ; |
millanea | 0:99928431bb44 | 88 | return *beacon ; |
millanea | 0:99928431bb44 | 89 | } |
millanea | 0:99928431bb44 | 90 | else { // if( nodeType == OBSERVER ){ |
millanea | 0:99928431bb44 | 91 | Observer* observer = new Observer( ranging, dw, framesOut, mavlinkIn ) ; |
millanea | 0:99928431bb44 | 92 | return *observer ; |
millanea | 0:99928431bb44 | 93 | } |
millanea | 0:99928431bb44 | 94 | } |