From c1a20ceab4e3b10a9e603434b8e7410f1014e789 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 27 May 2021 17:29:03 +1000 Subject: [PATCH] autotest: add test to catch bug with opticalflow if no rangefinder --- Tools/autotest/arducopter.py | 38 ++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index c243402863..2c2ce1c848 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -1867,6 +1867,31 @@ class AutoTestCopter(AutoTest): if ex is not None: raise ex + def configure_EKFs_to_use_optical_flow_instead_of_GPS(self): + '''configure EKF to use optical flow instead of GPS''' + ahrs_ekf_type = self.get_parameter("AHRS_EKF_TYPE") + if ahrs_ekf_type == 2: + self.set_parameter("EK2_GPS_TYPE", 3) + if ahrs_ekf_type == 3: + self.set_parameters({ + "EK3_SRC1_POSXY": 0, + "EK3_SRC1_VELXY": 5, + "EK3_SRC1_VELZ": 0, + }) + + def optical_flow(self): + '''test optical low works''' + self.start_subtest("Make sure no crash if no rangefinder") + self.set_parameter("SIM_FLOW_ENABLE", 1) + self.set_parameter("FLOW_TYPE", 10) + + self.configure_EKFs_to_use_optical_flow_instead_of_GPS() + + self.reboot_sitl() + self.change_mode('LOITER') + self.delay_sim_time(5) + self.wait_statustext("Need Position Estimate", timeout=300) + # fly_optical_flow_limits - test EKF navigation limiting def fly_optical_flow_limits(self): ex = None @@ -1876,14 +1901,7 @@ class AutoTestCopter(AutoTest): self.set_parameter("SIM_FLOW_ENABLE", 1) self.set_parameter("FLOW_TYPE", 10) - # configure EKF to use optical flow instead of GPS - ahrs_ekf_type = self.get_parameter("AHRS_EKF_TYPE") - if ahrs_ekf_type == 2: - self.set_parameter("EK2_GPS_TYPE", 3) - if ahrs_ekf_type == 3: - self.set_parameter("EK3_SRC1_POSXY", 0) - self.set_parameter("EK3_SRC1_VELXY", 5) - self.set_parameter("EK3_SRC1_VELZ", 0) + self.configure_EKFs_to_use_optical_flow_instead_of_GPS() self.set_analog_rangefinder_parameters() @@ -6860,6 +6878,10 @@ class AutoTestCopter(AutoTest): "Test magnetometer failure", self.test_mag_fail), + ("OpticalFlow", + "Test Optical Flow", + self.optical_flow), + ("OpticalFlowLimits", "Fly Optical Flow limits", self.fly_optical_flow_limits), # 27s