From be799137262a908fd0f14017cbaf2e48af55e1d1 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Fri, 8 Nov 2019 16:16:16 -0500 Subject: [PATCH] Change virtual current meter to use setpoint rather than rcCommand throttle Use the final calculated throttle value that may be affected by throttle limiting, throttle boost, etc. instead of the rcCommand input when calculating the virtual current meter. --- src/main/blackbox/blackbox.c | 2 +- src/main/flight/mixer.c | 8 ++++---- src/main/flight/mixer.h | 2 +- src/main/sensors/battery.c | 12 ++++++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index e15a0de086..6c0b97183b 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1035,7 +1035,7 @@ static void loadMainState(timeUs_t currentTimeUs) blackboxCurrent->setpoint[i] = lrintf(pidGetPreviousSetpoint(i)); } // log the final throttle value used in the mixer - blackboxCurrent->setpoint[3] = lrintf(mixerGetLoggingThrottle() * 1000); + blackboxCurrent->setpoint[3] = lrintf(mixerGetThrottle() * 1000); for (int i = 0; i < DEBUG16_VALUE_COUNT; i++) { blackboxCurrent->debug[i] = debug[i]; diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index a8afa68701..b92a5143bd 100644 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -472,7 +472,7 @@ void stopMotors(void) } static FAST_RAM_ZERO_INIT float throttle = 0; -static FAST_RAM_ZERO_INIT float loggingThrottle = 0; +static FAST_RAM_ZERO_INIT float mixerThrottle = 0; static FAST_RAM_ZERO_INIT float motorOutputMin; static FAST_RAM_ZERO_INIT float motorRangeMin; static FAST_RAM_ZERO_INIT float motorRangeMax; @@ -891,7 +891,7 @@ FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensa throttle += pidGetAirmodeThrottleOffset(); float airmodeThrottleChange = 0; #endif - loggingThrottle = throttle; + mixerThrottle = throttle; motorMixRange = motorMixMax - motorMixMin; if (motorMixRange > 1.0f) { @@ -934,7 +934,7 @@ void mixerSetThrottleAngleCorrection(int correctionValue) throttleAngleCorrection = correctionValue; } -float mixerGetLoggingThrottle(void) +float mixerGetThrottle(void) { - return loggingThrottle; + return mixerThrottle; } diff --git a/src/main/flight/mixer.h b/src/main/flight/mixer.h index 6469cd4855..572f03861d 100644 --- a/src/main/flight/mixer.h +++ b/src/main/flight/mixer.h @@ -111,4 +111,4 @@ void writeMotors(void); bool mixerIsTricopter(void); void mixerSetThrottleAngleCorrection(int correctionValue); -float mixerGetLoggingThrottle(void); +float mixerGetThrottle(void); diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 25a2dfacfb..7764bcf391 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -20,6 +20,7 @@ #include "stdbool.h" #include "stdint.h" +#include "math.h" #include "platform.h" @@ -29,18 +30,21 @@ #include "common/maths.h" #include "common/utils.h" +#include "config/config.h" #include "config/feature.h" -#include "pg/pg.h" -#include "pg/pg_ids.h" #include "drivers/adc.h" #include "fc/runtime_config.h" -#include "config/config.h" #include "fc/rc_controls.h" +#include "flight/mixer.h" + #include "io/beeper.h" +#include "pg/pg.h" +#include "pg/pg_ids.h" + #include "sensors/battery.h" /** @@ -427,7 +431,7 @@ void batteryUpdateCurrentMeter(timeUs_t currentTimeUs) #ifdef USE_VIRTUAL_CURRENT_METER throttleStatus_e throttleStatus = calculateThrottleStatus(); bool throttleLowAndMotorStop = (throttleStatus == THROTTLE_LOW && featureIsEnabled(FEATURE_MOTOR_STOP)); - int32_t throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000; + const int32_t throttleOffset = lrintf(mixerGetThrottle() * 1000); currentMeterVirtualRefresh(lastUpdateAt, ARMING_FLAG(ARMED), throttleLowAndMotorStop, throttleOffset); currentMeterVirtualRead(¤tMeter);