48 lines
1.1 KiB
C
Raw Normal View History

2021-01-29 12:31:58 +01:00
#pragma once
//
// FILE: runningAngle.h
// AUTHOR: Rob Tillaart
2022-11-23 17:07:12 +01:00
// VERSION: 0.1.5
2021-01-29 12:31:58 +01:00
// PURPOSE: Library to average angles by means of low pass filtering with wrapping.
2022-05-29 11:19:11 +02:00
// URL: https://github.com/RobTillaart/runningAngle
// RELATED: https://github.com/RobTillaart/AverageAngle
2021-01-29 12:31:58 +01:00
#include "Arduino.h"
#include "math.h"
2022-11-23 17:07:12 +01:00
#define RUNNING_ANGLE_LIB_VERSION (F("0.1.5"))
2021-01-29 12:31:58 +01:00
class runningAngle
{
public:
2022-05-29 11:19:11 +02:00
enum AngleType { DEGREES = 0, RADIANS = 1, GRADIANS = 2 };
2021-01-29 12:31:58 +01:00
runningAngle(const enum AngleType type = DEGREES);
2022-11-23 17:07:12 +01:00
// first value added will not use the weight to set the initial value.
float add(float angle); // returns new average
2021-01-29 12:31:58 +01:00
void reset();
float getAverage() { return _average; };
void setWeight(float w) { _weight = constrain(w, 0.001, 1); };
float getWeight() { return _weight; };
enum AngleType type() { return _type; };
2022-11-23 17:07:12 +01:00
// reformat angle to -180..+180 (degrees) or -PI..PI (radians)
2021-01-29 12:31:58 +01:00
float wrap(float angle);
private:
enum AngleType _type;
float _average = 0;
float _weight;
bool _reset;
};
2021-05-28 13:43:31 +02:00
2022-11-23 17:07:12 +01:00
// -- END OF FILE --
2021-12-28 09:50:06 +01:00