fix(flight_mode_manager): return to a waypoint that was not reached

This commit is contained in:
Roberto Rubinacci authored and Matthias Grob committed 2026-08-27 19:32:43 +02:00
1 parent 639e983df4
commit 779ec879e8
2 files changed
+12

No files matched your search

@@ -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
@@ -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 */
};