mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 09:45:37 +03:00
compact the posHoldUpdate() function - thanks K
This commit is contained in:
parent
5b2f209074
commit
c39b6ab06e
4 changed files with 8 additions and 16 deletions
|
@ -383,7 +383,7 @@ task_attribute_t task_attributes[TASK_COUNT] = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POS_HOLD_MODE
|
#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
|
#endif
|
||||||
|
|
||||||
#ifdef USE_MAG
|
#ifdef USE_MAG
|
||||||
|
|
|
@ -305,7 +305,7 @@ bool positionControl(bool useStickAdjustment, float deadband) {
|
||||||
} else if (deltaHeading < -180.0f) {
|
} else if (deltaHeading < -180.0f) {
|
||||||
deltaHeading += 360.0f; // Wrap around if less than -180
|
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 cosDeltaHeading = cos_approx(deltaHeadingRadians);
|
||||||
float sinDeltaHeading = sin_approx(deltaHeadingRadians);
|
float sinDeltaHeading = sin_approx(deltaHeadingRadians);
|
||||||
|
|
|
@ -78,23 +78,15 @@ void posHoldUpdateTargetLocation(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void posHoldUpdate(void)
|
void posHoldUpdate(timeUs_t currentTimeUs) {
|
||||||
{
|
|
||||||
posHoldUpdateTargetLocation();
|
|
||||||
|
|
||||||
if (getIsNewDataForPosHold() && posHold.posHoldIsOK) {
|
|
||||||
posHold.posHoldIsOK = positionControl(posHold.useStickAdjustment, posHold.deadband);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void updatePosHoldState(timeUs_t currentTimeUs) {
|
|
||||||
UNUSED(currentTimeUs);
|
UNUSED(currentTimeUs);
|
||||||
|
|
||||||
// check for enabling Alt Hold, otherwise do as little as possible while inactive
|
// check for enabling Alt Hold, otherwise do as little as possible while inactive
|
||||||
posHoldProcessTransitions();
|
posHoldProcessTransitions();
|
||||||
|
|
||||||
if (posHold.isPosHoldRequested) {
|
if (posHold.isPosHoldRequested) {
|
||||||
posHoldUpdate();
|
posHoldUpdateTargetLocation();
|
||||||
|
if (getIsNewDataForPosHold() && posHold.posHoldIsOK) {
|
||||||
|
posHold.posHoldIsOK = positionControl(posHold.useStickAdjustment, posHold.deadband);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
posHoldAngle[AI_PITCH] = 0.0f;
|
posHoldAngle[AI_PITCH] = 0.0f;
|
||||||
posHoldAngle[AI_ROLL] = 0.0f;
|
posHoldAngle[AI_ROLL] = 0.0f;
|
||||||
|
|
|
@ -34,7 +34,7 @@ typedef struct {
|
||||||
} posHoldState_t;
|
} posHoldState_t;
|
||||||
|
|
||||||
void posHoldInit(void);
|
void posHoldInit(void);
|
||||||
void updatePosHoldState(timeUs_t currentTimeUs);
|
void updatePosHold(timeUs_t currentTimeUs);
|
||||||
|
|
||||||
bool showPosHoldWarning(void);
|
bool showPosHoldWarning(void);
|
||||||
bool allowPosHoldWithoutMag(void);
|
bool allowPosHoldWithoutMag(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue