GY-63_MS5611/libraries/AverageAngle/examples/AverageAngle2/AverageAngle2.ino

299 lines
5.4 KiB
Arduino
Raw Normal View History

2020-11-27 05:10:47 -05:00
//
// FILE: averageAngle.ino
// AUTHOR: Rob Tillaart
2021-10-18 15:44:20 -04:00
// VERSION: 0.1.0
// DATE: 2017-11-21
// PURPOSE: demonstrates the usage of the AverageAngle Class
2020-11-27 05:10:47 -05:00
//
#include "AverageAngle.h"
2021-10-18 15:44:20 -04:00
2020-11-27 05:10:47 -05:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
test0();
test1();
test2(1000);
test3(1000);
test4();
test5();
test6();
test7();
test8();
test9();
test10(1000);
}
void loop()
{
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test0()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
AA.add(10, 10);
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t10, 10");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test1()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
for (int i = 0; i < 10; i++)
{
AA.add(i, i);
}
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t6.33, 4.5");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test2(int count)
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
for (int i = 0; i < count; i++)
{
AA.add(random(180), random(10));
}
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t~90, 2.85");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test3(int count)
{
AverageAngle AA(AverageAngle::RADIANS);
AA.reset();
for (int i = 0; i < count; i++)
{
AA.add( PI / 180 * random(180), random(10));
}
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t~PI/2, 2.93");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test4()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
AA.add(358, 1);
AA.add(359, 2);
AA.add(0, 3);
AA.add(1, 2);
AA.add(2, 1);
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t~0, 1.8");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test5()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
AA.add(357, 3);
AA.add(358, 1);
AA.add(359, 5);
AA.add(360, 1);
AA.add(1, 3);
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t~359, 2.6");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test6()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
AA.add(359, 5);
AA.add(360, 3);
AA.add(361, 2);
AA.add(362, 3);
AA.add(363, 5);
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t~1, 3.6");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test7()
{
AverageAngle AA(AverageAngle::DEGREES);
AverageAngle BB(AverageAngle::RADIANS);
Serial.println(__FUNCTION__);
Serial.print("AA:\t");
Serial.println(AA.type());
Serial.print("BB:\t");
Serial.println(BB.type());
Serial.println("EXPECT:\tAA=0 BB=1");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test8()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("LEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t0, 0");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test9()
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
AA.add(0);
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getAverageLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("AVGLEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t0, 1");
Serial.println();
}
2021-12-13 14:51:57 -05:00
2020-11-27 05:10:47 -05:00
void test10(int count)
{
AverageAngle AA(AverageAngle::DEGREES);
AA.reset();
for (int i = 0; i < count; i++)
{
AA.add(random(180), random(10));
}
int cnt = AA.count();
float avg = AA.getAverage();
float len = AA.getTotalLength();
Serial.println(__FUNCTION__);
Serial.print("COUNT:\t");
Serial.println(cnt);
Serial.print("AVG:\t");
Serial.println(avg, 6);
Serial.print("TOTLEN:\t");
Serial.println(len, 6);
Serial.println("EXPECT:\t90, ~2500-3000");
Serial.println();
}
2021-12-13 14:51:57 -05:00
// -- END OF FILE --