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 <noreply@anthropic.com>

* 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.
This commit is contained in:
Balduin authored and GitHub committed 2026-11-06 16:19:32 +01:00
1 parent bf59c29e8b
commit 69df0b9238
3 files changed
+50 -2

No files matched your search

@@ -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);
@@ -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
@@ -157,12 +157,13 @@ void VtolAttitudeControl::vehicle_cmd_poll()
const int transition_command_param1 = static_cast<int>(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;