mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-11 18:38:28 -04:00
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 <inttypes.h>
|
||||||
#include <AP_Common.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>
|
template <class T>
|
||||||
class Filter
|
class Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Filter(uint8_t filter_size);
|
Filter(uint8_t requested_size);
|
||||||
~Filter();
|
~Filter();
|
||||||
|
|
||||||
// apply - Add a new raw value to the filter, retrieve the filtered result
|
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||||
@ -44,8 +44,8 @@ typedef Filter<int16_t> FilterInt16;
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
template <class T>
|
template <class T>
|
||||||
Filter<T>::Filter(uint8_t filter_size) :
|
Filter<T>::Filter(uint8_t requested_size) :
|
||||||
filter_size(filter_size), sample_index(0)
|
filter_size(requested_size), sample_index(0)
|
||||||
{
|
{
|
||||||
// check filter size
|
// check filter size
|
||||||
if( Filter<T>::filter_size > FILTER_MAX_SAMPLES )
|
if( Filter<T>::filter_size > FILTER_MAX_SAMPLES )
|
||||||
@ -58,7 +58,7 @@ Filter<T>::Filter(uint8_t filter_size) :
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor - THIS SHOULD NEVER BE CALLED OR IT COULD LEAD TO MEMORY FRAGMENTATION
|
||||||
template <class T>
|
template <class T>
|
||||||
Filter<T>::~Filter()
|
Filter<T>::~Filter()
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ template <class T>
|
|||||||
class ModeFilter : public Filter<T>
|
class ModeFilter : public Filter<T>
|
||||||
{
|
{
|
||||||
public:
|
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
|
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||||
virtual T apply(T sample);
|
virtual T apply(T sample);
|
||||||
@ -40,14 +40,14 @@ typedef ModeFilter<int16_t> ModeFilterInt16;
|
|||||||
// Constructor //////////////////////////////////////////////////////////////
|
// Constructor //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
ModeFilter<T>::ModeFilter(uint8_t filter_size, uint8_t return_element) :
|
ModeFilter<T>::ModeFilter(uint8_t requested_size, uint8_t return_element) :
|
||||||
Filter<T>(filter_size),
|
Filter<T>(requested_size),
|
||||||
_return_element(return_element),
|
_return_element(return_element),
|
||||||
drop_high_sample(true)
|
drop_high_sample(true)
|
||||||
{
|
{
|
||||||
// ensure we have a valid return_nth_element value. if not, revert to median
|
// ensure we have a valid return_nth_element value. if not, revert to median
|
||||||
if( _return_element >= filter_size )
|
if( _return_element >= Filter<T>::filter_size )
|
||||||
_return_element = filter_size / 2;
|
_return_element = Filter<T>::filter_size / 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
@ -21,7 +21,7 @@ template <class T>
|
|||||||
class SumFilter : public Filter<T>
|
class SumFilter : public Filter<T>
|
||||||
{
|
{
|
||||||
public:
|
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
|
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||||
virtual T apply(T sample);
|
virtual T apply(T sample);
|
||||||
|
Loading…
Reference in New Issue
Block a user