From 6ddc2373347b854bfc40243d0db0248839013519 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 30 Apr 2024 15:22:59 +1000 Subject: [PATCH] autotest: add test that weights for blending work --- Tools/autotest/arducopter.py | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 0d5dc4caec..4cc8dad879 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -8889,6 +8889,75 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.context_pop() self.reboot_sitl() + def GPSWeightedBlending(self): + '''Test GPS Weighted Blending''' + + self.context_push() + + # configure: + self.set_parameters({ + "WP_YAW_BEHAVIOR": 0, # do not yaw + "GPS2_TYPE": 1, + "SIM_GPS2_TYPE": 1, + "SIM_GPS2_DISABLE": 0, + "SIM_GPS_POS_X": 1.0, + "SIM_GPS_POS_Y": -1.0, + "SIM_GPS2_POS_X": -1.0, + "SIM_GPS2_POS_Y": 1.0, + "GPS_AUTO_SWITCH": 2, + }) + # configure velocity errors such that the 1st GPS should be + # 4/5, second GPS 1/5 of result (0.5**2)/((0.5**2)+(1.0**2)) + self.set_parameters({ + "SIM_GPS_VERR_X": 0.3, # m/s + "SIM_GPS_VERR_Y": 0.4, + "SIM_GPS2_VERR_X": 0.6, # m/s + "SIM_GPS2_VERR_Y": 0.8, + "GPS_BLEND_MASK": 4, # use only speed for blend calculations + }) + self.reboot_sitl() + + alt = 10 + self.takeoff(alt, mode='GUIDED') + self.fly_guided_move_local(30, 0, alt) + self.fly_guided_move_local(30, 30, alt) + self.fly_guided_move_local(0, 30, alt) + self.fly_guided_move_local(0, 0, alt) + self.change_mode('LAND') + + current_log_file = self.dfreader_for_current_onboard_log() + + self.wait_disarmed() + + # ensure that the blended solution is always about half-way + # between the two GPSs: + current_ts = None + while True: + m = current_log_file.recv_match(type='GPS') + if m is None: + break + if current_ts is None: + if m.I != 0: # noqa + continue + current_ts = m.TimeUS + measurements = {} + if m.TimeUS != current_ts: + current_ts = None + continue + measurements[m.I] = (m.Lat, m.Lng) + if len(measurements) == 3: + # check lat: + for n in 0, 1: + expected_blended = 0.8*measurements[0][n] + 0.2*measurements[1][n] + epsilon = 0.0000002 + error = abs(measurements[2][n] - expected_blended) + if error > epsilon: + raise NotAchievedException(f"Blended diverged {measurements[0][n]=} {measurements[1][n]=}") + current_ts = None + + self.context_pop() + self.reboot_sitl() + def Callisto(self): '''Test Callisto''' self.customise_SITL_commandline( @@ -11152,6 +11221,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.RTL_TO_RALLY, self.FlyEachFrame, self.GPSBlending, + self.GPSWeightedBlending, self.GPSBlendingLog, self.DataFlash, Test(self.DataFlashErase, attempts=8),