Browse Source

AlphaFilter: replace isfinite with positive denominator check

master
Matthias Grob 5 years ago committed by Daniel Agar
parent
commit
daec5ae608
  1. 14
      EKF/AlphaFilter.hpp

14
EKF/AlphaFilter.hpp

@ -42,8 +42,6 @@
#pragma once #pragma once
#include "../ecl.h"
template <typename T> template <typename T>
class AlphaFilter { class AlphaFilter {
public: public:
@ -59,7 +57,11 @@ public:
* @param time_constant filter time constant determining convergence * @param time_constant filter time constant determining convergence
*/ */
void setParameters(float sample_interval, float time_constant) { void setParameters(float sample_interval, float time_constant) {
setAlpha(sample_interval / (time_constant + sample_interval)); const float denominator = time_constant + sample_interval;
if (denominator > FLT_EPSILON) {
setAlpha(sample_interval / denominator);
}
} }
/** /**
@ -67,11 +69,7 @@ public:
* *
* @param alpha [0,1] filter weight for the previous state. High value - long time constant. * @param alpha [0,1] filter weight for the previous state. High value - long time constant.
*/ */
void setAlpha(float alpha) { void setAlpha(float alpha) { _alpha = alpha; }
if (ISFINITE(alpha)) {
_alpha = alpha;
}
}
/** /**
* Set filter state to an initial value * Set filter state to an initial value

Loading…
Cancel
Save