Skip to content

Commit

Permalink
Fix default PID DENOM (betaflight#12509)
Browse files Browse the repository at this point in the history
* Set default PID DENOM

* Fixes after Karate review

* Fixes after Karate review v2

* Use gyro.sampleRateHz

* Fixes after discussion
  • Loading branch information
haslinghuis authored and davidbitton committed Feb 5, 2024
1 parent cfa483b commit f55fb2d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,19 @@ void validateAndFixGyroConfig(void)
// check for looptime restrictions based on motor protocol. Motor times have safety margin
float motorUpdateRestriction;

#if defined(STM32F4) || defined(STM32G4)
#if defined(USE_DSHOT) && defined(USE_PID_DENOM_CHECK)
/* If bidirectional DSHOT is being used on an F4 or G4 then force DSHOT300. The motor update restrictions then applied
* will automatically consider the loop time and adjust pid_process_denom appropriately
*/
if (motorConfig()->dev.useDshotTelemetry && (motorConfig()->dev.motorPwmProtocol == PWM_TYPE_DSHOT600)) {
motorConfigMutable()->dev.motorPwmProtocol = PWM_TYPE_DSHOT300;
if (motorConfig()->dev.useDshotTelemetry) {
if (motorConfig()->dev.motorPwmProtocol == PWM_TYPE_DSHOT600) {
motorConfigMutable()->dev.motorPwmProtocol = PWM_TYPE_DSHOT300;
}
if (gyro.sampleRateHz > 4000) {
pidConfigMutable()->pid_process_denom = 2;
}
}
#endif

#endif // USE_DSHOT && USE_PID_DENOM_CHECK
switch (motorConfig()->dev.motorPwmProtocol) {
case PWM_TYPE_STANDARD:
motorUpdateRestriction = 1.0f / BRUSHLESS_MOTORS_PWM_RATE;
Expand Down
6 changes: 1 addition & 5 deletions src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ pt1Filter_t throttleLpf;

PG_REGISTER_WITH_RESET_TEMPLATE(pidConfig_t, pidConfig, PG_PID_CONFIG, 3);

#if !defined(DEFAULT_PID_PROCESS_DENOM)
#if defined(STM32F411xE)
#define DEFAULT_PID_PROCESS_DENOM 2
#else
#ifndef DEFAULT_PID_PROCESS_DENOM
#define DEFAULT_PID_PROCESS_DENOM 1
#endif
#endif

#ifdef USE_RUNAWAY_TAKEOFF
PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
Expand Down
2 changes: 2 additions & 0 deletions src/main/target/STM32F405/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@

#define USE_EXTI

#define USE_PID_DENOM_CHECK

#define FLASH_PAGE_SIZE ((uint32_t)0x4000) // 16K sectors
2 changes: 2 additions & 0 deletions src/main/target/STM32F411/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@

#define USE_EXTI

#define USE_PID_DENOM_CHECK

#define FLASH_PAGE_SIZE ((uint32_t)0x4000) // 16K sectors
4 changes: 4 additions & 0 deletions src/main/target/STM32G47X/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@
#define USE_ESCSERIAL

#define USE_ADC

#define USE_EXTI

#define USE_PID_DENOM_CHECK

#define USE_TIMER_UP_CONFIG

0 comments on commit f55fb2d

Please sign in to comment.