1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 06:15:16 +03:00

Simplified PID rate counter code (#5350)

This commit is contained in:
Andrey Mironov 2018-03-04 01:48:22 +03:00 committed by Michael Keller
parent 33ee5efa17
commit 36c3fdb576

View file

@ -929,7 +929,7 @@ static void subTaskMotorUpdate(timeUs_t currentTimeUs)
// Function for loop trigger // Function for loop trigger
void taskMainPidLoop(timeUs_t currentTimeUs) void taskMainPidLoop(timeUs_t currentTimeUs)
{ {
static uint8_t pidUpdateCountdown = 0; static uint32_t pidUpdateCounter = 0;
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_GYROPID_SYNC) #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_GYROPID_SYNC)
if (lockMainPID() != 0) return; if (lockMainPID() != 0) return;
@ -937,16 +937,13 @@ void taskMainPidLoop(timeUs_t currentTimeUs)
// DEBUG_PIDLOOP, timings for: // DEBUG_PIDLOOP, timings for:
// 0 - gyroUpdate() // 0 - gyroUpdate()
// 1 - pidController() // 1 - subTaskPidController()
// 2 - subTaskMotorUpdate() // 2 - subTaskMotorUpdate()
// 3 - subTaskMainSubprocesses() // 3 - subTaskMainSubprocesses()
gyroUpdate(currentTimeUs); gyroUpdate(currentTimeUs);
DEBUG_SET(DEBUG_PIDLOOP, 0, micros() - currentTimeUs); DEBUG_SET(DEBUG_PIDLOOP, 0, micros() - currentTimeUs);
if (pidUpdateCountdown) { if (pidUpdateCounter++ % pidConfig()->pid_process_denom == 0) {
pidUpdateCountdown--;
} else {
pidUpdateCountdown = pidConfig()->pid_process_denom - 1;
subTaskPidController(currentTimeUs); subTaskPidController(currentTimeUs);
subTaskMotorUpdate(currentTimeUs); subTaskMotorUpdate(currentTimeUs);
subTaskMainSubprocesses(currentTimeUs); subTaskMainSubprocesses(currentTimeUs);