mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 22:05:17 +03:00
Merge pull request #4205 from martinbudden/bf_task_mainpidloop
Rationalise taskMainPidLoop
This commit is contained in:
commit
edea16f17e
1 changed files with 12 additions and 20 deletions
|
@ -656,7 +656,7 @@ static void subTaskMainSubprocesses(timeUs_t currentTimeUs)
|
||||||
#ifdef TRANSPONDER
|
#ifdef TRANSPONDER
|
||||||
transponderUpdate(currentTimeUs);
|
transponderUpdate(currentTimeUs);
|
||||||
#endif
|
#endif
|
||||||
DEBUG_SET(DEBUG_PIDLOOP, 2, micros() - startTime);
|
DEBUG_SET(DEBUG_PIDLOOP, 3, micros() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subTaskMotorUpdate(void)
|
static void subTaskMotorUpdate(void)
|
||||||
|
@ -684,7 +684,7 @@ static void subTaskMotorUpdate(void)
|
||||||
|
|
||||||
writeMotors();
|
writeMotors();
|
||||||
|
|
||||||
DEBUG_SET(DEBUG_PIDLOOP, 3, micros() - startTime);
|
DEBUG_SET(DEBUG_PIDLOOP, 2, micros() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t setPidUpdateCountDown(void)
|
uint8_t setPidUpdateCountDown(void)
|
||||||
|
@ -699,32 +699,19 @@ uint8_t setPidUpdateCountDown(void)
|
||||||
// Function for loop trigger
|
// Function for loop trigger
|
||||||
void taskMainPidLoop(timeUs_t currentTimeUs)
|
void taskMainPidLoop(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
static bool runTaskMainSubprocesses;
|
static uint8_t pidUpdateCountdown = 0;
|
||||||
static uint8_t pidUpdateCountdown;
|
|
||||||
|
|
||||||
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_GYROPID_SYNC)
|
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_GYROPID_SYNC)
|
||||||
if (lockMainPID() != 0) return;
|
if (lockMainPID() != 0) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (debugMode == DEBUG_CYCLETIME) {
|
|
||||||
debug[0] = getTaskDeltaTime(TASK_SELF);
|
|
||||||
debug[1] = averageSystemLoadPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (runTaskMainSubprocesses) {
|
|
||||||
subTaskMainSubprocesses(currentTimeUs);
|
|
||||||
runTaskMainSubprocesses = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEBUG_PIDLOOP, timings for:
|
// DEBUG_PIDLOOP, timings for:
|
||||||
// 0 - gyroUpdate()
|
// 0 - gyroUpdate()
|
||||||
// 1 - pidController()
|
// 1 - pidController()
|
||||||
// 2 - subTaskMainSubprocesses()
|
// 2 - subTaskMotorUpdate()
|
||||||
// 3 - subTaskMotorUpdate()
|
// 3 - subTaskMainSubprocesses()
|
||||||
uint32_t startTime = 0;
|
|
||||||
if (debugMode == DEBUG_PIDLOOP) {startTime = micros();}
|
|
||||||
gyroUpdate();
|
gyroUpdate();
|
||||||
DEBUG_SET(DEBUG_PIDLOOP, 0, micros() - startTime);
|
DEBUG_SET(DEBUG_PIDLOOP, 0, micros() - currentTimeUs);
|
||||||
|
|
||||||
if (pidUpdateCountdown) {
|
if (pidUpdateCountdown) {
|
||||||
pidUpdateCountdown--;
|
pidUpdateCountdown--;
|
||||||
|
@ -732,7 +719,12 @@ void taskMainPidLoop(timeUs_t currentTimeUs)
|
||||||
pidUpdateCountdown = setPidUpdateCountDown();
|
pidUpdateCountdown = setPidUpdateCountDown();
|
||||||
subTaskPidController(currentTimeUs);
|
subTaskPidController(currentTimeUs);
|
||||||
subTaskMotorUpdate();
|
subTaskMotorUpdate();
|
||||||
runTaskMainSubprocesses = true;
|
subTaskMainSubprocesses(currentTimeUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debugMode == DEBUG_CYCLETIME) {
|
||||||
|
debug[0] = getTaskDeltaTime(TASK_SELF);
|
||||||
|
debug[1] = averageSystemLoadPercent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue