1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

Enable Faster cycletimes (Sample Rates) on all targets // More automatic looptime calculations

cleanup
This commit is contained in:
borisbstyle 2016-02-24 16:36:12 +01:00
parent 981bddf182
commit f5de06c59e
12 changed files with 72 additions and 25 deletions

View file

@ -106,14 +106,24 @@ void setGyroSamplingSpeed(uint16_t looptime) {
uint16_t gyroSampleRate = 1000;
uint8_t maxDivider = 1;
if (looptime != targetLooptime) {
if (looptime != targetLooptime || looptime == 0) {
if (looptime == 0) looptime = targetLooptime; // needed for pid controller changes
#ifdef STM32F303xC
if (looptime < 1000) {
masterConfig.gyro_lpf = 0;
gyroSampleRate = 125;
maxDivider = 8;
if (looptime < 250) {
masterConfig.acc_hardware = 1;
masterConfig.baro_hardware = 1;
masterConfig.mag_hardware = 1;
masterConfig.pid_process_denom = 2;
} else if (looptime < 1000) {
masterConfig.pid_process_denom = 1;
}
} else {
masterConfig.gyro_lpf = 1;
masterConfig.pid_process_denom = 1;
}
#else
if (looptime < 1000) {
@ -123,11 +133,27 @@ void setGyroSamplingSpeed(uint16_t looptime) {
masterConfig.mag_hardware = 1;
gyroSampleRate = 125;
maxDivider = 8;
if (looptime < 250) {
masterConfig.pid_process_denom = 3;
} else if (looptime < 500) {
if (currentProfile->pidProfile.pidController == 2) {
masterConfig.pid_process_denom = 3;
} else {
masterConfig.pid_process_denom = 2;
}
} else {
if (currentProfile->pidProfile.pidController == 2) {
masterConfig.pid_process_denom = 2;
} else {
masterConfig.pid_process_denom = 1;
}
}
} else {
masterConfig.gyro_lpf = 1;
masterConfig.acc_hardware = 0;
masterConfig.baro_hardware = 0;
masterConfig.mag_hardware = 0;
masterConfig.pid_process_denom = 1;
}
#endif
masterConfig.gyro_sync_denom = constrain(looptime / gyroSampleRate, 1, maxDivider);
@ -1236,6 +1262,7 @@ static bool processInCommand(void)
uint32_t i;
uint16_t tmp;
uint8_t rate;
uint8_t oldPid;
#ifdef GPS
uint8_t wp_no;
int32_t lat = 0, lon = 0, alt = 0;
@ -1283,8 +1310,10 @@ static bool processInCommand(void)
setGyroSamplingSpeed(read16());
break;
case MSP_SET_PID_CONTROLLER:
oldPid = currentProfile->pidProfile.pidController;
currentProfile->pidProfile.pidController = read8();
pidSetController(currentProfile->pidProfile.pidController);
if (oldPid != currentProfile->pidProfile.pidController) setGyroSamplingSpeed(0); // recalculate looptimes for new PID
break;
case MSP_SET_PID:
if (IS_PID_CONTROLLER_FP_BASED(currentProfile->pidProfile.pidController)) {