From 91436c531423800ecfbc784af587f7662c5fe76c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 6 Mar 2019 17:37:26 +1100 Subject: [PATCH] Tools: autotest: add test for high-throttle-at-mode-change --- Tools/autotest/arducopter.py | 21 +++++++++++++++++++++ Tools/autotest/common.py | 34 ++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 4ba800d9aa..9837bfeb6a 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -2362,6 +2362,23 @@ class AutoTestCopter(AutoTest): if ex is not None: raise ex + def fly_manual_throttle_mode_change(self): + self.set_parameter("FS_GCS_ENABLE", 0) # avoid GUIDED instant disarm + self.change_mode("STABILIZE") + self.wait_ready_to_arm() + self.arm_vehicle() + self.change_mode("ACRO") + self.change_mode("STABILIZE") + self.change_mode("GUIDED") + self.set_rc(3, 1700) + self.watch_altitude_maintained(-1, 0.2) # should not take off in guided + self.run_cmd_do_set_mode( + "ACRO", + want_result=mavutil.mavlink.MAV_RESULT_UNSUPPORTED) # should fix this result code! + self.set_rc(3, 1000) + self.run_cmd_do_set_mode("ACRO") + self.mav.motors_disarmed_wait() + def test_mount_pitch(self, despitch, despitch_tolerance, timeout=5): tstart = self.get_sim_time() while True: @@ -2953,6 +2970,10 @@ class AutoTestCopter(AutoTest): "Test Arming Parameter Checks", self.test_parameter_checks), + ("ManualThrottleModeChange", + "Check manual throttle mode changes denied on high throttle", + self.fly_manual_throttle_mode_change), + ("LogDownLoad", "Log download", lambda: self.log_download( diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index 4ed1e6763a..9fbac3477d 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -1157,30 +1157,40 @@ class AutoTest(ABC): self.progress("Available modes '%s'" % mode_map) raise ErrorException("Unknown mode '%s'" % mode) - def do_set_mode_via_command_long(self, mode, timeout=30): - """Set mode with a command long message.""" + def run_cmd_do_set_mode(self, + mode, + timeout=30, + want_result=mavutil.mavlink.MAV_RESULT_ACCEPTED): base_mode = mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED custom_mode = self.get_mode_from_mode_mapping(mode) + self.run_cmd(mavutil.mavlink.MAV_CMD_DO_SET_MODE, + base_mode, + custom_mode, + 0, + 0, + 0, + 0, + 0, + want_result=want_result, + timeout=timeout + ) + + def do_set_mode_via_command_long(self, mode, timeout=30): + """Set mode with a command long message.""" tstart = self.get_sim_time() + want_custom_mode = self.get_mode_from_mode_mapping(mode) while True: remaining = timeout - (self.get_sim_time_cached() - tstart) if remaining <= 0: raise AutoTestTimeoutException("Failed to change mode") - self.run_cmd(mavutil.mavlink.MAV_CMD_DO_SET_MODE, - base_mode, - custom_mode, - 0, - 0, - 0, - 0, - 0, - ) + self.run_cmd_do_set_mode(mode, timeout=10) m = self.mav.recv_match(type='HEARTBEAT', blocking=True, timeout=5) if m is None: raise ErrorException("Heartbeat not received") - if m.custom_mode == custom_mode: + self.progress("Got mode=%u want=%u" % (m.custom_mode, want_custom_mode)) + if m.custom_mode == want_custom_mode: return def mavproxy_do_set_mode_via_command_long(self, mode, timeout=30):