From 779ec879e83d83c1ec64658e54240e2be4536c08 Mon Sep 17 00:00:00 2001 From: Roberto Rubinacci Date: Mon, 17 Aug 2026 22:52:41 +0200 Subject: [PATCH] fix(flight_mode_manager): return to a waypoint that was not reached --- .../flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp | 11 +++++++++++ .../flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp | 1 + 2 files changed, 12 insertions(+) diff --git a/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp b/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp index d9e3410fc89..9bd8b488068 100644 --- a/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp +++ b/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp @@ -182,6 +182,11 @@ bool FlightTaskAuto::update() _checkEmergencyBraking(); Vector3f waypoints[] = {_triplet_previous, _position_setpoint, _triplet_next}; + if (_type == WaypointType::position && _hasPassedCurrentWaypoint()) { + // Anchor the leg at the current position to not extrapolate past an unreached waypoint + waypoints[0] = _position; + } + if (isTargetModified()) { // In case the target has been modified, we take this as the next waypoints waypoints[2] = _position_setpoint; @@ -761,6 +766,12 @@ bool FlightTaskAuto::isTargetModified() const return xy_modified || z_modified; } +bool FlightTaskAuto::_hasPassedCurrentWaypoint() const +{ + const Vector2f u_previous_to_current = Vector2f(_triplet_current - _triplet_previous).unit_or_zero(); + return u_previous_to_current * Vector2f(_triplet_current - _position) < 0.f; +} + void FlightTaskAuto::_updateTrajConstraints() { // update params of the position smoothing diff --git a/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp b/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp index f8747b09758..46a54c467fb 100644 --- a/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp +++ b/src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp @@ -195,5 +195,6 @@ private: bool _evaluatePositionSetpointTriplet(); bool _isFinite(const position_setpoint_s &sp); /**< Checks if all waypoint triplets are finite. */ bool _evaluateGlobalReference(); /**< Check is global reference is available. */ + bool _hasPassedCurrentWaypoint() const; /**< True if the vehicle is horizontally past the current waypoint */ void _set_heading_from_mode(); /**< @see MPC_YAW_MODE */ };