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;