1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 17:55:30 +03:00

compact the posHoldUpdate() function - thanks K

This commit is contained in:
ctzsnooze 2024-10-18 23:06:39 +11:00
parent 5b2f209074
commit c39b6ab06e
4 changed files with 8 additions and 16 deletions

View file

@ -383,7 +383,7 @@ task_attribute_t task_attributes[TASK_COUNT] = {
#endif
#ifdef USE_POS_HOLD_MODE
[TASK_POSHOLD] = DEFINE_TASK("POSHOLD", NULL, NULL, updatePosHoldState, TASK_PERIOD_HZ(POSHOLD_TASK_RATE_HZ), TASK_PRIORITY_LOW),
[TASK_POSHOLD] = DEFINE_TASK("POSHOLD", NULL, NULL, updatePosHold, TASK_PERIOD_HZ(POSHOLD_TASK_RATE_HZ), TASK_PRIORITY_LOW),
#endif
#ifdef USE_MAG

View file

@ -305,7 +305,7 @@ bool positionControl(bool useStickAdjustment, float deadband) {
} else if (deltaHeading < -180.0f) {
deltaHeading += 360.0f; // Wrap around if less than -180
}
float deltaHeadingRadians = deltaHeading * (M_PIf / 180.0f); // Convert to radians
float deltaHeadingRadians = deltaHeading * RAD; // Convert to radians
float cosDeltaHeading = cos_approx(deltaHeadingRadians);
float sinDeltaHeading = sin_approx(deltaHeadingRadians);

View file

@ -78,23 +78,15 @@ void posHoldUpdateTargetLocation(void)
}
}
void posHoldUpdate(void)
{
posHoldUpdateTargetLocation();
if (getIsNewDataForPosHold() && posHold.posHoldIsOK) {
posHold.posHoldIsOK = positionControl(posHold.useStickAdjustment, posHold.deadband);
}
}
void updatePosHoldState(timeUs_t currentTimeUs) {
void posHoldUpdate(timeUs_t currentTimeUs) {
UNUSED(currentTimeUs);
// check for enabling Alt Hold, otherwise do as little as possible while inactive
posHoldProcessTransitions();
if (posHold.isPosHoldRequested) {
posHoldUpdate();
posHoldUpdateTargetLocation();
if (getIsNewDataForPosHold() && posHold.posHoldIsOK) {
posHold.posHoldIsOK = positionControl(posHold.useStickAdjustment, posHold.deadband);
}
} else {
posHoldAngle[AI_PITCH] = 0.0f;
posHoldAngle[AI_ROLL] = 0.0f;

View file

@ -34,7 +34,7 @@ typedef struct {
} posHoldState_t;
void posHoldInit(void);
void updatePosHoldState(timeUs_t currentTimeUs);
void updatePosHold(timeUs_t currentTimeUs);
bool showPosHoldWarning(void);
bool allowPosHoldWithoutMag(void);