1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Merge pull request #9544 from etracer65/simplify_pid_motor_pwm_validation

Simplify and improve motor protocol PID loop limiting
This commit is contained in:
Michael Keller 2020-03-07 15:56:22 +13:00 committed by GitHub
commit a67df68f2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -582,19 +582,8 @@ void validateAndFixGyroConfig(void)
}
#endif
float samplingTime;
switch (gyroMpuDetectionResult()->sensor) {
case ICM_20649_SPI:
samplingTime = 1.0f / 9000.0f;
break;
case BMI_160_SPI:
samplingTime = 0.0003125f;
break;
default:
samplingTime = 0.000125f;
break;
}
if (gyro.sampleRateHz > 0) {
float samplingTime = 1.0f / gyro.sampleRateHz;
// check for looptime restrictions based on motor protocol. Motor times have safety margin
float motorUpdateRestriction;
@ -630,10 +619,16 @@ void validateAndFixGyroConfig(void)
} else {
const float pidLooptime = samplingTime * pidConfig()->pid_process_denom;
if (pidLooptime < motorUpdateRestriction) {
const uint8_t minPidProcessDenom = constrain(motorUpdateRestriction / samplingTime, 1, MAX_PID_PROCESS_DENOM);
uint8_t minPidProcessDenom = motorUpdateRestriction / samplingTime;
if (motorUpdateRestriction / samplingTime > minPidProcessDenom) {
// if any fractional part then round up
minPidProcessDenom++;
}
minPidProcessDenom = constrain(minPidProcessDenom, 1, MAX_PID_PROCESS_DENOM);
pidConfigMutable()->pid_process_denom = MAX(pidConfigMutable()->pid_process_denom, minPidProcessDenom);
}
}
}
#ifdef USE_GYRO_DATA_ANALYSE
// Disable dynamic filter if gyro loop is less than 2KHz