Benjamin Hepp / Mbed 2 deprecated AIT_UWB_Tracker

Dependencies:   DW1000 ait_link BufferedSerial mbed

Committer:
bhepp
Date:
Wed Apr 06 08:23:26 2016 +0000
Revision:
10:6e95128c2efa
Parent:
5:1928eb8c417a
Removed mavlink

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