Skip to content

Commit

Permalink
Simplified PID rate counter code (betaflight#5350)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieHertz authored and mikeller committed Mar 3, 2018
1 parent 33ee5ef commit 36c3fdb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,24 +929,21 @@ static void subTaskMotorUpdate(timeUs_t currentTimeUs)
// Function for loop trigger
void taskMainPidLoop(timeUs_t currentTimeUs)
{
static uint8_t pidUpdateCountdown = 0;
static uint32_t pidUpdateCounter = 0;

#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_GYROPID_SYNC)
if (lockMainPID() != 0) return;
#endif

// DEBUG_PIDLOOP, timings for:
// 0 - gyroUpdate()
// 1 - pidController()
// 1 - subTaskPidController()
// 2 - subTaskMotorUpdate()
// 3 - subTaskMainSubprocesses()
gyroUpdate(currentTimeUs);
DEBUG_SET(DEBUG_PIDLOOP, 0, micros() - currentTimeUs);

if (pidUpdateCountdown) {
pidUpdateCountdown--;
} else {
pidUpdateCountdown = pidConfig()->pid_process_denom - 1;
if (pidUpdateCounter++ % pidConfig()->pid_process_denom == 0) {
subTaskPidController(currentTimeUs);
subTaskMotorUpdate(currentTimeUs);
subTaskMainSubprocesses(currentTimeUs);
Expand Down

0 comments on commit 36c3fdb

Please sign in to comment.