1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

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.
This commit is contained in:
Bruce Luckcuck 2019-11-08 16:16:16 -05:00
parent c77c593a14
commit be79913726
4 changed files with 14 additions and 10 deletions

View file

@ -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];

View file

@ -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;
}

View file

@ -111,4 +111,4 @@ void writeMotors(void);
bool mixerIsTricopter(void);
void mixerSetThrottleAngleCorrection(int correctionValue);
float mixerGetLoggingThrottle(void);
float mixerGetThrottle(void);

View file

@ -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(&currentMeter);