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

View file

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

View file

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

View file

@ -82,7 +82,7 @@ int16_t magHoldTargetHeading;
static pt1Filter_t magHoldRateFilter; static pt1Filter_t magHoldRateFilter;
// Thrust PID Attenuation factor. 0.0f means fully attenuated, 1.0f no attenuation is applied // 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; static float tpaFactor;
int16_t axisPID[FLIGHT_DYNAMICS_INDEX_COUNT]; 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_LEVEL_P_MULTIPLIER 65.6f
#define FP_PID_YAWHOLD_P_MULTIPLIER 80.0f #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) 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 // Check if throttle changed
if (rcCommand[THROTTLE] != prevThrottle) { if (rcCommand[THROTTLE] != prevThrottle) {
prevThrottle = rcCommand[THROTTLE]; prevThrottle = rcCommand[THROTTLE];
signalRequiredPIDCoefficientsUpdate(); pidGainsUpdateRequired = true;
} }
// If nothing changed - don't waste time recalculating coefficients // If nothing changed - don't waste time recalculating coefficients
if (!shouldUpdatePIDCoeffs) { if (!pidGainsUpdateRequired) {
return; 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) static void pidApplyHeadingLock(const pidProfile_t *pidProfile, pidState_t *pidState)

View file

@ -87,7 +87,7 @@ struct controlRateConfig_s;
struct motorConfig_s; struct motorConfig_s;
struct rxConfig_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 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); void pidController(const pidProfile_t *pidProfile, const struct controlRateConfig_s *controlRateConfig, const struct rxConfig_s *rxConfig);