mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
128 lines
2.7 KiB
Arduino
128 lines
2.7 KiB
Arduino
|
//
|
||
|
// FILE: ping2cm.ino
|
||
|
// AUTHOR: Rob Tillaart
|
||
|
// DATE: 2013-05-11
|
||
|
// PUPROSE: test fast routines for PING))) sensor
|
||
|
// URL: https://github.com/RobTillaart/fast_math
|
||
|
|
||
|
|
||
|
#include "Arduino.h"
|
||
|
#include "fast_math.h"
|
||
|
|
||
|
|
||
|
uint32_t start, stop;
|
||
|
volatile uint32_t q = 0;
|
||
|
|
||
|
|
||
|
void setup()
|
||
|
{
|
||
|
Serial.begin(115200);
|
||
|
Serial.println();
|
||
|
Serial.println(__FILE__);
|
||
|
Serial.print("FASTMATH_LIB_VERSION: ");
|
||
|
Serial.println(FASTMATH_LIB_VERSION);
|
||
|
Serial.println();
|
||
|
delay(10);
|
||
|
|
||
|
Serial.print("pingRef\t");
|
||
|
delay(10);
|
||
|
start = micros();
|
||
|
for (uint16_t i = 0; i < 10000; i++)
|
||
|
{
|
||
|
q = i / 29.41176;
|
||
|
}
|
||
|
stop = micros();
|
||
|
Serial.println((stop - start) / 10000.0, 4);
|
||
|
delay(10);
|
||
|
|
||
|
Serial.print("ping2cm\t");
|
||
|
delay(10);
|
||
|
start = micros();
|
||
|
for (uint16_t i = 0; i < 10000; i++)
|
||
|
{
|
||
|
q = ping2cm(i);
|
||
|
}
|
||
|
stop = micros();
|
||
|
Serial.println((stop - start) / 10000.0, 4);
|
||
|
delay(10);
|
||
|
|
||
|
Serial.print("ping2mm\t");
|
||
|
delay(10);
|
||
|
start = micros();
|
||
|
for (uint16_t i = 0; i < 10000; i++)
|
||
|
{
|
||
|
q = ping2mm(i);
|
||
|
}
|
||
|
stop = micros();
|
||
|
Serial.println((stop - start) / 10000.0, 4);
|
||
|
delay(100);
|
||
|
|
||
|
Serial.println("\nverify I");
|
||
|
for (uint16_t i = 0; i < 200; i += 10)
|
||
|
{
|
||
|
Serial.print(i);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(i * 0.034, 1);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(ping2cm(i));
|
||
|
Serial.print("\t");
|
||
|
Serial.print((1.0 * ping2cm(i)) / (i * 0.034) );
|
||
|
Serial.print("\t\t");
|
||
|
Serial.print(i * 0.34, 1);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(ping2mm(i));
|
||
|
Serial.print("\t");
|
||
|
Serial.print((1.0 * ping2mm(i)) / (i * 0.34) );
|
||
|
Serial.print("\t");
|
||
|
Serial.println();
|
||
|
}
|
||
|
|
||
|
Serial.println("\nverify II");
|
||
|
for (uint16_t i = 200; i < 1000; i += 50)
|
||
|
{
|
||
|
Serial.print(i);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(i * 0.034, 1);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(ping2cm(i));
|
||
|
Serial.print("\t");
|
||
|
Serial.print((1.0 * ping2cm(i)) / (i * 0.034) );
|
||
|
Serial.print("\t\t");
|
||
|
Serial.print(i * 0.34, 1);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(ping2mm(i));
|
||
|
Serial.print("\t");
|
||
|
Serial.print((1.0 * ping2mm(i)) / (i * 0.34) );
|
||
|
Serial.print("\t");
|
||
|
Serial.println();
|
||
|
}
|
||
|
|
||
|
Serial.println("\nverify III");
|
||
|
for (uint16_t i = 1000; i <= 10000; i += 500)
|
||
|
{
|
||
|
Serial.print(i);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(i * 0.034, 1);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(ping2cm(i));
|
||
|
Serial.print("\t");
|
||
|
Serial.print((1.0 * ping2cm(i)) / (i * 0.034) );
|
||
|
Serial.print("\t\t");
|
||
|
Serial.print(i * 0.34, 1);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(ping2mm(i));
|
||
|
Serial.print("\t");
|
||
|
Serial.print((1.0 * ping2mm(i)) / (i * 0.34) );
|
||
|
Serial.print("\t");
|
||
|
Serial.println();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
// -- END OF FILE --
|