Benjamin Hepp / Mbed 2 deprecated AIT_UWB_Tracker

Dependencies:   DW1000 ait_link BufferedSerial mbed

Committer:
bhepp
Date:
Thu Mar 31 15:39:52 2016 +0000
Revision:
5:1928eb8c417a
Parent:
4:1a2c1e5e5516
Child:
10:6e95128c2efa
A lot of cleanup

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