test(mavsdk_tests): new 1 m/s tailwind test that does not trigger quadchute

This commit is contained in:
jonas committed 2026-11-20 11:28:42 +01:00
1 parent 114c19cd31
commit 7fe789300a
2 files changed
+47 -33

No files matched your search

@@ -1,7 +1,7 @@
"""AutopilotTester for the pusher failure detection of the SIH standard VTOL with pusher assist.
The pusher is stopped with an undetected motor failure (`failure motor wrong`): its output is cut,
but it stays in the control allocation and no motor failure is reported, like a pusher without
but it stays in the control allocation and no motor failure is reported, as with a pusher without
ESC telemetry. The checks only use what the vehicle reports (quad-chute events, VTOL state,
outputs), not how a failure is detected, so any detector can be measured with the same flights.
"""
@@ -21,14 +21,14 @@ from autopilot_tester import (MAV_CMD_NAV_LAND, MAV_CMD_NAV_WAYPOINT,
# The pusher is motor 5 (1-based failure instance) on output channel 8.
PUSHER_MOTOR_INSTANCE = 5
PUSHER_OUTPUT_INDEX = 7
# Outputs are 1000 + 1000 * throttle, a stopped or unused pusher reads 900.
# Outputs are 1000 + 1000 * throttle; a stopped or unused pusher reads 900.
PUSHER_PUSHING_OUTPUT = 1100.0
PUSHER_STOPPED_OUTPUT = 901.0
QUADCHUTE_EVENT_PREFIX = "vtol_att_ctrl_quadchute"
PUSHER_QUADCHUTE_EVENT = "vtol_att_ctrl_quadchute_fwd_prop"
# The VTOL state is sampled, fast enough not to miss a short fixed-wing phase.
# Sample the VTOL state fast enough not to miss a short fixed-wing phase.
VTOL_STATE_RATE_HZ = 10.0
@@ -36,6 +36,10 @@ class FixedWingReached(AssertionError):
pass
class QuadchuteMissing(AssertionError):
pass
@dataclass
class Wind:
"""Constant SIH wind. SIH_WIND_N and SIH_WIND_E are the speeds of the wind blowing from north
@@ -75,7 +79,7 @@ class AutopilotTesterPusherFailure(AutopilotTester):
self.set_param_int("SYS_FAILURE_EN", 1)
# The control allocation only applies injected motor stops with a failure mode set.
self.set_param_int("CA_FAILURE_MODE", 1)
# Airspeed-less setup (vtol_without_airspeed_sensor.md), the sensor stays installed.
# Airspeed-less setup as in vtol_without_airspeed_sensor.md; the sensor stays installed.
self.set_param_int("FW_USE_AIRSPD", 1 if use_airspeed else 0)
self.enable_actuator_output_status()
self._telemetry.set_rate_vtol_state(VTOL_STATE_RATE_HZ)
@@ -124,7 +128,7 @@ class AutopilotTesterPusherFailure(AutopilotTester):
return float(self._telemetry.actuator_output_status().actuator[PUSHER_OUTPUT_INDEX])
def check_pusher_pushing(self) -> None:
"""Precondition of the flights with a working pusher, otherwise they test nothing."""
"""Check that pusher assist is pushing, otherwise the flight tests nothing."""
output = self._pusher_output()
assert output >= PUSHER_PUSHING_OUTPUT, \
"Pusher output {:.0f}, expected pusher assist to push".format(output)
@@ -149,9 +153,10 @@ class AutopilotTesterPusherFailure(AutopilotTester):
def wait_for_quadchute(self, since_s: float, timeout_s: float,
expected_event: Optional[str] = None) -> float:
"""Wait for the first quad-chute after since_s, return its delay."""
assert self.poll_condition_with_timeout(
lambda: bool(self._quadchutes_since(since_s)), timeout_s), \
"No quad-chute within {} s".format(timeout_s)
received = self.poll_condition_with_timeout(
lambda: bool(self._quadchutes_since(since_s)), timeout_s)
if not received:
raise QuadchuteMissing("No quad-chute within {} s".format(timeout_s))
quadchute = self._quadchutes_since(since_s)[0]
if expected_event is not None:
@@ -160,21 +165,20 @@ class AutopilotTesterPusherFailure(AutopilotTester):
delay_s = quadchute.time_s - since_s
log("Quad-chute {} after {:.1f} s".format(quadchute.event_name, delay_s))
assert delay_s <= timeout_s, "Quad-chute after {:.1f} s, expected within {} s".format(
delay_s, timeout_s)
if delay_s > timeout_s:
raise QuadchuteMissing("Quad-chute after {:.1f} s, expected within {} s".format(
delay_s, timeout_s))
return delay_s
def wait_for_pusher_quadchute(self, timeout_s: float) -> float:
"""Wait for the pusher failure quad-chute after fail_pusher(), return the detection
time."""
assert self._pusher_failure_time_s is not None, "fail_pusher() was not called"
detection_time_s = self.wait_for_quadchute(
return self.wait_for_quadchute(
self._pusher_failure_time_s, timeout_s, PUSHER_QUADCHUTE_EVENT)
log("Detection time: {:.1f} s".format(detection_time_s))
return detection_time_s
def try_transition_to_fixedwing(self) -> None:
"""Command a front transition once, it may be denied."""
"""Command a front transition once; it may be denied."""
try:
self.transition_to_fixedwing()
except ActionError as e:
@@ -199,7 +203,7 @@ class AutopilotTesterPusherFailure(AutopilotTester):
"No front transition started within {} s".format(timeout_s)
def check_never_fixed_wing_since(self, since_s: float, duration_s: float) -> None:
"""Watch the VTOL state for duration_s more."""
"""Fail if fixed-wing mode is reached between since_s and duration_s from now."""
self.sleep_for(duration_s)
if VtolState.FW in self._vtol_states_since(since_s):
raise FixedWingReached("Fixed-wing mode reached")
+28 -18
View File
@@ -1,47 +1,55 @@
"""Pusher failure detection of standard VTOLs with pusher assist (VT_FWD_THRUST_EN).
What the detection must achieve, whatever the detector:
1. A failed pusher never brings the vehicle into fixed-wing flight.
2. A pusher that fails while pusher assist flies the vehicle forward in multicopter mode triggers
the pusher failure quad-chute within DETECTION_TIME_S. The vehicle then stays in multicopter
mode and lands.
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.
Accepted, not required: a headwind stronger than the pusher may be reported as a pusher failure,
the vehicle cannot make progress with pusher assist either way.
Known gaps of the current detector: a tailwind that keeps the vehicle moving hides the failure,
and a pusher that fails in hover is only noticed by the front transition checks.
since the vehicle cannot make progress with pusher assist anyway.
Known gaps of the VT_EF_* detector: a tailwind that keeps the vehicle moving hides the failure
(tailwind case), and a pusher that fails in hover is only detected on the next pusher-assisted
leg; a front transition before that is only aborted when airspeed is used (no_airspeed case).
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 \\
--case '*pusher*' test/mavsdk_tests/configs/sih-sitl.json
SIH has constant wind only and a 0.2 kg vehicle, so the flights check behaviour, not tuning.
SIH has constant wind only and a 0.2 kg vehicle, so the flights check behavior, not tuning.
"""
import pytest
from autopilot_tester import log
from autopilot_tester_pusher_failure import (PUSHER_QUADCHUTE_EVENT,
AutopilotTesterPusherFailure, FixedWingReached,
Wind)
QuadchuteMissing, Wind)
ALTITUDE_M = 20.0
SETTLE_S = 10.0
DETECTION_TIME_S = 10.0
# Backstop of the front transition, VT_TRANS_TIMEOUT
# 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
# SIH pusher assist makes progress against 7 m/s of headwind and drifts back at 8 m/s.
NO_WIND = Wind()
HEADWIND = Wind(from_north_m_s=3.0)
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)
TOO_STRONG_WIND = Wind(from_north_m_s=8.0)
@pytest.mark.vtol_pusher_failure
@pytest.mark.parametrize("wind", [NO_WIND, HEADWIND, CROSSWIND],
ids=["no_wind", "headwind", "crosswind"])
@pytest.mark.parametrize("wind", [
NO_WIND, HEADWIND, CROSSWIND,
pytest.param(TAILWIND, marks=pytest.mark.xfail(
strict=True, raises=QuadchuteMissing,
reason="without the pusher the vehicle drifts at the wind speed, above "
"VT_EF_V_THRESH")),
], ids=["no_wind", "headwind", "crosswind", "tailwind"])
def test_pusher_failure_in_multicopter_cruise(
tester_pusher_failure: AutopilotTesterPusherFailure, wind: Wind) -> None:
"""Requirement 2: the pusher stops on a mission leg flown north."""
@@ -56,6 +64,8 @@ def test_pusher_failure_in_multicopter_cruise(
tester.check_pusher_stopped()
tester.wait_for_pusher_quadchute(DETECTION_TIME_S)
# Right away, during the failsafe hold (COM_FAIL_ACT_T): Return rejects front transitions
# outright, which would test nothing.
tester.try_transition_to_fixedwing()
tester.wait_until_disarmed(240)
tester.check_only_multicopter_since(failure_time_s)
@@ -65,8 +75,9 @@ def test_pusher_failure_in_multicopter_cruise(
@pytest.mark.parametrize("wind", [NO_WIND, STRONG_WIND], ids=["no_wind", "strong_wind"])
def test_working_pusher_in_multicopter_mission(
tester_pusher_failure: AutopilotTesterPusherFailure, wind: Wind) -> None:
"""Requirement 3: legs into, across and with the wind. The waypoints command a north
heading, so with the wind the pusher idles."""
"""Requirement 3: legs into, across and with the wind (strong_wind case). The waypoints
keep the nose north, as weathervane (WV_EN, on for VTOLs) would in this wind, so the
vehicle flies the downwind leg tail first and the pusher idles."""
tester = tester_pusher_failure
tester.request_ground_truth()
tester.take_off_with_pusher_assist(ALTITUDE_M)
@@ -118,7 +129,7 @@ def test_headwind_stronger_than_pusher(
True,
pytest.param(False, marks=pytest.mark.xfail(
strict=True, raises=FixedWingReached,
reason="no pusher check in front transitions yet, the open loop transition "
reason="no pusher check in front transitions yet: the open-loop transition "
"(VT_F_TR_OL_TM) completes")),
], ids=["airspeed", "no_airspeed"])
def test_front_transition_with_failed_pusher(
@@ -136,6 +147,5 @@ def test_front_transition_with_failed_pusher(
tester.check_pusher_stopped()
tester.check_never_fixed_wing_since(transition_time_s, TRANSITION_TIMEOUT_S + 5)
abort_time_s = tester.wait_for_quadchute(transition_time_s, TRANSITION_TIMEOUT_S + 5)
log("Front transition aborted after {:.1f} s".format(abort_time_s))
tester.wait_for_quadchute(transition_time_s, TRANSITION_TIMEOUT_S + 5)
tester.wait_until_multicopter(10)