mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 07:28:54 +08:00
AlphaFilter: allow setting dt in update call
This commit is contained in:
@@ -71,6 +71,8 @@ public:
|
||||
if (denominator > FLT_EPSILON) {
|
||||
setAlpha(sample_interval / denominator);
|
||||
}
|
||||
|
||||
_time_constant = time_constant;
|
||||
}
|
||||
|
||||
bool setCutoffFreq(float sample_freq, float cutoff_freq)
|
||||
@@ -82,8 +84,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
setParameters(1.f / sample_freq, 1.f / (2.f * M_PI_F * cutoff_freq));
|
||||
_cutoff_freq = cutoff_freq;
|
||||
setParameters(1.f / sample_freq, 1.f / (M_TWOPI_F * cutoff_freq));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -112,14 +113,19 @@ public:
|
||||
return _filter_state;
|
||||
}
|
||||
|
||||
const T update(const T &sample, float dt)
|
||||
{
|
||||
setParameters(dt, _time_constant);
|
||||
return update(sample);
|
||||
}
|
||||
|
||||
const T &getState() const { return _filter_state; }
|
||||
float getCutoffFreq() const { return _cutoff_freq; }
|
||||
float getCutoffFreq() const { return 1.f / (M_TWOPI_F * _time_constant); }
|
||||
|
||||
protected:
|
||||
T updateCalculation(const T &sample);
|
||||
|
||||
|
||||
float _cutoff_freq{0.f};
|
||||
float _time_constant{0.f};
|
||||
float _alpha{0.f};
|
||||
T _filter_state{};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user