From 89f81c0f2ab354bf3890d29d3698c7e68f89ee6b Mon Sep 17 00:00:00 2001 From: Balduin Date: Wed, 12 Aug 2026 16:57:26 +0200 Subject: [PATCH] fix(FlightTaskManualAltitude): reset terrain hold state on activation 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. --- .../tasks/ManualAltitude/FlightTaskManualAltitude.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/flight_mode_manager/tasks/ManualAltitude/FlightTaskManualAltitude.cpp b/src/modules/flight_mode_manager/tasks/ManualAltitude/FlightTaskManualAltitude.cpp index a8bce62b5d3..9ac095ab8c9 100644 --- a/src/modules/flight_mode_manager/tasks/ManualAltitude/FlightTaskManualAltitude.cpp +++ b/src/modules/flight_mode_manager/tasks/ManualAltitude/FlightTaskManualAltitude.cpp @@ -64,6 +64,8 @@ bool FlightTaskManualAltitude::activate(const trajectory_setpoint_s &last_setpoi _acceleration_setpoint = Vector3f(0.f, 0.f, NAN); // altitude is controlled from position/velocity _position_setpoint(2) = _position(2); _velocity_setpoint(2) = 0.f; + _terrain_hold = false; + _dist_to_ground_lock = NAN; _stick_yaw.reset(_yaw, _unaided_yaw); _setDefaultConstraints();