diff --git a/test/mavsdk_tests/autopilot_tester_geofence.py b/test/mavsdk_tests/autopilot_tester_geofence.py index a906657fb0a..21f9777750a 100644 --- a/test/mavsdk_tests/autopilot_tester_geofence.py +++ b/test/mavsdk_tests/autopilot_tester_geofence.py @@ -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: diff --git a/test/mavsdk_tests/test_multicopter_contingency_geofence.py b/test/mavsdk_tests/test_multicopter_contingency_geofence.py index d32cab46238..63d53fd2c7a 100644 --- a/test/mavsdk_tests/test_multicopter_contingency_geofence.py +++ b/test/mavsdk_tests/test_multicopter_contingency_geofence.py @@ -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) diff --git a/test/mavsdk_tests/test_vtol_contingency_geofence.py b/test/mavsdk_tests/test_vtol_contingency_geofence.py index 9adb29ee410..62636c04997 100644 --- a/test/mavsdk_tests/test_vtol_contingency_geofence.py +++ b/test/mavsdk_tests/test_vtol_contingency_geofence.py @@ -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)