Fixed possible pid process denom exceeding allowed values

This commit is contained in:
blckmn 2017-02-06 04:54:35 +11:00 committed by borisbstyle
parent 297f5ba2af
commit 9f17bae3e4
3 changed files with 16 additions and 13 deletions

View File

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

View File

@ -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,8 +1113,10 @@ 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)) {

View File

@ -19,6 +19,7 @@
#include <stdbool.h>
#define MAX_PID_PROCESS_DENOM 16
#define PID_CONTROLLER_BETAFLIGHT 1
#define PID_MIXER_SCALING 1000.0f
#define PID_SERVO_MIXER_SCALING 0.7f