test(mavsdk_tests): send the arm command directly in the geofence tests

MAVSDK's arm() switches a vehicle in Mission mode to Hold first, where
arming is allowed. The check that Mission mode cannot be armed with a
rejected mission only held while MAVSDK had not seen the mode change
yet. Wait for Mission mode and send the arm command itself.

Also assert that the VTOL is still close to the fence when the margin
is set, so a late margin fails with a reason.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: jonas <jonspero@me.com>
This commit is contained in:
jonas committed 2026-11-20 17:49:41 +01:00
1 parent a33a52607b
commit 3876e8860c
3 files changed
+12 -13

No files matched your search

+8 -11
View File
@@ -8,18 +8,18 @@ import math
import threading
from typing import Any, List, Optional, Tuple
from mavsdk.plugins.action import ActionError # type: ignore
from mavsdk.plugins.telemetry import FlightMode # type: ignore
from autopilot_tester import (
MANUAL_CONTROL_RATE_HZ, MAV_CMD_NAV_WAYPOINT, MAV_FRAME_GLOBAL_INT,
MAV_FRAME_GLOBAL_RELATIVE_ALT, MissionOptions, log, raw_mission_item)
MANUAL_CONTROL_RATE_HZ, MAV_CMD_COMPONENT_ARM_DISARM, MAV_CMD_NAV_WAYPOINT,
MAV_FRAME_GLOBAL_INT, MAV_FRAME_GLOBAL_RELATIVE_ALT, MissionOptions, log, raw_mission_item)
from autopilot_tester_loiter import AutopilotTesterLoiter
from geometry import CoordinateTransformation
MAV_CMD_NAV_VTOL_TAKEOFF = 84
MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION = 5001
MAV_MISSION_TYPE_FENCE = 1
MAV_RESULT_TEMPORARILY_REJECTED = 1
# Values of GF_ACTION and GF_CONT_ACTION.
ACTION_WARNING = 1
@@ -89,14 +89,11 @@ class AutopilotTesterGeofence(AutopilotTesterLoiter):
"""Switch to Mission mode. A disarmed vehicle accepts that even with a rejected mission."""
assert self._try_start_mission(), "Could not switch to Mission mode"
def arming_is_denied(self) -> bool:
"""One arming attempt, without the retries of arm()."""
try:
self._action.arm()
except ActionError as e:
log("Arming denied: {}".format(e))
return True
return False
def check_arming_is_denied(self) -> None:
"""One arming attempt, without the retries of arm(). Sent as a command, because
MAVSDK's arm() first switches a vehicle in Mission mode to Hold."""
self.send_command_long(MAV_CMD_COMPONENT_ARM_DISARM, param1=1.0,
expected_result=MAV_RESULT_TEMPORARILY_REJECTED)
def fly_in_position_mode_until_hold(self, forward: float, throttle: float,
timeout_s: float) -> None:
@@ -107,7 +107,7 @@ def test_contingency_geofence_refuses_arming_missions_and_targets(
tester.set_param_float("GF_CONT_H_MARGIN", 40.0)
tester.sleep_for(2)
assert tester.arming_is_denied(), "Armed within the contingency geofence margin"
tester.check_arming_is_denied()
tester.set_param_float("GF_CONT_H_MARGIN", 10.0)
tester.sleep_for(2)
@@ -116,7 +116,8 @@ def test_contingency_geofence_refuses_arming_missions_and_targets(
# 5 m from the northern edge: the mission is rejected, so Mission mode cannot be armed.
tester.upload_mission_to(25.0, options)
tester.select_mission_mode()
assert tester.arming_is_denied(), "Armed with a mission into the margin"
tester.wait_for_flight_mode(FlightMode.MISSION, 5)
tester.check_arming_is_denied()
# 15 m from the northern edge.
tester.upload_mission_to(15.0, options)
@@ -42,6 +42,7 @@ def test_more_severe_action_wins_after_contingency_geofence_hold(
tester.wait_for_flight_mode(FlightMode.MISSION, 1)
# The vehicle is closer to the fence than the margin that is set now.
assert tester.home_distance_m() < 400.0, "The margin is set too late"
tester.start_tracking()
tester.set_param_float("GF_CONT_H_MARGIN", MARGIN_M)
tester.wait_for_flight_mode(FlightMode.HOLD, 10)