FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(FlightTaskManualAltitude): Always invalidate stored distance when exiting terrain hold by mbjd · Pull Request #28231 · PX4/PX4-Autopilot · GitHub

fix(FlightTaskManualAltitude): Always invalidate stored distance when exiting terrain hold - #28231

Merged
mbjd merged 2 commits into
mainfrom
pr-fix-altitude-lock
Aug 31, 2026
Merged

mbjd merged 2 commits into
mainfrom
pr-fix-altitude-lock

Conversation

mbjd commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

When terrain hold disengages due to horizontal stick input, _dist_to_ground_lock currently keeps its last value. If terrain hold then re-engages while the altitude sp is NaN (vertical velocity control) the vehicle flies back to the old height above ground.

Solution

Always invalidate _dist_to_ground_lock when exiting terrain hold.

Related fix (claude found when reviewing the first): 10584a9 - reset terrain hold state in activate() to avoid flying to completely stale altitudes after switching to external mode and back. Can put in separate PR if preferred.

Testing

Reproduce the failure / verify the fix:

  • make px4_sitl gz_x500_lidar_down with default params, particularly MPC_ALT_MODE=2
  • Take off in position mode, hover at low altitude to lock
  • Give horizontal stick input to disengage terrain hold
  • Give throttle up to ascend
  • Stop giving horizontal stick input
  • Release throttle at higher altitude

Result before: Vehicle descends down to initial altitude

Result after: Vehicle stays at altitude where throttle was released + braking distance

Changelog Entry

For release notes:

Fix: Always invalidate stored distance when exiting terrain hold to avoid flying to stale altitude

mbjd added 2 commits August 12, 2026 17:00
… when stopping terrain hold

When terrain hold disengages due to horizontal stick input,
_dist_to_ground_lock currently keeps its last value. If terrain hold
then re-engages while the altitude sp is NaN (vertical velocity control)
the vehicle would fly to the old height above ground.

Fix: Always invalidate the lock when stopping terrain hold.

Reproduce the failure / verify the fix:
 - make px4_sitl gz_x500_lidar_down with default params
     - particularly: MPC_ALT_MODE 2
 - Take off in position mode, hover at low altitude to lock
 - Give horizontal stick input to disengage terrain hold
 - Give throttle up to ascend
 - Stop giving horizontal stick input
 - Release throttle at higher altitude

Result before: Vehicle descends down to initial altitude
Result after: Vehicle stays at altitude where throttle was released +
braking distance
Flight tasks are statically allocated, so _terrain_hold and
_dist_to_ground_lock survive switching to another mode and back. On
reactivation with sticks centered and a valid distance to ground,
terrain following would resume on the old lock and command the height
above ground from before the mode switch, however long ago and far
away that was. Since no disengage or re-engage transition runs in
between, invalidating the lock on those transitions cannot cover this
path. Start every activation with terrain hold off and no lock; the
regular engage logic then re-latches at the current height above
ground when the conditions are met.
github-actions Bot added the kind:bug Something is broken or behaving incorrectly. label Aug 12, 2026
mbjd requested review from bresch and haumarco August 12, 2026 15:09
github-actions Bot added the scope:control Rate, attitude, position, allocation, or actuator control. label Aug 12, 2026

Copy link
Copy Markdown
Contributor

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 8 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
     +14%     +12   +14%     +12    FlightTaskManualAltitude::activate()
    -0.6%      -4  -0.6%      -4    FlightTaskManualAltitude::_updateAltitudeLock()
  +0.0%     +57  [ = ]       0    .debug_abbrev
  -0.0%     -25  [ = ]       0    .debug_line
    +250%      +5  [ = ]       0    [Unmapped]
    -0.0%     -30  [ = ]       0    [section .debug_line]
  -0.0%     -19  [ = ]       0    .debug_loclists
  -0.0%     -17  [ = ]       0    .debug_rnglists
    [DEL]      -3  [ = ]       0    [Unmapped]
    -0.0%     -14  [ = ]       0    [section .debug_rnglists]
  -0.1%      -8  [ = ]       0    [Unmapped]
  -0.0%      -4  +0.0%      +8    TOTAL

px4_fmu-v6x [Total VM Diff: 0 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +57  [ = ]       0    .debug_abbrev
  -0.0%     -33  [ = ]       0    .debug_line
   -75.0%      -3  [ = ]       0    [Unmapped]
    -0.0%     -30  [ = ]       0    [section .debug_line]
  -0.0%     -19  [ = ]       0    .debug_loclists
  -0.0%     -13  [ = ]       0    .debug_rnglists
    +100%      +1  [ = ]       0    [Unmapped]
    -0.0%     -14  [ = ]       0    [section .debug_rnglists]
  -0.0%      -8  [ = ]       0    TOTAL

Updated: 2026-08-12T15:16:24

dakejahl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There are a lot of issues with rangefinder fusion and state logic. If you want to jump down the rabbit hole let me know 😅

mbjd merged commit 89f81c0 into main Aug 31, 2026
79 checks passed
mbjd deleted the pr-fix-altitude-lock branch August 31, 2026 09:19
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug Something is broken or behaving incorrectly. scope:control Rate, attitude, position, allocation, or actuator control.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL