Skip to content

Commit

Permalink
Merge pull request #10187 from breadoven/abo_coursehold_improvement
Browse files Browse the repository at this point in the history
Nav course hold yaw stick control improvement for fixed wing
  • Loading branch information
breadoven authored Jul 23, 2024
2 parents 4f461a8 + 0b237d1 commit 1594996
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/navigation/navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_COURSE_HOLD_IN_PROGRESS
}

const bool mcRollStickHeadingAdjustmentActive = STATE(MULTIROTOR) && ABS(rcCommand[ROLL]) > rcControlsConfig()->pos_hold_deadband;
static bool adjustmentWasActive = false;

// User demanding yaw -> yaw stick on FW, yaw or roll sticks on MR
// We record the desired course and change the desired target in the meanwhile
Expand All @@ -1353,9 +1354,19 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_COURSE_HOLD_IN_PROGRESS
if (timeDifference > 100) timeDifference = 0; // if adjustment was called long time ago, reset the time difference.
float rateTarget = scaleRangef((float)headingAdjustCommand, -500.0f, 500.0f, -cruiseYawRate, cruiseYawRate);
float centidegsPerIteration = rateTarget * MS2S(timeDifference);
posControl.cruise.course = wrap_36000(posControl.cruise.course - centidegsPerIteration);
DEBUG_SET(DEBUG_CRUISE, 1, CENTIDEGREES_TO_DEGREES(posControl.cruise.course));

if (ABS(wrap_18000(posControl.cruise.course - posControl.actualState.cog)) < fabsf(rateTarget)) {
posControl.cruise.course = wrap_36000(posControl.cruise.course - centidegsPerIteration);
}

posControl.cruise.lastCourseAdjustmentTime = currentTimeMs;
adjustmentWasActive = true;

DEBUG_SET(DEBUG_CRUISE, 1, CENTIDEGREES_TO_DEGREES(posControl.cruise.course));
} else if (STATE(AIRPLANE) && adjustmentWasActive) {
posControl.cruise.course = posControl.actualState.cog - DEGREES_TO_CENTIDEGREES(gyroRateDps(YAW));
resetPositionController();
adjustmentWasActive = false;
} else if (currentTimeMs - posControl.cruise.lastCourseAdjustmentTime > 4000) {
posControl.cruise.previousCourse = posControl.cruise.course;
}
Expand Down

0 comments on commit 1594996

Please sign in to comment.