mirror of https://github.com/ArduPilot/ardupilot
Filter - removed shadowing of variables in constructors for Filter, ModeFilter and SumFilter (sorry tridge!)
increased maximum sample buffer size from 6 to 10
This commit is contained in:
parent
4501c488b4
commit
b345529241
|
@ -17,13 +17,13 @@
|
|||
#include <inttypes.h>
|
||||
#include <AP_Common.h>
|
||||
|
||||
#define FILTER_MAX_SAMPLES 6 // max number of samples that can be added to the filter
|
||||
#define FILTER_MAX_SAMPLES 10 // maximum size of the sample buffer (normally older values will be overwritten as new appear)
|
||||
|
||||
template <class T>
|
||||
class Filter
|
||||
{
|
||||
public:
|
||||
Filter(uint8_t filter_size);
|
||||
Filter(uint8_t requested_size);
|
||||
~Filter();
|
||||
|
||||
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||
|
@ -44,8 +44,8 @@ typedef Filter<int16_t> FilterInt16;
|
|||
|
||||
// Constructor
|
||||
template <class T>
|
||||
Filter<T>::Filter(uint8_t filter_size) :
|
||||
filter_size(filter_size), sample_index(0)
|
||||
Filter<T>::Filter(uint8_t requested_size) :
|
||||
filter_size(requested_size), sample_index(0)
|
||||
{
|
||||
// check filter size
|
||||
if( Filter<T>::filter_size > FILTER_MAX_SAMPLES )
|
||||
|
@ -58,7 +58,7 @@ Filter<T>::Filter(uint8_t filter_size) :
|
|||
reset();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
// Destructor - THIS SHOULD NEVER BE CALLED OR IT COULD LEAD TO MEMORY FRAGMENTATION
|
||||
template <class T>
|
||||
Filter<T>::~Filter()
|
||||
{
|
||||
|
|
|
@ -22,7 +22,7 @@ template <class T>
|
|||
class ModeFilter : public Filter<T>
|
||||
{
|
||||
public:
|
||||
ModeFilter(uint8_t filter_size, uint8_t return_element);
|
||||
ModeFilter(uint8_t requested_size, uint8_t return_element);
|
||||
|
||||
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||
virtual T apply(T sample);
|
||||
|
@ -40,14 +40,14 @@ typedef ModeFilter<int16_t> ModeFilterInt16;
|
|||
// Constructor //////////////////////////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
ModeFilter<T>::ModeFilter(uint8_t filter_size, uint8_t return_element) :
|
||||
Filter<T>(filter_size),
|
||||
ModeFilter<T>::ModeFilter(uint8_t requested_size, uint8_t return_element) :
|
||||
Filter<T>(requested_size),
|
||||
_return_element(return_element),
|
||||
drop_high_sample(true)
|
||||
{
|
||||
// ensure we have a valid return_nth_element value. if not, revert to median
|
||||
if( _return_element >= filter_size )
|
||||
_return_element = filter_size / 2;
|
||||
if( _return_element >= Filter<T>::filter_size )
|
||||
_return_element = Filter<T>::filter_size / 2;
|
||||
};
|
||||
|
||||
// Public Methods //////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -21,7 +21,7 @@ template <class T>
|
|||
class SumFilter : public Filter<T>
|
||||
{
|
||||
public:
|
||||
SumFilter(uint8_t filter_size) : Filter<T>(filter_size) {};
|
||||
SumFilter(uint8_t requested_size) : Filter<T>(requested_size) {};
|
||||
|
||||
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||
virtual T apply(T sample);
|
||||
|
|
Loading…
Reference in New Issue