mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +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:
commit
a67df68f2c
1 changed files with 41 additions and 46 deletions
|
@ -582,19 +582,8 @@ void validateAndFixGyroConfig(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float samplingTime;
|
if (gyro.sampleRateHz > 0) {
|
||||||
switch (gyroMpuDetectionResult()->sensor) {
|
float samplingTime = 1.0f / gyro.sampleRateHz;
|
||||||
case ICM_20649_SPI:
|
|
||||||
samplingTime = 1.0f / 9000.0f;
|
|
||||||
break;
|
|
||||||
case BMI_160_SPI:
|
|
||||||
samplingTime = 0.0003125f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
samplingTime = 0.000125f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// check for looptime restrictions based on motor protocol. Motor times have safety margin
|
// check for looptime restrictions based on motor protocol. Motor times have safety margin
|
||||||
float motorUpdateRestriction;
|
float motorUpdateRestriction;
|
||||||
|
@ -630,10 +619,16 @@ void validateAndFixGyroConfig(void)
|
||||||
} else {
|
} else {
|
||||||
const float pidLooptime = samplingTime * pidConfig()->pid_process_denom;
|
const float pidLooptime = samplingTime * pidConfig()->pid_process_denom;
|
||||||
if (pidLooptime < motorUpdateRestriction) {
|
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);
|
pidConfigMutable()->pid_process_denom = MAX(pidConfigMutable()->pid_process_denom, minPidProcessDenom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_GYRO_DATA_ANALYSE
|
#ifdef USE_GYRO_DATA_ANALYSE
|
||||||
// Disable dynamic filter if gyro loop is less than 2KHz
|
// Disable dynamic filter if gyro loop is less than 2KHz
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue