From 83b81fbbef9b6ec84c08d4dfb19b84f9e78b2e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 16 Oct 2020 15:09:41 +0200 Subject: [PATCH] battery: fix isFloatEqual(), use matrix::isEqualF Fixes param migration, e.g. if BAT_N_CELLS is set, migrates to BAT1_N_CELLS. --- src/lib/battery/battery.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/battery/battery.h b/src/lib/battery/battery.h index dc589d6118..bed43eaf4f 100644 --- a/src/lib/battery/battery.h +++ b/src/lib/battery/battery.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -179,22 +180,20 @@ protected: param_get(new_param, new_val); // Check if the parameter values are different - if (!isFloatEqual(*old_val, *new_val)) { + if (!matrix::isEqualF((float)*old_val, (float)*new_val)) { // If so, copy the new value over to the unchanged parameter // Note: If they differ from the beginning we migrate old to new - if (firstcall || !isFloatEqual(*old_val, previous_old_val)) { + if (firstcall || !matrix::isEqualF((float)*old_val, (float)previous_old_val)) { param_set_no_notification(new_param, old_val); param_get(new_param, new_val); - } else if (!isFloatEqual(*new_val, previous_new_val)) { + } else if (!matrix::isEqualF((float)*new_val, (float)previous_new_val)) { param_set_no_notification(old_param, new_val); param_get(old_param, old_val); } } } - bool isFloatEqual(float a, float b) const { return fabsf(a - b) > FLT_EPSILON; } - private: void sumDischarged(const hrt_abstime ×tamp, float current_a); void estimateRemaining(const float voltage_v, const float current_a, const float throttle);