From 850227ffdb96136bab0a4ee85678a7bd46232980 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 25 Feb 2022 13:23:57 +1100 Subject: [PATCH] autotest: add test for THR_FAILSAFE==2 and throttle output --- Tools/autotest/arduplane.py | 25 +++++++++++++++++++++++-- Tools/autotest/common.py | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Tools/autotest/arduplane.py b/Tools/autotest/arduplane.py index 8a250572ac..2ddc9fa0a5 100644 --- a/Tools/autotest/arduplane.py +++ b/Tools/autotest/arduplane.py @@ -898,7 +898,7 @@ class AutoTestPlane(AutoTest): raise NotAchievedException("Bad absalt (want=%f vs got=%f)" % (original_alt+30, x.alt_msl)) self.fly_home_land_and_disarm() - def test_throttle_failsafe(self): + def ThrottleFailsafe(self): self.change_mode('MANUAL') m = self.mav.recv_match(type='SYS_STATUS', blocking=True) receiver_bit = mavutil.mavlink.MAV_SYS_STATUS_SENSOR_RC_RECEIVER @@ -1021,6 +1021,27 @@ class AutoTestPlane(AutoTest): if ex is not None: raise ex + self.start_subtest("Not use RC throttle input when THR_FAILSAFE==2") + self.takeoff(100) + self.set_rc(3, 1800) + self.set_rc(1, 2000) + self.wait_attitude(desroll=45, timeout=1) + self.context_push() + self.set_parameters({ + "THR_FAILSAFE": 2, + "SIM_RC_FAIL": 1, # no pulses + }) + self.delay_sim_time(1) + self.wait_attitude(desroll=0, timeout=5) + self.assert_servo_channel_value(3, self.get_parameter("RC3_MIN")) + self.set_parameters({ + "SIM_RC_FAIL": 0, # fix receiver + }) + self.zero_throttle() + self.disarm_vehicle() + self.context_pop() + self.reboot_sitl() + def test_throttle_failsafe_fence(self): fence_bit = mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE @@ -3504,7 +3525,7 @@ function''' ("ThrottleFailsafe", "Fly throttle failsafe", - self.test_throttle_failsafe), + self.ThrottleFailsafe), ("NeedEKFToArm", "Ensure we need EKF to be healthy to arm", diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index 358d6b09e9..0e86a51f45 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -5822,6 +5822,21 @@ class AutoTest(ABC): if comparator(m_value, value): return m_value + def assert_servo_channel_value(self, channel, value, comparator=operator.eq): + """assert channel value (default condition is equality)""" + channel_field = "servo%u_raw" % channel + opstring = ("%s" % comparator)[-3:-1] + m = self.assert_receive_message('SERVO_OUTPUT_RAW', timeout=1) + m_value = getattr(m, channel_field, None) + if m_value is None: + raise ValueError("message (%s) has no field %s" % + (str(m), channel_field)) + self.progress("assert SERVO_OUTPUT_RAW.%s=%u %s %u" % + (channel_field, m_value, opstring, value)) + if comparator(m_value, value): + return m_value + raise NotAchievedException("Wrong value") + def get_rc_channel_value(self, channel, timeout=2): """wait for channel to hit value""" channel_field = "chan%u_raw" % channel @@ -5854,6 +5869,16 @@ class AutoTest(ABC): if value == m_value: return + def assert_rc_channel_value(self, channel, value): + channel_field = "chan%u_raw" % channel + + m_value = self.get_rc_channel_value(channel, timeout=1) + self.progress("RC_CHANNELS.%s=%u want=%u" % + (channel_field, m_value, value)) + if value != m_value: + raise NotAchievedException("Expected %s to be %u got %u" % + (channel, value, m_value)) + def wait_location(self, loc, accuracy=5.0,