aboutsummaryrefslogtreecommitdiff
path: root/src/modules/position_estimator_inav/inertial_filter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/position_estimator_inav/inertial_filter.c')
-rw-r--r--src/modules/position_estimator_inav/inertial_filter.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/modules/position_estimator_inav/inertial_filter.c b/src/modules/position_estimator_inav/inertial_filter.c
index 13328edb4..2f1b3c014 100644
--- a/src/modules/position_estimator_inav/inertial_filter.c
+++ b/src/modules/position_estimator_inav/inertial_filter.c
@@ -5,27 +5,30 @@
* Author: Anton Babushkin <rk3dov@gmail.com>
*/
+#include <math.h>
+
#include "inertial_filter.h"
void inertial_filter_predict(float dt, float x[3])
{
- x[0] += x[1] * dt + x[2] * dt * dt / 2.0f;
- x[1] += x[2] * dt;
+ if (isfinite(dt)) {
+ x[0] += x[1] * dt + x[2] * dt * dt / 2.0f;
+ x[1] += x[2] * dt;
+ }
}
void inertial_filter_correct(float e, float dt, float x[3], int i, float w)
{
- float ewdt = w * dt;
- if (ewdt > 1.0f)
- ewdt = 1.0f; // prevent over-correcting
- ewdt *= e;
- x[i] += ewdt;
+ if (isfinite(e) && isfinite(w) && isfinite(dt)) {
+ float ewdt = e * w * dt;
+ x[i] += ewdt;
- if (i == 0) {
- x[1] += w * ewdt;
- x[2] += w * w * ewdt / 3.0;
+ if (i == 0) {
+ x[1] += w * ewdt;
+ x[2] += w * w * ewdt / 3.0;
- } else if (i == 1) {
- x[2] += w * ewdt;
+ } else if (i == 1) {
+ x[2] += w * ewdt;
+ }
}
}