mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Rationalise taskMainPidLoop
This commit is contained in:
parent
9f0206b4e2
commit
62862c3388
1 changed files with 13 additions and 20 deletions
|
@ -648,7 +648,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)
|
||||||
|
@ -676,7 +676,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)
|
||||||
|
@ -691,32 +691,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--;
|
||||||
|
@ -724,7 +711,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,6 +724,7 @@ bool isMotorsReversed(void)
|
||||||
{
|
{
|
||||||
return reverseMotors;
|
return reverseMotors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFlipOverAfterCrashMode(void)
|
bool isFlipOverAfterCrashMode(void)
|
||||||
{
|
{
|
||||||
return flipOverAfterCrashMode;
|
return flipOverAfterCrashMode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue