Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Toggle main menu visibility
Loading...
Searching...
No Matches
src
filters
RollingAvgFilter.h
1
#pragma once
2
3
#include <
iterator
>
4
#include <
list
>
5
#include <
numeric
>
6
7
namespace
filters {
8
15
template
<
typename
T>
class
RollingAvgFilter
{
16
public
:
22
explicit
RollingAvgFilter
(
size_t
numPoints)
23
: numPoints(numPoints), data() {}
24
34
T
get
()
const
{
35
return
std::reduce(std::next(data.begin()), data.end(), data.front()) / data.size();
36
}
37
44
T
get
(
const
T& val) {
45
data.push_back(val);
46
if
(data.size() > numPoints) {
47
data.pop_front();
48
}
49
50
return
get
();
51
}
52
56
void
reset
() {
57
data.clear();
58
}
59
65
int
getSize
()
const
{
66
return
data.size();
67
}
68
74
int
getBufferSize
()
const
{
75
return
numPoints;
76
}
77
83
std::list<T>
getData
()
const
{
84
return
data;
85
}
86
87
private
:
88
size_t
numPoints;
89
std::list<T>
data;
90
};
91
92
}
// namespace filters
iterator
list
numeric
std::list
filters::RollingAvgFilter::getBufferSize
int getBufferSize() const
Get the maximum number of points that can be stored in the buffer.
Definition
RollingAvgFilter.h:74
filters::RollingAvgFilter::RollingAvgFilter
RollingAvgFilter(size_t numPoints)
Construct a new rolling average filter.
Definition
RollingAvgFilter.h:22
filters::RollingAvgFilter::get
T get(const T &val)
Adds data to the filter and gets the new output.
Definition
RollingAvgFilter.h:44
filters::RollingAvgFilter::reset
void reset()
Clears all data in the buffer.
Definition
RollingAvgFilter.h:56
filters::RollingAvgFilter::get
T get() const
Get the output of the filter.
Definition
RollingAvgFilter.h:34
filters::RollingAvgFilter::getSize
int getSize() const
Returns the number of points stored in the buffer.
Definition
RollingAvgFilter.h:65
filters::RollingAvgFilter::getData
std::list< T > getData() const
Get the underlying buffer of the filter.
Definition
RollingAvgFilter.h:83
Generated by
1.17.0