mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 03:50:02 +03:00
Merge pull request #9633 from mikeller/remove_vbat_pid_compensation
Remove vbat pid compensation
This commit is contained in:
commit
41fa8754bc
13 changed files with 7 additions and 27 deletions
|
@ -1372,7 +1372,6 @@ static bool blackboxWriteSysinfo(void)
|
||||||
BLACKBOX_PRINT_HEADER_LINE("iterm_relax_type", "%d", currentPidProfile->iterm_relax_type);
|
BLACKBOX_PRINT_HEADER_LINE("iterm_relax_type", "%d", currentPidProfile->iterm_relax_type);
|
||||||
BLACKBOX_PRINT_HEADER_LINE("iterm_relax_cutoff", "%d", currentPidProfile->iterm_relax_cutoff);
|
BLACKBOX_PRINT_HEADER_LINE("iterm_relax_cutoff", "%d", currentPidProfile->iterm_relax_cutoff);
|
||||||
#endif
|
#endif
|
||||||
BLACKBOX_PRINT_HEADER_LINE("vbat_pid_gain", "%d", currentPidProfile->vbatPidCompensation);
|
|
||||||
BLACKBOX_PRINT_HEADER_LINE("pidAtMinThrottle", "%d", currentPidProfile->pidAtMinThrottle);
|
BLACKBOX_PRINT_HEADER_LINE("pidAtMinThrottle", "%d", currentPidProfile->pidAtMinThrottle);
|
||||||
|
|
||||||
// Betaflight PID controller parameters
|
// Betaflight PID controller parameters
|
||||||
|
|
|
@ -1035,7 +1035,6 @@ const clivalue_t valueTable[] = {
|
||||||
{ "dterm_lowpass2_hz", VAR_INT16 | PROFILE_VALUE, .config.minmax = { 0, FILTER_FREQUENCY_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_lowpass2_hz) },
|
{ "dterm_lowpass2_hz", VAR_INT16 | PROFILE_VALUE, .config.minmax = { 0, FILTER_FREQUENCY_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_lowpass2_hz) },
|
||||||
{ "dterm_notch_hz", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, FILTER_FREQUENCY_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_notch_hz) },
|
{ "dterm_notch_hz", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, FILTER_FREQUENCY_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_notch_hz) },
|
||||||
{ "dterm_notch_cutoff", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, FILTER_FREQUENCY_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_notch_cutoff) },
|
{ "dterm_notch_cutoff", VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, FILTER_FREQUENCY_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, dterm_notch_cutoff) },
|
||||||
{ "vbat_pid_gain", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, vbatPidCompensation) },
|
|
||||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||||
{ "vbat_sag_compensation", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 150 }, PG_PID_PROFILE, offsetof(pidProfile_t, vbat_sag_compensation) },
|
{ "vbat_sag_compensation", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 150 }, PG_PID_PROFILE, offsetof(pidProfile_t, vbat_sag_compensation) },
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1188,7 +1188,7 @@ static FAST_CODE void subTaskMotorUpdate(timeUs_t currentTimeUs)
|
||||||
startTime = micros();
|
startTime = micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
mixTable(currentTimeUs, currentPidProfile->vbatPidCompensation);
|
mixTable(currentTimeUs);
|
||||||
|
|
||||||
#ifdef USE_SERVOS
|
#ifdef USE_SERVOS
|
||||||
// motor outputs are used as sources for servo mixing, so motors must be calculated using mixTable() before servos.
|
// motor outputs are used as sources for servo mixing, so motors must be calculated using mixTable() before servos.
|
||||||
|
|
|
@ -825,7 +825,7 @@ static void updateDynLpfCutoffs(timeUs_t currentTimeUs, float throttle)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensation)
|
FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
// Find min and max throttle based on conditions. Throttle has to be known before mixing
|
// Find min and max throttle based on conditions. Throttle has to be known before mixing
|
||||||
calculateThrottleAndCurrentMotorEndpoints(currentTimeUs);
|
calculateThrottleAndCurrentMotorEndpoints(currentTimeUs);
|
||||||
|
@ -867,9 +867,6 @@ FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensa
|
||||||
scaledAxisPidYaw = -scaledAxisPidYaw;
|
scaledAxisPidYaw = -scaledAxisPidYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate voltage compensation
|
|
||||||
const float vbatCompensationFactor = vbatPidCompensation ? calculateVbatPidCompensation() : 1.0f;
|
|
||||||
|
|
||||||
// Apply the throttle_limit_percent to scale or limit the throttle based on throttle_limit_type
|
// Apply the throttle_limit_percent to scale or limit the throttle based on throttle_limit_type
|
||||||
if (currentControlRateProfile->throttle_limit_type != THROTTLE_LIMIT_TYPE_OFF) {
|
if (currentControlRateProfile->throttle_limit_type != THROTTLE_LIMIT_TYPE_OFF) {
|
||||||
throttle = applyThrottleLimit(throttle);
|
throttle = applyThrottleLimit(throttle);
|
||||||
|
@ -903,8 +900,6 @@ FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensa
|
||||||
scaledAxisPidPitch * activeMixer[i].pitch +
|
scaledAxisPidPitch * activeMixer[i].pitch +
|
||||||
scaledAxisPidYaw * activeMixer[i].yaw;
|
scaledAxisPidYaw * activeMixer[i].yaw;
|
||||||
|
|
||||||
mix *= vbatCompensationFactor; // Add voltage compensation
|
|
||||||
|
|
||||||
if (mix > motorMixMax) {
|
if (mix > motorMixMax) {
|
||||||
motorMixMax = mix;
|
motorMixMax = mix;
|
||||||
} else if (mix < motorMixMin) {
|
} else if (mix < motorMixMin) {
|
||||||
|
|
|
@ -106,7 +106,7 @@ void mixerInitProfile(void);
|
||||||
void mixerConfigureOutput(void);
|
void mixerConfigureOutput(void);
|
||||||
|
|
||||||
void mixerResetDisarmedMotors(void);
|
void mixerResetDisarmedMotors(void);
|
||||||
void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensation);
|
void mixTable(timeUs_t currentTimeUs);
|
||||||
void stopMotors(void);
|
void stopMotors(void);
|
||||||
void writeMotors(void);
|
void writeMotors(void);
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,6 @@ void resetPidProfile(pidProfile_t *pidProfile)
|
||||||
.dterm_notch_hz = 0,
|
.dterm_notch_hz = 0,
|
||||||
.dterm_notch_cutoff = 0,
|
.dterm_notch_cutoff = 0,
|
||||||
.itermWindupPointPercent = 100,
|
.itermWindupPointPercent = 100,
|
||||||
.vbatPidCompensation = 0,
|
|
||||||
.pidAtMinThrottle = PID_STABILISATION_ON,
|
.pidAtMinThrottle = PID_STABILISATION_ON,
|
||||||
.levelAngleLimit = 55,
|
.levelAngleLimit = 55,
|
||||||
.feedForwardTransition = 0,
|
.feedForwardTransition = 0,
|
||||||
|
|
|
@ -149,7 +149,6 @@ typedef struct pidProfile_s {
|
||||||
uint16_t crash_delay; // ms
|
uint16_t crash_delay; // ms
|
||||||
uint8_t crash_recovery_angle; // degrees
|
uint8_t crash_recovery_angle; // degrees
|
||||||
uint8_t crash_recovery_rate; // degree/second
|
uint8_t crash_recovery_rate; // degree/second
|
||||||
uint8_t vbatPidCompensation; // Scale PIDsum to battery voltage
|
|
||||||
uint8_t feedForwardTransition; // Feed forward weight transition
|
uint8_t feedForwardTransition; // Feed forward weight transition
|
||||||
uint16_t crash_limit_yaw; // limits yaw errorRate, so crashes don't cause huge throttle increase
|
uint16_t crash_limit_yaw; // limits yaw errorRate, so crashes don't cause huge throttle increase
|
||||||
uint16_t itermLimit;
|
uint16_t itermLimit;
|
||||||
|
|
|
@ -1746,7 +1746,7 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst)
|
||||||
sbufWriteU16(dst, 0);
|
sbufWriteU16(dst, 0);
|
||||||
sbufWriteU16(dst, 0); // was pidProfile.yaw_p_limit
|
sbufWriteU16(dst, 0); // was pidProfile.yaw_p_limit
|
||||||
sbufWriteU8(dst, 0); // reserved
|
sbufWriteU8(dst, 0); // reserved
|
||||||
sbufWriteU8(dst, currentPidProfile->vbatPidCompensation);
|
sbufWriteU8(dst, 0); // was vbatPidCompensation
|
||||||
sbufWriteU8(dst, currentPidProfile->feedForwardTransition);
|
sbufWriteU8(dst, currentPidProfile->feedForwardTransition);
|
||||||
sbufWriteU8(dst, 0); // was low byte of currentPidProfile->dtermSetpointWeight
|
sbufWriteU8(dst, 0); // was low byte of currentPidProfile->dtermSetpointWeight
|
||||||
sbufWriteU8(dst, 0); // reserved
|
sbufWriteU8(dst, 0); // reserved
|
||||||
|
@ -2595,7 +2595,7 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
|
||||||
sbufReadU16(src);
|
sbufReadU16(src);
|
||||||
sbufReadU16(src); // was pidProfile.yaw_p_limit
|
sbufReadU16(src); // was pidProfile.yaw_p_limit
|
||||||
sbufReadU8(src); // reserved
|
sbufReadU8(src); // reserved
|
||||||
currentPidProfile->vbatPidCompensation = sbufReadU8(src);
|
sbufReadU8(src); // was vbatPidCompensation
|
||||||
currentPidProfile->feedForwardTransition = sbufReadU8(src);
|
currentPidProfile->feedForwardTransition = sbufReadU8(src);
|
||||||
sbufReadU8(src); // was low byte of currentPidProfile->dtermSetpointWeight
|
sbufReadU8(src); // was low byte of currentPidProfile->dtermSetpointWeight
|
||||||
sbufReadU8(src); // reserved
|
sbufReadU8(src); // reserved
|
||||||
|
|
|
@ -460,15 +460,6 @@ void batteryUpdateCurrentMeter(timeUs_t currentTimeUs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float calculateVbatPidCompensation(void) {
|
|
||||||
float batteryScaler = 1.0f;
|
|
||||||
if (batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE && batteryCellCount > 0) {
|
|
||||||
// Up to 33% PID gain. Should be fine for 4,2to 3,3 difference
|
|
||||||
batteryScaler = constrainf((( (float)batteryConfig()->vbatmaxcellvoltage * batteryCellCount ) / (float) voltageMeter.displayFiltered), 1.0f, 1.33f);
|
|
||||||
}
|
|
||||||
return batteryScaler;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t calculateBatteryPercentageRemaining(void)
|
uint8_t calculateBatteryPercentageRemaining(void)
|
||||||
{
|
{
|
||||||
uint8_t batteryPercentage = 0;
|
uint8_t batteryPercentage = 0;
|
||||||
|
|
|
@ -101,7 +101,6 @@ void batteryUpdateAlarms(void);
|
||||||
|
|
||||||
struct rxConfig_s;
|
struct rxConfig_s;
|
||||||
|
|
||||||
float calculateVbatPidCompensation(void);
|
|
||||||
uint8_t calculateBatteryPercentageRemaining(void);
|
uint8_t calculateBatteryPercentageRemaining(void);
|
||||||
bool isBatteryVoltageConfigured(void);
|
bool isBatteryVoltageConfigured(void);
|
||||||
uint16_t getBatteryVoltage(void);
|
uint16_t getBatteryVoltage(void);
|
||||||
|
|
|
@ -1047,7 +1047,7 @@ extern "C" {
|
||||||
bool isFirstArmingGyroCalibrationRunning(void) { return false; }
|
bool isFirstArmingGyroCalibrationRunning(void) { return false; }
|
||||||
void pidController(const pidProfile_t *, timeUs_t) {}
|
void pidController(const pidProfile_t *, timeUs_t) {}
|
||||||
void pidStabilisationState(pidStabilisationState_e) {}
|
void pidStabilisationState(pidStabilisationState_e) {}
|
||||||
void mixTable(timeUs_t , uint8_t) {};
|
void mixTable(timeUs_t) {};
|
||||||
void writeMotors(void) {};
|
void writeMotors(void) {};
|
||||||
void writeServos(void) {};
|
void writeServos(void) {};
|
||||||
bool calculateRxChannelsAndUpdateFailsafe(timeUs_t) { return true; }
|
bool calculateRxChannelsAndUpdateFailsafe(timeUs_t) { return true; }
|
||||||
|
|
|
@ -114,7 +114,6 @@ void setDefaultTestSettings(void) {
|
||||||
pidProfile->dterm_notch_cutoff = 160;
|
pidProfile->dterm_notch_cutoff = 160;
|
||||||
pidProfile->dterm_filter_type = FILTER_BIQUAD;
|
pidProfile->dterm_filter_type = FILTER_BIQUAD;
|
||||||
pidProfile->itermWindupPointPercent = 50;
|
pidProfile->itermWindupPointPercent = 50;
|
||||||
pidProfile->vbatPidCompensation = 0;
|
|
||||||
pidProfile->pidAtMinThrottle = PID_STABILISATION_ON;
|
pidProfile->pidAtMinThrottle = PID_STABILISATION_ON;
|
||||||
pidProfile->levelAngleLimit = 55;
|
pidProfile->levelAngleLimit = 55;
|
||||||
pidProfile->feedForwardTransition = 100;
|
pidProfile->feedForwardTransition = 100;
|
||||||
|
|
|
@ -139,7 +139,7 @@ extern "C" {
|
||||||
bool isFirstArmingGyroCalibrationRunning(void) { return false; }
|
bool isFirstArmingGyroCalibrationRunning(void) { return false; }
|
||||||
void pidController(const pidProfile_t *, timeUs_t) {}
|
void pidController(const pidProfile_t *, timeUs_t) {}
|
||||||
void pidStabilisationState(pidStabilisationState_e) {}
|
void pidStabilisationState(pidStabilisationState_e) {}
|
||||||
void mixTable(timeUs_t , uint8_t) {};
|
void mixTable(timeUs_t) {};
|
||||||
void writeMotors(void) {};
|
void writeMotors(void) {};
|
||||||
void writeServos(void) {};
|
void writeServos(void) {};
|
||||||
bool calculateRxChannelsAndUpdateFailsafe(timeUs_t) { return true; }
|
bool calculateRxChannelsAndUpdateFailsafe(timeUs_t) { return true; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue