Benjamin Hepp / Mbed 2 deprecated AIT_UWB_Tracker

Dependencies:   DW1000 ait_link BufferedSerial mbed

Committer:
bhepp
Date:
Thu Feb 11 10:49:49 2016 +0000
Revision:
1:c070ca30da80
Child:
4:1a2c1e5e5516
Multi Ranging working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhepp 1:c070ca30da80 1 #include "settings.h"
bhepp 1:c070ca30da80 2
bhepp 1:c070ca30da80 3 #if BUILD_SLAVE
bhepp 1:c070ca30da80 4
bhepp 1:c070ca30da80 5 #include <mbed.h>
bhepp 1:c070ca30da80 6 #include <DW1000.h>
bhepp 1:c070ca30da80 7 #include <DW1000Utils.h>
bhepp 1:c070ca30da80 8 #include <mavlink_bridge/mavlink_bridge.h>
bhepp 1:c070ca30da80 9
bhepp 1:c070ca30da80 10 #include "PC.h"
bhepp 1:c070ca30da80 11 #include "UWBSlave.h"
bhepp 1:c070ca30da80 12
bhepp 1:c070ca30da80 13 using ait::UWBSlave;
bhepp 1:c070ca30da80 14
bhepp 1:c070ca30da80 15 using ait::MAVLinkBridge;
bhepp 1:c070ca30da80 16 using ait::UART_Mbed;
bhepp 1:c070ca30da80 17
bhepp 1:c070ca30da80 18 const int SPI_FREQUENCY = 1000000;
bhepp 1:c070ca30da80 19
bhepp 1:c070ca30da80 20 const int SLAVE_ADDRESS = 10;
bhepp 1:c070ca30da80 21
bhepp 1:c070ca30da80 22 const bool USE_NLOS_SETTINGS = true;
bhepp 1:c070ca30da80 23
bhepp 1:c070ca30da80 24 const PinName DW_RESET_PIN = D15;
bhepp 1:c070ca30da80 25 const PinName DW_MOSI_PIN = D11;
bhepp 1:c070ca30da80 26 const PinName DW_MISO_PIN = D12;
bhepp 1:c070ca30da80 27 const PinName DW_SCLK_PIN = D13;
bhepp 1:c070ca30da80 28 const PinName DW_IRQ_PIN = D14;
bhepp 1:c070ca30da80 29 const PinName DW_CS_PIN = D10;
bhepp 1:c070ca30da80 30
bhepp 1:c070ca30da80 31 PC pc(USBTX, USBRX, 115200); // USB UART Terminal
bhepp 1:c070ca30da80 32
bhepp 1:c070ca30da80 33 int main()
bhepp 1:c070ca30da80 34 {
bhepp 1:c070ca30da80 35 UART_Mbed uart(USBTX, USBRX, 115200);
bhepp 1:c070ca30da80 36 MAVLinkBridge mb(&uart);
bhepp 1:c070ca30da80 37
bhepp 1:c070ca30da80 38 pc.printf("==== AIT UWB Multi Range Slave ====\r\n");
bhepp 1:c070ca30da80 39
bhepp 1:c070ca30da80 40 SPI spi(DW_MOSI_PIN, DW_MISO_PIN, DW_SCLK_PIN);
bhepp 1:c070ca30da80 41 spi.format(8, 0); // Setup the spi for standard 8 bit data and SPI-Mode 0 (GPIO5, GPIO6 open circuit or ground on DW1000)
bhepp 1:c070ca30da80 42 // NOTE: Minimum Frequency 1MHz. Below it is now working. Could be something with the activation and deactivation of interrupts.
bhepp 1:c070ca30da80 43 spi.frequency(SPI_FREQUENCY); // with a 1MHz clock rate (worked up to 49MHz in our Test)
bhepp 1:c070ca30da80 44
bhepp 1:c070ca30da80 45 Timer timer;
bhepp 1:c070ca30da80 46 timer.start();
bhepp 1:c070ca30da80 47
bhepp 1:c070ca30da80 48 InterruptIn irq(DW_IRQ_PIN);
bhepp 1:c070ca30da80 49
bhepp 1:c070ca30da80 50 pc.printf("Performing hardware reset of UWB modules\r\n");
bhepp 1:c070ca30da80 51 // == IMPORTANT == Create all DW objects first (this will cause a reset of the DW module)
bhepp 1:c070ca30da80 52 DW1000::hardwareReset(DW_RESET_PIN);
bhepp 1:c070ca30da80 53
bhepp 1:c070ca30da80 54 // Initialize the DW module
bhepp 1:c070ca30da80 55 DW1000 dw(spi, irq, DW_CS_PIN);
bhepp 1:c070ca30da80 56 dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
bhepp 1:c070ca30da80 57 pc.printf("\r\nDecaWave 1.0 up and running!\r\n"); // Splashscreen
bhepp 1:c070ca30da80 58 pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID());
bhepp 1:c070ca30da80 59 pc.printf("EUI register: %016llX\r\n", dw.getEUI());
bhepp 1:c070ca30da80 60 pc.printf("Voltage: %.2fV\r\n", dw.getVoltage());
bhepp 1:c070ca30da80 61
bhepp 1:c070ca30da80 62 // Set NLOS settings (According to DecaWave Application Note APS006)
bhepp 1:c070ca30da80 63 if (USE_NLOS_SETTINGS)
bhepp 1:c070ca30da80 64 {
bhepp 1:c070ca30da80 65 pc.printf("Setting NLOS configuration\r\n");
bhepp 1:c070ca30da80 66 DW1000Utils::setNLOSSettings(&dw, DATA_RATE_SETTING, PRF_SETTING, PREAMBLE_SETTING);
bhepp 1:c070ca30da80 67 }
bhepp 1:c070ca30da80 68
bhepp 1:c070ca30da80 69 pc.printf("Initializing slave with address %d\r\n", SLAVE_ADDRESS);
bhepp 1:c070ca30da80 70 UWBSlave slave(&dw, SLAVE_ADDRESS);
bhepp 1:c070ca30da80 71
bhepp 1:c070ca30da80 72 pc.printf("Entering main loop\r\n");
bhepp 1:c070ca30da80 73
bhepp 1:c070ca30da80 74 slave.startReceiving();
bhepp 1:c070ca30da80 75 while (true)
bhepp 1:c070ca30da80 76 {
bhepp 1:c070ca30da80 77 // slave.checkForFrame();
bhepp 1:c070ca30da80 78 pc.printf(".");
bhepp 1:c070ca30da80 79 wait_ms(500);
bhepp 1:c070ca30da80 80 }
bhepp 1:c070ca30da80 81
bhepp 1:c070ca30da80 82 //return 0;
bhepp 1:c070ca30da80 83 }
bhepp 1:c070ca30da80 84 #endif