mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-09-11 19:55:14 +02:00
Add a class to movingAvg class for calculation of averages for angle data
This commit is contained in:
@@ -22,6 +22,7 @@ class movingAvg
|
||||
int getCount() { return m_nbrReadings; }
|
||||
void reset();
|
||||
T* getReadings() { return m_readings; }
|
||||
T to2PI(T a);
|
||||
|
||||
private:
|
||||
int m_interval; // number of data points for the moving average
|
||||
@@ -33,6 +34,32 @@ class movingAvg
|
||||
T* m_readings; // pointer to the dynamically allocated interval array
|
||||
};
|
||||
|
||||
// moving average for angle type of data (wind, course, rotation)
|
||||
// makes sense for data types double and float; angle in radians [0..2pi]
|
||||
template <typename T>
|
||||
class movingAvgAngle
|
||||
{
|
||||
public:
|
||||
movingAvgAngle(int interval)
|
||||
: m_interval{interval}, m_nbrReadings{0}, m_sumSin{0}, m_sumCos{0}, m_next{0}, m_buffer{nullptr} {}
|
||||
~movingAvgAngle() { delete[] m_buffer; }
|
||||
void begin();
|
||||
T reading(T newReading);
|
||||
T getAvg();
|
||||
T getAvg(int nPoints);
|
||||
int getCount() { return m_nbrReadings; }
|
||||
void reset();
|
||||
T* getReadings() { return m_buffer; }
|
||||
T to2PI(T a);
|
||||
|
||||
private:
|
||||
int m_interval; // number of data points for the moving average
|
||||
int m_nbrReadings; // number of readings
|
||||
double m_sumSin, m_sumCos; // sum for angle values should always be double for precision reasons, regardless of class type
|
||||
int m_next; // index to the next reading
|
||||
T* m_buffer; // pointer to the dynamically allocated interval array
|
||||
};
|
||||
|
||||
// Include the implementation to satisfy template instantiation requirements
|
||||
#include "movingAvg.tpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user