mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
Merge pull request #11361 from bobbycisneros/OSDBattEfficiencyFix
Update for Battery Efficiency Fix Issue #11277
This commit is contained in:
commit
7b4415f062
2 changed files with 9 additions and 6 deletions
|
@ -121,6 +121,7 @@
|
|||
#include "common/typeconversion.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/unit.h"
|
||||
#include "common/filter.h"
|
||||
|
||||
#include "config/config.h"
|
||||
#include "config/feature.h"
|
||||
|
@ -178,6 +179,9 @@
|
|||
|
||||
#define FULL_CIRCLE 360
|
||||
#define EFFICIENCY_MINIMUM_SPEED_CM_S 100
|
||||
#define EFFICIENCY_CUTOFF_HZ 0.5f
|
||||
|
||||
static pt1Filter_t batteryEfficiencyFilt;
|
||||
|
||||
#define MOTOR_STOPPED_THRESHOLD_RPM 1000
|
||||
|
||||
|
@ -1082,12 +1086,9 @@ static void osdElementEfficiency(osdElementParms_t *element)
|
|||
{
|
||||
int efficiency = 0;
|
||||
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
|
||||
|
||||
if (speedX100 > 0) {
|
||||
const int mAmperage = getAmperage() * 10; // Current in mA
|
||||
efficiency = mAmperage * 100 / speedX100; // mAmperage * 100 to cancel out speed * 100 from above
|
||||
}
|
||||
const float speed = (float)osdGetSpeedToSelectedUnit(gpsSol.groundSpeed);
|
||||
const float mAmperage = (float)getAmperage() * 10.f; // Current in mA
|
||||
efficiency = lrintf(pt1FilterApply(&batteryEfficiencyFilt, (mAmperage / speed)));
|
||||
}
|
||||
|
||||
const char unitSymbol = osdConfig()->units == UNIT_IMPERIAL ? SYM_MILES : SYM_KM;
|
||||
|
@ -1858,6 +1859,7 @@ void osdElementsInit(bool backgroundLayerFlag)
|
|||
{
|
||||
backgroundLayerSupported = backgroundLayerFlag;
|
||||
activeOsdElementCount = 0;
|
||||
pt1FilterInit(&batteryEfficiencyFilt, pt1FilterGain(EFFICIENCY_CUTOFF_HZ, 1.0f / osdConfig()->framerate_hz));
|
||||
}
|
||||
|
||||
void osdSyncBlink() {
|
||||
|
|
|
@ -192,6 +192,7 @@ osd_unittest_SRC := \
|
|||
$(USER_DIR)/common/maths.c \
|
||||
$(USER_DIR)/common/printf.c \
|
||||
$(USER_DIR)/common/time.c \
|
||||
$(USER_DIR)/common/filter.c \
|
||||
$(USER_DIR)/fc/runtime_config.c
|
||||
|
||||
osd_unittest_DEFINES := \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue