diff --git a/test/mavsdk_tests/autopilot_tester_pusher_failure.py b/test/mavsdk_tests/autopilot_tester_pusher_failure.py index b31fba6ae89..199666ed04c 100644 --- a/test/mavsdk_tests/autopilot_tester_pusher_failure.py +++ b/test/mavsdk_tests/autopilot_tester_pusher_failure.py @@ -99,6 +99,10 @@ class AutopilotTesterPusherFailure(AutopilotTester): self.set_param_float("SIH_WIND_E", wind.from_east_m_s) self.sleep_for(settle_s) + def keep_heading(self) -> None: + """Turn weathervane off, so the nose stays north and the wind a head- or tailwind.""" + self.set_param_int("WV_EN", 0) + def start_multicopter_mission(self, waypoints: List[Tuple[float, float]], altitude_m: float) -> None: """Fly to each (north, east) waypoint relative to home in multicopter mode and land at @@ -177,6 +181,13 @@ class AutopilotTesterPusherFailure(AutopilotTester): return self.wait_for_quadchute( self._pusher_failure_time_s, timeout_s, PUSHER_QUADCHUTE_EVENT) + def start_front_transition(self) -> float: + """Command a front transition, return the time it was commanded once it started.""" + transition_time_s = self.time_s() + self.transition_to_fixedwing() + self.wait_until_transition_started(transition_time_s, 5) + return transition_time_s + def try_transition_to_fixedwing(self) -> None: """Command a front transition once; it may be denied.""" try: diff --git a/test/mavsdk_tests/test_vtol_pusher_failure.py b/test/mavsdk_tests/test_vtol_pusher_failure.py index 22ee26aff7d..15f6f4b2f6c 100644 --- a/test/mavsdk_tests/test_vtol_pusher_failure.py +++ b/test/mavsdk_tests/test_vtol_pusher_failure.py @@ -1,17 +1,20 @@ -"""Pusher failure detection of standard VTOLs with pusher assist (VT_FWD_THRUST_EN). +"""Pusher failure detection of standard VTOLs (VT_EF_TIME, VT_EF_FT_ACC). What the detection must achieve, whatever the detector: -1. A vehicle with a failed pusher never reaches fixed-wing flight. -2. A pusher that fails while the vehicle flies forward with pusher assist in multicopter mode - triggers the pusher failure quad-chute within DETECTION_TIME_S. The vehicle then stays in - multicopter mode and lands. -3. A working pusher triggers no quad-chute. +1. A pusher that failed before or early in a front transition triggers the pusher failure + quad-chute within FT_DETECTION_TIME_S of the transition start, with or without airspeed + sensor. The vehicle never reaches fixed-wing flight and lands in multicopter mode. +2. A pusher that fails while the vehicle flies forward with pusher assist (VT_FWD_THRUST_EN) in + multicopter mode triggers the pusher failure quad-chute within DETECTION_TIME_S. The vehicle + then stays in multicopter mode and lands. +3. A working pusher triggers no quad-chute, in multicopter flight and in front transitions. Accepted, not required: a headwind stronger than the pusher may be reported as a pusher failure, since the vehicle cannot make progress with pusher assist anyway. Known gaps of the VT_EF_* detector: a tailwind that carries the vehicle within VT_EF_VEL_ERR of -its velocity setpoint hides the failure, and a pusher that fails in hover is only detected on the -next pusher-assisted leg or at the start of the next front transition. +its velocity setpoint hides the failure, a pusher that fails in hover is only detected on the +next pusher-assisted leg or at the start of the next front transition, and a pusher that fails +after the transition check passed (about 3.4 s into the transition) is not detected. The detection times are logged, so detectors can be compared with the same flights: test/mavsdk_tests/mavsdk_test_runner.py --speed-factor 10 --model standard_vtol \\ @@ -21,11 +24,16 @@ SIH has constant wind only and a 0.2 kg vehicle, so the flights check behavior, import pytest -from autopilot_tester_pusher_failure import AutopilotTesterPusherFailure, Wind +from autopilot_tester_pusher_failure import (PUSHER_QUADCHUTE_EVENT, + AutopilotTesterPusherFailure, FixedWingReached, + Wind) ALTITUDE_M = 20.0 SETTLE_S = 10.0 DETECTION_TIME_S = 10.0 +# A failed pusher has to stop the front transition before the open-loop transition would complete +# without airspeed (VT_F_TR_OL_TM default). +FT_DETECTION_TIME_S = 6.0 # Front transition backstop, the VT_TRANS_TIMEOUT default. PX4 scales it with air density # (about 16 s at the CI home altitude), which the 5 s margin below covers. TRANSITION_TIMEOUT_S = 15.0 @@ -37,6 +45,7 @@ CROSSWIND = Wind(from_east_m_s=3.0) # Weak enough for pusher assist to still push before the failure, which it does not at 3 m/s. TAILWIND = Wind(from_north_m_s=-1.0) STRONG_WIND = Wind(from_north_m_s=5.0) +FT_TAILWIND = Wind(from_north_m_s=-3.0) @pytest.mark.vtol_pusher_failure @@ -111,12 +120,93 @@ def test_front_transition_with_failed_pusher( tester.fail_pusher() tester.sleep_for(2) - transition_time_s = tester.time_s() - tester.transition_to_fixedwing() - tester.wait_until_transition_started(transition_time_s, 5) + transition_time_s = tester.start_front_transition() tester.sleep_for(1) tester.check_pusher_stopped() - tester.check_never_fixed_wing_since(transition_time_s, TRANSITION_TIMEOUT_S + 5) + check_front_transition_stopped(tester, transition_time_s) - tester.wait_for_quadchute(transition_time_s, TRANSITION_TIMEOUT_S + 5) - tester.wait_until_multicopter(10) + +@pytest.mark.vtol_pusher_failure +@pytest.mark.parametrize("use_airspeed", [True, False], ids=["airspeed", "no_airspeed"]) +def test_pusher_failure_early_in_front_transition( + tester_pusher_failure: AutopilotTesterPusherFailure, use_airspeed: bool) -> None: + """Requirement 1: the pusher stops 0.5 s into a front transition from hover, while it ramps up + to the transition throttle (VT_PSHER_SLEW). Later, the SIH vehicle could already be fast + enough to complete the transition with airspeed.""" + tester = tester_pusher_failure + tester.take_off_with_pusher_assist(ALTITUDE_M, use_airspeed) + + transition_time_s = tester.start_front_transition() + tester.sleep_for(0.5) + tester.fail_pusher() + tester.check_pusher_stopped() + check_front_transition_stopped(tester, transition_time_s) + + +@pytest.mark.vtol_pusher_failure +def test_front_transition_after_pusher_failure_in_cruise( + tester_pusher_failure: AutopilotTesterPusherFailure) -> None: + """Requirement 1: the pusher stops on a pusher-assisted mission leg, and a front transition + is commanded 1 s later, before the multicopter check reports it, while the vehicle still moves + forward.""" + tester = tester_pusher_failure + tester.take_off_with_pusher_assist(ALTITUDE_M) + tester.start_multicopter_mission([(300.0, 0.0)], ALTITUDE_M) + tester.wait_until_north_of(40.0, 60) + tester.check_pusher_pushing() + tester.fail_pusher() + tester.check_pusher_stopped() + tester.sleep_for(1) + + transition_time_s = tester.start_front_transition() + check_front_transition_stopped(tester, transition_time_s) + + +@pytest.mark.vtol_pusher_failure +@pytest.mark.parametrize("use_airspeed,wind", [ + (True, NO_WIND), (False, NO_WIND), (False, STRONG_WIND), (False, FT_TAILWIND), +], ids=["airspeed", "no_airspeed", "no_airspeed_headwind", "no_airspeed_tailwind"]) +def test_front_transition_with_working_pusher( + tester_pusher_failure: AutopilotTesterPusherFailure, use_airspeed: bool, + wind: Wind) -> None: + """Requirement 3: front transitions from hover with the nose north, so the wind is a head- or + tailwind.""" + tester = tester_pusher_failure + tester.take_off_with_pusher_assist(ALTITUDE_M, use_airspeed) + tester.keep_heading() + tester.set_wind(wind, SETTLE_S) + + tester.start_front_transition() + tester.wait_until_fixedwing(TRANSITION_TIMEOUT_S + 5) + tester.sleep_for(5) + tester.check_no_quadchute() + + +@pytest.mark.vtol_pusher_failure +@pytest.mark.xfail( + strict=True, raises=FixedWingReached, + reason="the transition check ends once the pusher accelerated the vehicle, so a later failure " + "completes the open-loop transition (VT_F_TR_OL_TM)") +def test_pusher_failure_late_in_front_transition( + tester_pusher_failure: AutopilotTesterPusherFailure) -> None: + """Known gap: without airspeed, the pusher stops after it accelerated the vehicle, but before + the open-loop transition completes.""" + tester = tester_pusher_failure + tester.take_off_with_pusher_assist(ALTITUDE_M, use_airspeed=False) + + transition_time_s = tester.start_front_transition() + # The check decides 3.4 s into the transition, at the default VT_PSHER_SLEW. + tester.sleep_for(5) + tester.fail_pusher() + tester.check_pusher_stopped() + tester.check_never_fixed_wing_since(transition_time_s, FT_DETECTION_TIME_S + 5) + + +def check_front_transition_stopped(tester: AutopilotTesterPusherFailure, + transition_time_s: float) -> None: + """The pusher failure quad-chute stops the front transition in time, the vehicle never reaches + fixed-wing flight and lands in multicopter mode.""" + tester.wait_for_quadchute(transition_time_s, FT_DETECTION_TIME_S, PUSHER_QUADCHUTE_EVENT) + tester.check_never_fixed_wing_since(transition_time_s, FT_DETECTION_TIME_S + 5) + tester.wait_until_disarmed(240) + tester.check_never_fixed_wing_since(transition_time_s, 0)