Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: main.cpp
- Revision:
- 43:d89fe237a684
- Parent:
- 42:83931678c4de
- Child:
- 44:2e0045042a59
diff -r 83931678c4de -r d89fe237a684 main.cpp --- a/main.cpp Mon Mar 02 09:33:03 2015 +0000 +++ b/main.cpp Thu Mar 05 10:26:51 2015 +0000 @@ -8,8 +8,7 @@ DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ) MMRanging r(dw); // Ranging class for getting distances and later positions -float rangings[1000]; -int index = 0; +int average_index = 0; int main() { pc.printf("\r\nDecaWave 1.0 up and running!\r\n"); @@ -33,7 +32,7 @@ while(1) { if (!r.receiver) { - #if 1 // normal operation + #if 0 // normal operation r.requestRangingAll(); for (int i = 1; i <= 4; i++) { // Request ranging to all anchors pc.printf("%f, ", r.distances[i]); @@ -42,6 +41,9 @@ pc.printf("\r\n"); #endif #if 0 // calibration of antennadelay + float rangings[1000]; + int index = 0; + r.requestRanging(1); if (r.distances[1] < 100) { rangings[index] = r.distances[1]; @@ -71,25 +73,26 @@ //pc.printf("%lld\r\n", r.timeDifference40Bit(r.rangingtimingsReceiver[0][0], r.rangingtimingsReceiver[0][1])); // debuging output to find 40Bit overflows on receiver side } - #if 0 // averaging the distance with a ringbuffer - int average[50]; - int average_index = 0; - float averaged; - - pc.printf("Distance: %f\r\n", (r.tofs[2]*300/MMRANGING_TIMEUNIT_US / 2) - 0.5); - average[average_index] = r.tofs[2]; + #if 1 // averaging the distance with a ringbuffer + float averaged = 0; + float average[1000]; + + int i = 1; + r.requestRanging(i); + average[average_index] = r.distances[i]; average_index++; - if(average_index == 50) + if(average_index == 1000) { average_index = 0; - for(int i = 0; i < 50; i++) - averaged += average[i]; - averaged /= 50; - pc.printf("Distance: %f\r\n", (averaged*300/MMRANGING_TIMEUNIT_US / 2) - 0.5); + for(int j = 0; j < 1000; j++) + averaged += average[j]; + averaged /= 1000; + pc.printf("Distance: %f\r\n", averaged); + pc.printf("Calibrated: %f\r\n", -0.123 *averaged*averaged + 2.564 * averaged - 5.332 ); + } #endif #if 0 // Output bars on console for(int i = 1; i < 3; i++) { - //pc.printf("%f ", r.tofs[j]*MMRANGING_TIMEUNIT_NS); pc.printf("%lld [", r.tofs[i]); int dots = r.tofs[i]*70/1400; if (abs(dots) < 10000)