-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Enable Fixed Wing Auto Speed During Waypoint Mission #11757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
breadoven
wants to merge
2
commits into
iNavFlight:maintenance-10.x
Choose a base branch
from
breadoven:abo_wpmode_fw_autospeed
base: maintenance-10.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−27
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,8 @@ static float throttleSpeedAdjustment = 0; | |
| static bool isAutoThrottleManuallyIncreased = false; | ||
| static float navCrossTrackError; | ||
| static int8_t loiterDirYaw = 1; | ||
| bool needToCalculateCircularLoiter; | ||
| static bool needToCalculateCircularLoiter; | ||
| static bool autoSpeedIsActive = false; | ||
|
|
||
| // Calculates the cutoff frequency for smoothing out roll/pitch commands | ||
| // control_smoothness valid range from 0 to 9 | ||
|
|
@@ -887,18 +888,38 @@ void applyFixedWingEmergencyLandingController(timeUs_t currentTimeUs) | |
| * Auto Speed mode control | ||
| *-----------------------------------------------------------*/ | ||
| bool isFixedwingAutoSpeedActive(void) | ||
| { | ||
| return autoSpeedIsActive; | ||
| } | ||
|
Comment on lines
890
to
+893
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Stale autospeed active flag isFixedwingAutoSpeedActive() now returns a cached flag that is only updated inside applyAutoSpeedThrottleDemand(), but fixed-wing throttle logic checks isFixedwingAutoSpeedActive() earlier in the same navigation loop. When Auto Speed becomes disabled, the fixed-wing controller can incorrectly skip its normal throttle path for one cycle, leaving rcCommand[THROTTLE] without the expected nav throttle control for that iteration. Agent Prompt
|
||
|
|
||
| static int8_t isAutoSpeedRequiredByNav(void) | ||
| { | ||
| int8_t result = -1; | ||
| if (FLIGHT_MODE(NAV_WP_MODE) && getActiveSpeed() > 0) { | ||
| result = FW_AUTO_SPD_GROUND; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| static bool isAutoSpeedEnabled(void) | ||
| { | ||
| bool thrStickEmergStop = navConfig()->fw.auto_speed_channel != (THROTTLE + 1) && throttleStickIsLow(); | ||
| bool autoSpeedRequested = IS_RC_MODE_ACTIVE(BOXAUTOSPEED) || isAutoSpeedRequiredByNav() >= 0; | ||
|
|
||
| return STATE(AIRPLANE) && ARMING_FLAG(ARMED) && IS_RC_MODE_ACTIVE(BOXAUTOSPEED) && isProbablyStillFlying() && !thrStickEmergStop && | ||
| !FLIGHT_MODE(FAILSAFE_MODE) && !FLIGHT_MODE(SOARING_MODE) && !FLIGHT_MODE(MANUAL_MODE) && | ||
| posControl.flags.estVelStatus == EST_TRUSTED && posControl.flags.estAltStatus == EST_TRUSTED && | ||
| !(navigationRequiresAutoThrottleMode() && !(navGetCurrentStateFlags() & NAV_CTL_SPEED)); | ||
| return ARMING_FLAG(ARMED) && autoSpeedRequested && isProbablyStillFlying() && !thrStickEmergStop && | ||
| !FLIGHT_MODE(FAILSAFE_MODE) && !FLIGHT_MODE(SOARING_MODE) && !FLIGHT_MODE(MANUAL_MODE) && | ||
| posControl.flags.estVelStatus == EST_TRUSTED && posControl.flags.estAltStatus == EST_TRUSTED && | ||
| !(navigationRequiresAutoThrottleMode() && !(navGetCurrentStateFlags() & NAV_CTL_SPEED)); | ||
| } | ||
|
|
||
| void applyAutoSpeedThrottleDemand(int16_t *throttleCommand, timeUs_t currentTimeUs) | ||
| { | ||
| if (!isFixedwingAutoSpeedActive()) return; | ||
| if (!STATE(AIRPLANE) || !isAutoSpeedEnabled()) { | ||
| autoSpeedIsActive = false; | ||
| return; | ||
| } | ||
| autoSpeedIsActive = true; | ||
|
|
||
| static uint16_t autoSpeedThrottleCommand = PWM_RANGE_MIDDLE; | ||
|
|
||
|
|
@@ -918,16 +939,24 @@ void applyAutoSpeedThrottleDemand(int16_t *throttleCommand, timeUs_t currentTime | |
| uint16_t minThrottle = MAX(getThrottleIdleValue(), currentBatteryProfile->nav.fw.min_throttle); | ||
| uint16_t maxThrottle = currentBatteryProfile->nav.fw.max_throttle; | ||
|
|
||
| posControl.desiredState.autoSpeedDemand = scaleRange(rxGetChannelValue(navConfig()->fw.auto_speed_channel - 1), PWM_RANGE_MIN, PWM_RANGE_MAX, minSpeed, maxSpeed); | ||
| bool useAirSpeed = !LOGIC_CONDITION_GLOBAL_FLAG(LOGIC_CONDITION_GLOBAL_FLAG_DISABLE_AUTOSPEED_AIRSPEED); | ||
| if (IS_RC_MODE_ACTIVE(BOXAUTOSPEED)) { | ||
| posControl.desiredState.autoSpeedDemand = scaleRange(rxGetChannelValue(navConfig()->fw.auto_speed_channel - 1), PWM_RANGE_MIN, PWM_RANGE_MAX, minSpeed, maxSpeed); | ||
| } else { | ||
| posControl.desiredState.autoSpeedDemand = constrain(getActiveSpeed(), minSpeed, maxSpeed); | ||
| useAirSpeed = isAutoSpeedRequiredByNav() == FW_AUTO_SPD_AIR; | ||
| } | ||
|
|
||
| uint16_t actualSpeed = posControl.actualState.vel3D; | ||
| posControl.autoSpeedSpdSource = FW_AUTO_SPD_GROUND; | ||
| uint16_t groundSpeedBoost = 0; | ||
|
|
||
| #ifdef USE_PITOT | ||
| if (pitotValidateAirspeed()) { | ||
| static bool airspeedBoost = false; | ||
|
|
||
| // Pitot available and airspeed source selected or low airspeed boost applied when using ground speed source | ||
| if (!LOGIC_CONDITION_GLOBAL_FLAG(LOGIC_CONDITION_GLOBAL_FLAG_DISABLE_AUTOSPEED_AIRSPEED) || airspeedBoost) { | ||
| if (useAirSpeed || airspeedBoost) { | ||
| actualSpeed = getAirspeedEstimate(); | ||
| if (airspeedBoost && actualSpeed > minSpeed) { | ||
| airspeedBoost = false; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.