Skip to content

Commit

Permalink
Set default PID DENOM
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Mar 11, 2023
1 parent 50de917 commit 16ff09c
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,32 @@ FAST_DATA_ZERO_INIT float throttleBoost;
pt1Filter_t throttleLpf;
#endif

PG_REGISTER_WITH_RESET_TEMPLATE(pidConfig_t, pidConfig, PG_PID_CONFIG, 3);
PG_REGISTER_WITH_RESET_FN(pidConfig_t, pidConfig, PG_PID_CONFIG, 4);

void pgResetFn_pidConfig(pidConfig_t *pidConfig)
{
unsigned denom = 1;
#if defined(STM32F411xE)
#define PID_PROCESS_DENOM_DEFAULT 2
#else
#define PID_PROCESS_DENOM_DEFAULT 1
bool found = false;
for (unsigned pos = 0; pos < 7; pos++) {
if (gyroConfig()->gyrosDetected & BIT(pos)) {
found = true;
break;
}
}
if (found) {
if (gyro.gyroSensor1.gyroDev.gyroHardware != GYRO_BMI160 || gyro.gyroSensor1.gyroDev.gyroHardware != GYRO_BMI270) {
denom = 2;
}
}
#endif

pidConfig->pid_process_denom = denom;
#ifdef USE_RUNAWAY_TAKEOFF
PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
.pid_process_denom = PID_PROCESS_DENOM_DEFAULT,
.runaway_takeoff_prevention = true,
.runaway_takeoff_deactivate_throttle = 20, // throttle level % needed to accumulate deactivation time
.runaway_takeoff_deactivate_delay = 500, // Accumulated time (in milliseconds) before deactivation in successful takeoff
);
#else
PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
.pid_process_denom = PID_PROCESS_DENOM_DEFAULT,
);
pidConfig->runaway_takeoff_prevention = true;
pidConfig->runaway_takeoff_deactivate_throttle = 20; // throttle level % needed to accumulate deactivation time
pidConfig->runaway_takeoff_deactivate_delay = 500; // Accumulated time (in milliseconds) before deactivation in successful takeoff
#endif
}

#ifdef USE_ACRO_TRAINER
#define ACRO_TRAINER_LOOKAHEAD_RATE_LIMIT 500.0f // Max gyro rate for lookahead time scaling
Expand Down

0 comments on commit 16ff09c

Please sign in to comment.