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
- Committer:
- manumaet
- Date:
- 2015-03-08
- Revision:
- 45:01a33363bc21
- Parent:
- 44:2e0045042a59
- Child:
- 46:6398237672a0
File content as of revision 45:01a33363bc21:
// by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
#include "mbed.h"
#include "PC.h" // Serial Port via USB for debugging with Terminal
#include "DW1000.h" // our DW1000 device driver
#include "MM2WayRanging.h" // our self developed ranging application
#define myprintf pc.printf // to make the code adaptable to other outputs that support printf
PC pc(USBTX, USBRX, 921600); // USB UART Terminal
DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ)
MM2WayRanging node(dw); // Instance of the two way ranging algorithm
void rangeAndDisplayAll(){
node.requestRangingAll(); // Request ranging to all anchors
for (int i = 1; i <= 5; i++) { // Output Results
myprintf("%f, ", node.distances[i]);
//myprintf("T:%f", node.roundtriptimes[i]);
//myprintf("\r\n");
}
myprintf("\r\n");
}
void calibrationRanging(int destination){
const int numberOfRangings = 100;
float rangings[numberOfRangings];
int index = 0;
float mean = 0;
float start, stop;
Timer localTimer;
localTimer.start();
start = localTimer.read();
while (1) {
node.requestRanging(destination);
if(node.overflow){
myprintf("Overflow! Measured: %f\r\n", node.distances[destination]);
}
if (node.distances[destination] == -1) {
myprintf("Measurement timed out\r\n");
wait(0.001);
continue;
}
if (node.distances[destination] < 100) {
rangings[index] = node.distances[destination];
//myprintf("%f\r\n", node.distances[destination]);
index++;
if (index == numberOfRangings) {
stop = localTimer.read();
for (int i = 0; i < numberOfRangings - 1; i++)
rangings[numberOfRangings - 1] += rangings[i];
mean = rangings[numberOfRangings - 1] / numberOfRangings;
myprintf("\r\n\r\nMean %i: %f\r\n", destination, mean);
myprintf("Elapsed Time for %i: %f\r\n", numberOfRangings, stop - start);
mean = 0;
index = 0;
//wait(2);
start = localTimer.read();
}
}
else myprintf("%f\r\n", node.distances[destination]);
}
}
// -----------------------------------------------------------------------------------------------
int main() {
pc.printf("\r\nDecaWave 1.0 up and running!\r\n"); // Splashscreen
dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID());
pc.printf("EUI register: %016llX\r\n", dw.getEUI());
pc.printf("Voltage: %fV\r\n", dw.getVoltage());
node.isAnchor = false;
// declare as anchor or beacon
if (node.isAnchor) {
node.address = 1;
myprintf("This node is Anchor node %d \r\n", node.address);
} else {
node.address = 0;
myprintf("This node is a Beacon. ");
}
while(1) {
if (!node.isAnchor){
rangeAndDisplayAll();
//calibrationRanging(4);
}else
myprintf(".\r");
wait(0.3);
}
}
