From 91c7b4a990324b36200450833f0759a0c2bb5c47 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 21 Mar 2024 12:08:30 +1100 Subject: [PATCH] autotest: add new blending test --- Tools/autotest/arducopter.py | 64 +++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index db14505e85e89c..1515e12d29796d 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -8752,7 +8752,7 @@ def test_replay_optical_flow_bit(self): print("log difference: %s" % str(log_difference)) return log_difference[0] - def GPSBlending(self): + def GPSBlendingLog(self): '''Test GPS Blending''' '''ensure we get dataflash log messages for blended instance''' @@ -8827,6 +8827,67 @@ def GPSBlending(self): if ex is not None: raise ex + def GPSBlending(self): + '''Test GPS Blending''' + '''ensure we get dataflash log messages for blended instance''' + + 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, + }) + 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 = (measurements[0][n] + measurements[1][n])/2 + epsilon = 0.0000002 + error = abs(measurements[2][n] - expected_blended) + if error > epsilon: + raise NotAchievedException("Blended diverged") + current_ts = None + + self.context_pop() + self.reboot_sitl() + def Callisto(self): '''Test Callisto''' self.customise_SITL_commandline( @@ -10936,6 +10997,7 @@ def tests2b(self): # this block currently around 9.5mins here self.RTL_TO_RALLY, self.FlyEachFrame, self.GPSBlending, + self.GPSBlendingLog, self.DataFlash, Test(self.DataFlashErase, attempts=8), self.Callisto,