1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 03:20:00 +03:00

Merge pull request #11361 from bobbycisneros/OSDBattEfficiencyFix

Update for Battery Efficiency Fix Issue #11277
This commit is contained in:
haslinghuis 2022-02-14 00:22:48 +01:00 committed by GitHub
commit 7b4415f062
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -121,6 +121,7 @@
#include "common/typeconversion.h" #include "common/typeconversion.h"
#include "common/utils.h" #include "common/utils.h"
#include "common/unit.h" #include "common/unit.h"
#include "common/filter.h"
#include "config/config.h" #include "config/config.h"
#include "config/feature.h" #include "config/feature.h"
@ -178,6 +179,9 @@
#define FULL_CIRCLE 360 #define FULL_CIRCLE 360
#define EFFICIENCY_MINIMUM_SPEED_CM_S 100 #define EFFICIENCY_MINIMUM_SPEED_CM_S 100
#define EFFICIENCY_CUTOFF_HZ 0.5f
static pt1Filter_t batteryEfficiencyFilt;
#define MOTOR_STOPPED_THRESHOLD_RPM 1000 #define MOTOR_STOPPED_THRESHOLD_RPM 1000
@ -1082,12 +1086,9 @@ static void osdElementEfficiency(osdElementParms_t *element)
{ {
int efficiency = 0; int efficiency = 0;
if (sensors(SENSOR_GPS) && ARMING_FLAG(ARMED) && STATE(GPS_FIX) && gpsSol.groundSpeed >= EFFICIENCY_MINIMUM_SPEED_CM_S) { if (sensors(SENSOR_GPS) && ARMING_FLAG(ARMED) && STATE(GPS_FIX) && gpsSol.groundSpeed >= EFFICIENCY_MINIMUM_SPEED_CM_S) {
const int speedX100 = osdGetSpeedToSelectedUnit(gpsSol.groundSpeed * 100); // speed * 100 for improved resolution at slow speeds const float speed = (float)osdGetSpeedToSelectedUnit(gpsSol.groundSpeed);
const float mAmperage = (float)getAmperage() * 10.f; // Current in mA
if (speedX100 > 0) { efficiency = lrintf(pt1FilterApply(&batteryEfficiencyFilt, (mAmperage / speed)));
const int mAmperage = getAmperage() * 10; // Current in mA
efficiency = mAmperage * 100 / speedX100; // mAmperage * 100 to cancel out speed * 100 from above
}
} }
const char unitSymbol = osdConfig()->units == UNIT_IMPERIAL ? SYM_MILES : SYM_KM; const char unitSymbol = osdConfig()->units == UNIT_IMPERIAL ? SYM_MILES : SYM_KM;
@ -1858,6 +1859,7 @@ void osdElementsInit(bool backgroundLayerFlag)
{ {
backgroundLayerSupported = backgroundLayerFlag; backgroundLayerSupported = backgroundLayerFlag;
activeOsdElementCount = 0; activeOsdElementCount = 0;
pt1FilterInit(&batteryEfficiencyFilt, pt1FilterGain(EFFICIENCY_CUTOFF_HZ, 1.0f / osdConfig()->framerate_hz));
} }
void osdSyncBlink() { void osdSyncBlink() {

View file

@ -192,6 +192,7 @@ osd_unittest_SRC := \
$(USER_DIR)/common/maths.c \ $(USER_DIR)/common/maths.c \
$(USER_DIR)/common/printf.c \ $(USER_DIR)/common/printf.c \
$(USER_DIR)/common/time.c \ $(USER_DIR)/common/time.c \
$(USER_DIR)/common/filter.c \
$(USER_DIR)/fc/runtime_config.c $(USER_DIR)/fc/runtime_config.c
osd_unittest_DEFINES := \ osd_unittest_DEFINES := \