diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index e39a2f6c3..b17bb03b7 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -710,7 +710,7 @@ const clivalue_t valueTable[] = { { "iterm_windup", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.itermWindupPointPercent, .config.minmax = {30, 100 } }, { "yaw_lowpass", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yaw_lpf_hz, .config.minmax = {0, 500 } }, - { "pid_process_denom", VAR_UINT8 | MASTER_VALUE, &pidConfig()->pid_process_denom, .config.minmax = { 1, 16 } }, + { "pid_process_denom", VAR_UINT8 | MASTER_VALUE, &pidConfig()->pid_process_denom, .config.minmax = { 1, MAX_PID_PROCESS_DENOM } }, { "p_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PITCH], .config.minmax = { 0, 200 } }, { "i_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PITCH], .config.minmax = { 0, 200 } }, diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 4b06396ad..f7c2af595 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -937,11 +937,11 @@ void activateConfig(void) void validateAndFixConfig(void) { - if((motorConfig()->motorPwmProtocol == PWM_TYPE_BRUSHED) && (motorConfig()->mincommand < 1000)) { + if ((motorConfig()->motorPwmProtocol == PWM_TYPE_BRUSHED) && (motorConfig()->mincommand < 1000)) { motorConfigMutable()->mincommand = 1000; } - if((motorConfig()->motorPwmProtocol == PWM_TYPE_STANDARD) && (motorConfig()->motorPwmRate > 400)) { + if ((motorConfig()->motorPwmProtocol == PWM_TYPE_STANDARD) && (motorConfig()->motorPwmRate > 400)) { motorConfig()->motorPwmRate = 400; } @@ -1093,7 +1093,7 @@ void validateAndFixGyroConfig(void) float motorUpdateRestriction; switch(motorConfig()->motorPwmProtocol) { case (PWM_TYPE_STANDARD): - motorUpdateRestriction = 0.002f; + motorUpdateRestriction = 0.0025f; break; case (PWM_TYPE_ONESHOT125): motorUpdateRestriction = 0.0005f; @@ -1113,11 +1113,13 @@ void validateAndFixGyroConfig(void) motorUpdateRestriction = 0.00003125f; } - if(pidLooptime < motorUpdateRestriction) - pidConfig()->pid_process_denom = motorUpdateRestriction / (samplingTime * gyroConfig()->gyro_sync_denom); + if (pidLooptime < motorUpdateRestriction) { + const uint8_t maxPidProcessDenom = constrain(motorUpdateRestriction / (samplingTime * gyroConfig()->gyro_sync_denom), 1, MAX_PID_PROCESS_DENOM); + pidConfigMutable()->pid_process_denom = MIN(pidConfigMutable()->pid_process_denom, maxPidProcessDenom); + } // Prevent overriding the max rate of motors - if(motorConfig()->useUnsyncedPwm && (motorConfig()->motorPwmProtocol <= PWM_TYPE_BRUSHED)) { + if (motorConfig()->useUnsyncedPwm && (motorConfig()->motorPwmProtocol <= PWM_TYPE_BRUSHED)) { uint32_t maxEscRate = lrintf(1.0f / motorUpdateRestriction); if(motorConfig()->motorPwmRate > maxEscRate) diff --git a/src/main/flight/pid.h b/src/main/flight/pid.h index 2c40241d3..f0f756a6a 100644 --- a/src/main/flight/pid.h +++ b/src/main/flight/pid.h @@ -19,12 +19,13 @@ #include -#define PID_CONTROLLER_BETAFLIGHT 1 -#define PID_MIXER_SCALING 1000.0f -#define PID_SERVO_MIXER_SCALING 0.7f -#define YAW_P_LIMIT_MIN 100 // Maximum value for yaw P limiter -#define YAW_P_LIMIT_MAX 500 // Maximum value for yaw P limiter -#define PIDSUM_LIMIT 0.5f +#define MAX_PID_PROCESS_DENOM 16 +#define PID_CONTROLLER_BETAFLIGHT 1 +#define PID_MIXER_SCALING 1000.0f +#define PID_SERVO_MIXER_SCALING 0.7f +#define YAW_P_LIMIT_MIN 100 // Maximum value for yaw P limiter +#define YAW_P_LIMIT_MAX 500 // Maximum value for yaw P limiter +#define PIDSUM_LIMIT 0.5f // Scaling factors for Pids for better tunable range in configurator for betaflight pid controller. The scaling is based on legacy pid controller or previous float #define PTERM_SCALE 0.032029f