mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.7 AverageAngle
This commit is contained in:
parent
8d8d01eeee
commit
45c50e1f54
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: AverageAngle.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.6
|
||||
// VERSION: 0.1.7
|
||||
// PURPOSE: class for averaging angles
|
||||
// URL: https://github.com/RobTillaart/AverageAngle
|
||||
//
|
||||
@ -11,8 +11,10 @@
|
||||
// 0.1.2 2018-03-30 added getAverageLength, getTotalLength + zero-test
|
||||
// 0.1.3 2020-03-26 #pragma once; removed pre 1.00 support; readme.md
|
||||
// 0.1.4 2020-05-27 update library.json
|
||||
// 0.1.5 2020-12-12 added arduino-CI, unit tests, minor refactor.
|
||||
// 0.1.5 2020-12-12 added Arduino-CI, unit tests, minor refactor.
|
||||
// 0.1.6 2021-10-18 update Arduino-CI, add GRADIANS
|
||||
// 0.1.7 2021-12-13 update library.json, fix badges, license, readme
|
||||
|
||||
|
||||
|
||||
#include "AverageAngle.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: AverageAngle.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.6
|
||||
// VERSION: 0.1.7
|
||||
// PURPOSE: class for averaging angles.
|
||||
// HISTORY: See AverageAngle.cpp
|
||||
//
|
||||
@ -11,7 +11,7 @@
|
||||
#include "math.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#define AVERAGE_ANGLE_LIB_VERSION (F("0.1.6"))
|
||||
#define AVERAGE_ANGLE_LIB_VERSION (F("0.1.7"))
|
||||
|
||||
#define GRAD_TO_RAD (PI / 200.0)
|
||||
#define RAD_TO_GRAD (200.0 / PI)
|
||||
@ -43,4 +43,6 @@ private:
|
||||
uint32_t _count;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2021 Rob Tillaart
|
||||
Copyright (c) 2017-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,11 +1,14 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/AverageAngle/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/AverageAngle/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AverageAngle/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/AverageAngle/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AverageAngle/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AverageAngle/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AverageAngle.svg?maxAge=3600)](https://github.com/RobTillaart/AverageAngle/releases)
|
||||
|
||||
|
||||
# AverageAngle
|
||||
|
||||
Arduino library to calculate correctly the average of multiple angles
|
||||
Arduino library to calculate correctly the average of multiple angles.
|
||||
|
||||
|
||||
## Description
|
||||
@ -16,20 +19,20 @@ This is especially useful when angles are around 0 degrees,
|
||||
e.g. from a compass sensor or the resultant of a track.
|
||||
Example, the average angle of 359 and 1 is 0, not 179 (most of the time)
|
||||
|
||||
Furthermore the AverageAngle can also include the **length (weight)** of the angle
|
||||
as if it is a vector. Default this length is set to 1 so all angles are by default of
|
||||
equal weight.
|
||||
Furthermore the AverageAngle can also include the **length (weight)** of the angle as if it is a vector.
|
||||
Default this length is set to 1 so all angles are by default of equal weight.
|
||||
|
||||
Example: The average angle of 359 (length = 2) and 1 (length = 1) is 359.something not zero.
|
||||
|
||||
**See also runningAngle class**.
|
||||
See also **runningAngle** class.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
- **enum AngleType { DEGREES, RADIANS, GRADIANS } ** idem. 100 GRADIANS == 90 DEGREES.
|
||||
- **AverageAngle(AngleType type = DEGREES)** constructor defaults to degrees.
|
||||
- **uint32_t add(float alpha, float length = 1.0)** add a new angle, optional with length. **add()** returns the number of elements (count).
|
||||
- **uint32_t add(float alpha, float length = 1.0)** add a new angle, optional with length.
|
||||
**add()** returns the number of elements (count).
|
||||
- **void reset()** clears internal buffers.
|
||||
- **uint32_t count()** the amount of angles added.
|
||||
- **float getAverage() ** returns the average.
|
||||
@ -41,7 +44,8 @@ Example: The average angle of 359 (length = 2) and 1(length = 1) is 359.somethin
|
||||
|
||||
## Gradians
|
||||
|
||||
Gradians a.k.a. gon, is a less often used unit for angles. There are 100 gradians in a right angle. A full circle = 400 gradians.
|
||||
Gradians a.k.a. gon, is a less often used unit for angles.
|
||||
There are 100 gradians in a right angle. A full circle = 400 gradians.
|
||||
|
||||
https://en.wikipedia.org/wiki/Gradian
|
||||
|
||||
@ -50,7 +54,7 @@ https://en.wikipedia.org/wiki/Gradian
|
||||
|
||||
If you want to average 5 compass readings you can just add the angles and
|
||||
do not use the length parameter.
|
||||
```
|
||||
```cpp
|
||||
AA.reset();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
@ -63,7 +67,7 @@ do not use the length parameter.
|
||||
|
||||
If you want to average a track, e.g. 5 steps North, 3 steps west etc,
|
||||
you need to include the length of each step.
|
||||
```
|
||||
```cpp
|
||||
AA.reset();
|
||||
AA.add(90, 5); // 5 steps north
|
||||
AA.add(180, 3); // 3 steps west
|
||||
@ -74,9 +78,7 @@ you need to include the length of each step.
|
||||
|
||||
## Future
|
||||
|
||||
- Improve documentation.
|
||||
- check if other units exist to support.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -31,6 +31,7 @@ void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void test0()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -52,6 +53,7 @@ void test0()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test1()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -76,6 +78,7 @@ void test1()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test2(int count)
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -100,6 +103,7 @@ void test2(int count)
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test3(int count)
|
||||
{
|
||||
AverageAngle AA(AverageAngle::RADIANS);
|
||||
@ -124,6 +128,7 @@ void test3(int count)
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test4()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -151,6 +156,7 @@ void test4()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test5()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -178,6 +184,7 @@ void test5()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test6()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -205,6 +212,7 @@ void test6()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test7()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -218,6 +226,7 @@ void test7()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test8()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -238,6 +247,7 @@ void test8()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test9()
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -259,6 +269,7 @@ void test9()
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test10(int count)
|
||||
{
|
||||
AverageAngle AA(AverageAngle::DEGREES);
|
||||
@ -283,4 +294,6 @@ void test10(int count)
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AverageAngle.git"
|
||||
},
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "AverageAngle.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AverageAngle
|
||||
version=0.1.6
|
||||
version=0.1.7
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to average angles correctly around 0.
|
||||
|
@ -34,6 +34,15 @@ unittest_teardown()
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
assertEqualFloat(PI / 180.0, DEG_TO_RAD, 0.00001);
|
||||
assertEqualFloat(180.0 / PI, RAD_TO_DEG, 0.00001);
|
||||
assertEqualFloat(PI / 200.0, GRAD_TO_RAD, 0.00001);
|
||||
assertEqualFloat(200.0 / PI, RAD_TO_GRAD, 0.00001);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "AVERAGE_ANGLE_LIB_VERSION: %s\n", (char*) AVERAGE_ANGLE_LIB_VERSION);
|
||||
@ -45,11 +54,6 @@ unittest(test_constructor)
|
||||
assertEqual(AverageAngle::DEGREES, dd.type());
|
||||
assertEqual(AverageAngle::RADIANS, rr.type());
|
||||
assertEqual(AverageAngle::GRADIANS, gg.type());
|
||||
|
||||
assertEqualFloat(PI / 180.0, DEG_TO_RAD, 0.00001);
|
||||
assertEqualFloat(180.0 / PI, RAD_TO_DEG, 0.00001);
|
||||
assertEqualFloat(PI / 200.0, GRAD_TO_RAD, 0.00001);
|
||||
assertEqualFloat(200.0 / PI, RAD_TO_GRAD, 0.00001);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user