1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-16 21:05:32 +03:00

Fix missing PID gains updates

This commit is contained in:
Konstantin Sharlaimov (DigitalEntity) 2016-12-01 10:15:57 +10:00
parent efb65c6f5d
commit 33e79030f4
5 changed files with 28 additions and 21 deletions

View file

@ -150,6 +150,8 @@ static long cmsx_PidWriteback(const OSD_Entry *self)
cmsx_WritebackPidFromArray(cmsx_pidPitch, PIDPITCH);
cmsx_WritebackPidFromArray(cmsx_pidYaw, PIDYAW);
schedulePidGainsUpdate();
return 0;
}
@ -203,6 +205,8 @@ static long cmsx_menuPidAltMag_onExit(const OSD_Entry *self)
cmsx_WritebackPidFromArray(cmsx_pidVel, PIDVEL);
masterConfig.profile[profileIndex].pidProfile.P8[PIDMAG] = cmsx_pidMag[0];
navigationUsePIDs(&masterConfig.profile[profileIndex].pidProfile);
return 0;
}
@ -251,6 +255,8 @@ static long cmsx_menuPidGpsnav_onExit(const OSD_Entry *self)
cmsx_WritebackPidFromArray(cmsx_pidPosR, PIDPOSR);
cmsx_WritebackPidFromArray(cmsx_pidNavR, PIDNAVR);
navigationUsePIDs(&masterConfig.profile[profileIndex].pidProfile);
return 0;
}

View file

@ -1198,12 +1198,13 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
break;
case MSP_SET_PID:
signalRequiredPIDCoefficientsUpdate();
for (int i = 0; i < PID_ITEM_COUNT; i++) {
currentProfile->pidProfile.P8[i] = sbufReadU8(src);
currentProfile->pidProfile.I8[i] = sbufReadU8(src);
currentProfile->pidProfile.D8[i] = sbufReadU8(src);
}
schedulePidGainsUpdate();
navigationUsePIDs(&currentProfile->pidProfile);
break;
case MSP_SET_MODE_RANGE:
@ -1269,7 +1270,7 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
currentControlRateProfile->rcYawExpo8 = sbufReadU8(src);
}
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
} else {
return MSP_RESULT_ERROR;
}

View file

@ -531,7 +531,7 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
controlRateConfig->rates[FD_PITCH] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_RATE, newValue);
if (adjustmentFunction == ADJUSTMENT_PITCH_RATE) {
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
}
// follow though for combined ADJUSTMENT_PITCH_ROLL_RATE
@ -539,13 +539,13 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
newValue = constrain((int)controlRateConfig->rates[FD_ROLL] + delta, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MIN, CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX);
controlRateConfig->rates[FD_ROLL] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_RATE, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_YAW_RATE:
newValue = constrain((int)controlRateConfig->rates[FD_YAW] + delta, CONTROL_RATE_CONFIG_YAW_RATE_MIN, CONTROL_RATE_CONFIG_YAW_RATE_MAX);
controlRateConfig->rates[FD_YAW] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_RATE, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_PITCH_ROLL_P:
case ADJUSTMENT_PITCH_P:
@ -553,7 +553,7 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
pidProfile->P8[PIDPITCH] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_P, newValue);
if (adjustmentFunction == ADJUSTMENT_PITCH_P) {
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
}
// follow though for combined ADJUSTMENT_PITCH_ROLL_P
@ -561,7 +561,7 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
newValue = constrain((int)pidProfile->P8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in serial_cli.c
pidProfile->P8[PIDROLL] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_P, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_PITCH_ROLL_I:
case ADJUSTMENT_PITCH_I:
@ -569,7 +569,7 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
pidProfile->I8[PIDPITCH] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_I, newValue);
if (adjustmentFunction == ADJUSTMENT_PITCH_I) {
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
}
// follow though for combined ADJUSTMENT_PITCH_ROLL_I
@ -577,7 +577,7 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
newValue = constrain((int)pidProfile->I8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in serial_cli.c
pidProfile->I8[PIDROLL] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_I, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_PITCH_ROLL_D:
case ADJUSTMENT_PITCH_D:
@ -585,7 +585,7 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
pidProfile->D8[PIDPITCH] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_D, newValue);
if (adjustmentFunction == ADJUSTMENT_PITCH_D) {
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
}
// follow though for combined ADJUSTMENT_PITCH_ROLL_D
@ -593,25 +593,25 @@ void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustm
newValue = constrain((int)pidProfile->D8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in serial_cli.c
pidProfile->D8[PIDROLL] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_D, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_YAW_P:
newValue = constrain((int)pidProfile->P8[PIDYAW] + delta, 0, 200); // FIXME magic numbers repeated in serial_cli.c
pidProfile->P8[PIDYAW] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_P, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_YAW_I:
newValue = constrain((int)pidProfile->I8[PIDYAW] + delta, 0, 200); // FIXME magic numbers repeated in serial_cli.c
pidProfile->I8[PIDYAW] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_I, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
case ADJUSTMENT_YAW_D:
newValue = constrain((int)pidProfile->D8[PIDYAW] + delta, 0, 200); // FIXME magic numbers repeated in serial_cli.c
pidProfile->D8[PIDYAW] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_D, newValue);
signalRequiredPIDCoefficientsUpdate();
schedulePidGainsUpdate();
break;
default:
break;

View file

@ -82,7 +82,7 @@ int16_t magHoldTargetHeading;
static pt1Filter_t magHoldRateFilter;
// Thrust PID Attenuation factor. 0.0f means fully attenuated, 1.0f no attenuation is applied
static bool shouldUpdatePIDCoeffs = false;
static bool pidGainsUpdateRequired = false;
static float tpaFactor;
int16_t axisPID[FLIGHT_DYNAMICS_INDEX_COUNT];
@ -152,9 +152,9 @@ FP-PID has been rescaled to match LuxFloat (and MWRewrite) from Cleanflight 1.13
#define FP_PID_LEVEL_P_MULTIPLIER 65.6f
#define FP_PID_YAWHOLD_P_MULTIPLIER 80.0f
void signalRequiredPIDCoefficientsUpdate(void)
void schedulePidGainsUpdate(void)
{
shouldUpdatePIDCoeffs = true;
pidGainsUpdateRequired = true;
}
void updatePIDCoefficients(const pidProfile_t *pidProfile, const controlRateConfig_t *controlRateConfig, const struct motorConfig_s *motorConfig)
@ -164,11 +164,11 @@ void updatePIDCoefficients(const pidProfile_t *pidProfile, const controlRateConf
// Check if throttle changed
if (rcCommand[THROTTLE] != prevThrottle) {
prevThrottle = rcCommand[THROTTLE];
signalRequiredPIDCoefficientsUpdate();
pidGainsUpdateRequired = true;
}
// If nothing changed - don't waste time recalculating coefficients
if (!shouldUpdatePIDCoeffs) {
if (!pidGainsUpdateRequired) {
return;
}
@ -235,7 +235,7 @@ void updatePIDCoefficients(const pidProfile_t *pidProfile, const controlRateConf
}
}
shouldUpdatePIDCoeffs = false;
pidGainsUpdateRequired = false;
}
static void pidApplyHeadingLock(const pidProfile_t *pidProfile, pidState_t *pidState)

View file

@ -87,7 +87,7 @@ struct controlRateConfig_s;
struct motorConfig_s;
struct rxConfig_s;
void signalRequiredPIDCoefficientsUpdate(void);
void schedulePidGainsUpdate(void);
void updatePIDCoefficients(const pidProfile_t *pidProfile, const struct controlRateConfig_s *controlRateConfig, const struct motorConfig_s *motorConfig);
void pidController(const pidProfile_t *pidProfile, const struct controlRateConfig_s *controlRateConfig, const struct rxConfig_s *rxConfig);