25#ifndef SMART_AVERAGER_H_
26#define SMART_AVERAGER_H_
29#define SQR(x) ((x)*(x))
33#define ONE_DIV_2PI 0.159155f
34#define PI_TIMES_2 6.2832f
37template<
class value_t,
bool CLAMP_OUTPUT_FIRST_CIRCLE = false,
bool SOFT_TAKEOFF = true>
47 for (
unsigned index = 0; index < N_SECTORS; ++index)
49 sector_averages[index] = {0};
50 sector_sample_count[index] = 0;
56 return present_output;
75 fill_recordings_with_value (averager.
get_output());
80 present_output = get_boxcar_average();
91 reset( get_boxcar_average());
99 present_output = get_boxcar_average();
102 present_output = get_boxcar_average();
114 unsigned index = find_sector_index(
heading);
116 if( old_sector != index)
119 if( sector_sample_count[index] > 1)
122 sector_sample_count[index] = 0;
123 sector_averages[index] = {0};
128 ++ sector_sample_count[index];
134 for (
unsigned i = 0;
i < N_SECTORS; ++
i)
136 sector_averages[
i] = {0};
137 sector_sample_count[
i] = 0;
139 present_output = value;
144 for (
unsigned index = 0; index < N_SECTORS; ++index)
145 if( sector_sample_count[index] == 0)
157 value_t get_boxcar_average(
void)
162 for (
unsigned index = 0; index < N_SECTORS; ++index)
163 if( sector_sample_count[index] > 0)
165 average =
average + sector_averages[index] * (
ONE / sector_sample_count[index]);
174 unsigned find_sector_index(
float heading)
177 if(
retv >= N_SECTORS)
182 void fill_recordings_with_value (
value_t value)
184 for (
unsigned i = 0;
i < N_SECTORS; ++
i)
186 sector_averages[
i] = value;
187 sector_sample_count[
i] = 1;
191 enum { N_SECTORS = 16};
196 value_t sector_averages[N_SECTORS];
197 unsigned sector_sample_count[N_SECTORS];
attitude and heading reference system (interface)
void settle(const datatype &present_input)
datatype get_output(void) const
datatype respond(const datatype &input)
template for an average filter for circling and straight flight
soaring_flight_averager(float normalized_stop_frequency)
void record_input(value_t current_value, volatile float heading)
bool circle_completed(void) const
void update(const value_t ¤t_value, float heading, circle_state_t new_state)
const value_t & get_output(void) const
void reset(value_t value)
mathematical vector of arbitrary type and size
defines platform-dependent algorithms and constants
tunable second order IIR lowpass filter (butterworth)