mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Fixed checking of PID loop timing.
This commit is contained in:
parent
41df8adbdb
commit
79f0e6dd1f
1 changed files with 12 additions and 10 deletions
|
@ -535,7 +535,7 @@ void validateAndFixGyroConfig(void)
|
||||||
float motorUpdateRestriction;
|
float motorUpdateRestriction;
|
||||||
switch (motorConfig()->dev.motorPwmProtocol) {
|
switch (motorConfig()->dev.motorPwmProtocol) {
|
||||||
case (PWM_TYPE_STANDARD):
|
case (PWM_TYPE_STANDARD):
|
||||||
motorUpdateRestriction = 1.0f/BRUSHLESS_MOTORS_PWM_RATE;
|
motorUpdateRestriction = 1.0f / BRUSHLESS_MOTORS_PWM_RATE;
|
||||||
break;
|
break;
|
||||||
case (PWM_TYPE_ONESHOT125):
|
case (PWM_TYPE_ONESHOT125):
|
||||||
motorUpdateRestriction = 0.0005f;
|
motorUpdateRestriction = 0.0005f;
|
||||||
|
@ -555,17 +555,19 @@ void validateAndFixGyroConfig(void)
|
||||||
motorUpdateRestriction = 0.00003125f;
|
motorUpdateRestriction = 0.00003125f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pidLooptime < motorUpdateRestriction) {
|
if (!motorConfig()->dev.useUnsyncedPwm) {
|
||||||
const uint8_t maxPidProcessDenom = constrain(motorUpdateRestriction / (samplingTime * gyroConfig()->gyro_sync_denom), 1, MAX_PID_PROCESS_DENOM);
|
if (pidLooptime < motorUpdateRestriction) {
|
||||||
pidConfigMutable()->pid_process_denom = MIN(pidConfigMutable()->pid_process_denom, maxPidProcessDenom);
|
const uint8_t minPidProcessDenom = constrain(motorUpdateRestriction / (samplingTime * gyroConfig()->gyro_sync_denom), 1, MAX_PID_PROCESS_DENOM);
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent overriding the max rate of motors
|
pidConfigMutable()->pid_process_denom = MAX(pidConfigMutable()->pid_process_denom, minPidProcessDenom);
|
||||||
if (motorConfig()->dev.useUnsyncedPwm && (motorConfig()->dev.motorPwmProtocol <= PWM_TYPE_BRUSHED) && motorConfig()->dev.motorPwmProtocol != PWM_TYPE_STANDARD) {
|
}
|
||||||
uint32_t maxEscRate = lrintf(1.0f / motorUpdateRestriction);
|
} else {
|
||||||
|
// Prevent overriding the max rate of motors
|
||||||
|
if ((motorConfig()->dev.motorPwmProtocol <= PWM_TYPE_BRUSHED) && (motorConfig()->dev.motorPwmProtocol != PWM_TYPE_STANDARD)) {
|
||||||
|
const uint32_t maxEscRate = lrintf(1.0f / motorUpdateRestriction);
|
||||||
|
|
||||||
if (motorConfig()->dev.motorPwmRate > maxEscRate)
|
motorConfigMutable()->dev.motorPwmRate = MIN(motorConfig()->dev.motorPwmRate, maxEscRate);
|
||||||
motorConfigMutable()->dev.motorPwmRate = maxEscRate;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue