From 69df0b9238afe7a37afe5031fa49da77dddcce97 Mon Sep 17 00:00:00 2001 From: Balduin Date: Fri, 6 Nov 2026 16:19:32 +0100 Subject: [PATCH] fix(commander): reject Follow Target and Orbit on fixed-wing (#29432) * fix(commander): reject Follow Target and Orbit on fixed-wing Both modes only exist as multicopter flight tasks. Commander runs them with the Trajectory setpoint type and neither auto, manual nor offboard set, so that RC input does not make the flight task exit itself. On fixed-wing that falls through the outer loop: fw_mode_manager ends in FW_POSCTRL_MODE_OTHER and publishes no lateral/longitudinal setpoint, while fw_lateral_longitudinal_control keeps running (the position and altitude flags are set) on the last setpoint it received, with no timeout. The vehicle flies a straight line at the previous mode's course and altitude, or at trim airspeed and wings level on a VTOL that never flew fixed-wing, with no position feedback and all inner loops healthy. Mark both modes as not supported for fixed-wing, so entry is refused and a VTOL transitioning while in one of them falls back to RTL. Follow Target is reachable via DO_SET_MODE without a vehicle type check; Orbit is already mapped to Loiter for fixed-wing, but the transition case applies to it too. Assisted-by: Claude Opus 5 * feat(vtol_att_control): Also disallow transition to FW in Follow target Already done for Orbit, this makes sense also for any other mode that is not supported for FW. commander: Remove comment describing old architecture. --- .../commander/ModeUtil/mode_requirements.cpp | 11 ++++++ .../commander/failsafe/failsafe_test.cpp | 36 +++++++++++++++++++ .../vtol_att_control_main.cpp | 5 +-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/modules/commander/ModeUtil/mode_requirements.cpp b/src/modules/commander/ModeUtil/mode_requirements.cpp index afe39b0a78a..34d2331aee2 100644 --- a/src/modules/commander/ModeUtil/mode_requirements.cpp +++ b/src/modules/commander/ModeUtil/mode_requirements.cpp @@ -210,6 +210,11 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags) setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET, flags.mode_req_prevent_arming); setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET, flags.mode_req_wind_and_flight_time_compliance); + if (vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING) { + // Follow Target is only implemented as a multicopter flight task + setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET, flags.mode_not_supported); + } + // NAVIGATION_STATE_AUTO_PRECLAND setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND, flags.mode_req_angular_velocity); setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND, flags.mode_req_attitude); @@ -225,6 +230,12 @@ void getModeRequirements(uint8_t vehicle_type, failsafe_flags_s &flags) setRequirement(vehicle_status_s::NAVIGATION_STATE_ORBIT, flags.mode_req_prevent_arming); setRequirement(vehicle_status_s::NAVIGATION_STATE_ORBIT, flags.mode_req_wind_and_flight_time_compliance); + if (vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING) { + // Orbit is only implemented as a multicopter flight task. Commander maps DO_ORBIT to Loiter for + // fixed-wing, but a VTOL can still transition to fixed-wing while Orbit is active. + setRequirement(vehicle_status_s::NAVIGATION_STATE_ORBIT, flags.mode_not_supported); + } + // NAVIGATION_STATE_AUTO_VTOL_TAKEOFF setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF, flags.mode_req_angular_velocity); setRequirement(vehicle_status_s::NAVIGATION_STATE_AUTO_VTOL_TAKEOFF, flags.mode_req_attitude); diff --git a/src/modules/commander/failsafe/failsafe_test.cpp b/src/modules/commander/failsafe/failsafe_test.cpp index b37c0529b4e..a84a1dc82cd 100644 --- a/src/modules/commander/failsafe/failsafe_test.cpp +++ b/src/modules/commander/failsafe/failsafe_test.cpp @@ -1060,6 +1060,42 @@ TEST_F(FailsafeTest, RoverUnsupportedDescendToDisarm) ASSERT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Disarm); } +TEST_F(FailsafeTest, FixedWingCannotRunFollowTargetOrOrbit) +{ + // Follow Target and Orbit only exist as multicopter flight tasks, and both clear + // flag_control_auto_enabled. + failsafe_flags_s fw_flags{}; + mode_util::getModeRequirements(vehicle_status_s::VEHICLE_TYPE_FIXED_WING, fw_flags); + EXPECT_TRUE(fw_flags.mode_not_supported & (1u << vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET)); + EXPECT_TRUE(fw_flags.mode_not_supported & (1u << vehicle_status_s::NAVIGATION_STATE_ORBIT)); + + // Both stay available for multicopters, including a VTOL in hover + failsafe_flags_s mc_flags{}; + mode_util::getModeRequirements(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING, mc_flags); + EXPECT_FALSE(mc_flags.mode_not_supported & (1u << vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET)); + EXPECT_FALSE(mc_flags.mode_not_supported & (1u << vehicle_status_s::NAVIGATION_STATE_ORBIT)); + + // A vehicle that ends up in Follow Target as a fixed-wing gets taken out of it + Failsafe failsafe(nullptr); + + FailsafeBase::State state{}; + state.armed = true; + state.vehicle_type = vehicle_status_s::VEHICLE_TYPE_FIXED_WING; + state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET; + hrt_abstime time = 5_s; + + failsafe.update(time, state, false, false, fw_flags); + + // Advance past the COM_FAIL_ACT_T hold delay set in SetUp() + time += 6_s; + const uint8_t updated_user_intended_mode = failsafe.update(time, state, false, false, fw_flags); + + EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::RTL); + // The user intention stays on Follow Target, but the mode actually flown is RTL + EXPECT_EQ(FailsafeBase::modeFromAction(failsafe.selectedAction(), updated_user_intended_mode), + vehicle_status_s::NAVIGATION_STATE_AUTO_RTL); +} + TEST_F(FailsafeTest, GnssLostUsesGnssLossActParam) { // Each param value is exercised on its own fresh Failsafe instance, to avoid diff --git a/src/modules/vtol_att_control/vtol_att_control_main.cpp b/src/modules/vtol_att_control/vtol_att_control_main.cpp index fbc245b3f01..99176b4330c 100644 --- a/src/modules/vtol_att_control/vtol_att_control_main.cpp +++ b/src/modules/vtol_att_control/vtol_att_control_main.cpp @@ -157,12 +157,13 @@ void VtolAttitudeControl::vehicle_cmd_poll() const int transition_command_param1 = static_cast(lround(vehicle_command.param1)); - // deny transition from MC to FW in Takeoff, Land, Return and Orbit + // deny transition from MC to FW in Takeoff, Land, Return, Orbit and Follow Target if (transition_command_param1 == vtol_vehicle_status_s::VEHICLE_VTOL_STATE_FW && (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LAND || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_RTL - || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_ORBIT)) { + || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_ORBIT + || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET)) { result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED;