18 #ifndef _GAZEBO_MOVING_WINDOW_FILTER_HH_
19 #define _GAZEBO_MOVING_WINDOW_FILTER_HH_
25 #include <boost/function.hpp>
26 #include <boost/bind.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/thread/mutex.hpp>
30 #include <gazebo/gazebo_config.h>
58 public:
typename std::vector<T>::iterator
valIter;
72 this->valWindowSize = 4;
73 this->valHistory.resize(this->valWindowSize);
74 this->valIter = this->valHistory.begin();
92 public:
void Update(T _val);
129 this->dataPtr->valHistory.clear();
130 delete this->dataPtr;
131 this->dataPtr =
NULL;
141 this->dataPtr->sum += _val;
144 ++this->dataPtr->valIter;
145 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
148 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
152 ++this->dataPtr->samples;
154 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
157 this->dataPtr->sum -= (*this->dataPtr->valIter);
159 (*this->dataPtr->valIter) = _val;
161 --this->dataPtr->samples;
166 (*this->dataPtr->valIter) = _val;
174 this->dataPtr->valWindowSize = _n;
175 this->dataPtr->valHistory.clear();
176 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
177 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
178 this->dataPtr->sum = T();
179 this->dataPtr->samples = 0;
186 return this->dataPtr->valWindowSize;
193 return this->dataPtr->samples == this->dataPtr->valWindowSize;
200 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
MovingWindowFilterPrivate< T > * dataPtr
Data pointer.
Definition: MovingWindowFilter.hh:115
T Get()
Get filtered result.
Definition: MovingWindowFilter.hh:198
unsigned int GetWindowSize() const
Get the window size.
Definition: MovingWindowFilter.hh:184
bool GetWindowFilled() const
Get whether the window has been filled.
Definition: MovingWindowFilter.hh:191
std::vector< T >::iterator valIter
iterator pointing to current value in buffer
Definition: MovingWindowFilter.hh:58
unsigned int valWindowSize
For moving window smoothed value.
Definition: MovingWindowFilter.hh:52
std::vector< T > valHistory
buffer history of raw values
Definition: MovingWindowFilter.hh:55
T sum
keep track of running sum
Definition: MovingWindowFilter.hh:61
void SetWindowSize(unsigned int _n)
Set window size.
Definition: MovingWindowFilter.hh:172
Definition: MovingWindowFilter.hh:46
MovingWindowFilterPrivate()
Definition: MovingWindowFilter.hh:69
Base class for MovingWindowFilter.
Definition: MovingWindowFilter.hh:82
void Update(T _val)
Update value of filter.
Definition: MovingWindowFilter.hh:136
#define NULL
Definition: CommonTypes.hh:31
unsigned int samples
keep track of number of elements
Definition: MovingWindowFilter.hh:64
virtual ~MovingWindowFilter()
Destructor.
Definition: MovingWindowFilter.hh:127
MovingWindowFilter()
Constructor.
Definition: MovingWindowFilter.hh:120