mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
Simplified PID rate counter code (#5350)
This commit is contained in:
parent
33ee5efa17
commit
36c3fdb576
1 changed files with 3 additions and 6 deletions
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue