From 7f61acedd3f973af9d9febfe6d76e71d12ae9cde Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 16 Oct 2021 10:17:33 +1100 Subject: [PATCH] autotest: add test for Copter compassmot --- Tools/autotest/arducopter.py | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 5e82437504395..5a818ea7ef64b 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -2055,6 +2055,67 @@ def ModeCircle(self, holdtime=36): self.do_RTL() + def CompassMot(self): + '''test code that adjust mag field for motor interference''' + self.run_cmd( + mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION, + 0, # p1 + 0, # p2 + 0, # p3 + 0, # p4 + 0, # p5 + 1, # p6 + 0 # p7 + ) + self.context_collect("STATUSTEXT") + self.wait_statustext("Starting calibration", check_context=True) + self.wait_statustext("Current", check_context=True) + rc3_min = self.get_parameter('RC3_MIN') + rc3_max = self.get_parameter('RC3_MAX') + rc3_dz = self.get_parameter('RC3_DZ') + + def set_rc3_for_throttle_pct(thr_pct): + value = int((rc3_min+rc3_dz) + (thr_pct/100.0) * (rc3_max-(rc3_min+rc3_dz))) + self.progress("Setting rc3 to %u" % value) + self.set_rc(3, value) + + throttle_in_pct = 0 + set_rc3_for_throttle_pct(throttle_in_pct) + self.assert_received_message_field_values("COMPASSMOT_STATUS", { + "interference": 0, + "throttle": throttle_in_pct + }, verbose=True, very_verbose=True) + tstart = self.get_sim_time() + delta = 5 + while True: + if self.get_sim_time_cached() - tstart > 60: + raise NotAchievedException("did not run through entire range") + throttle_in_pct += delta + self.progress("Using throttle %f%%" % throttle_in_pct) + set_rc3_for_throttle_pct(throttle_in_pct) + self.wait_message_field_values("COMPASSMOT_STATUS", { + "throttle": throttle_in_pct * 10.0, + }, verbose=True, very_verbose=True, epsilon=1) + if throttle_in_pct == 0: + # finished counting down + break + if throttle_in_pct == 100: + # start counting down + delta = -delta + + m = self.wait_message_field_values("COMPASSMOT_STATUS", { + "throttle": 0, + }, verbose=True) + for axis in "X", "Y", "Z": + fieldname = "Compensation" + axis + if getattr(m, fieldname) <= 0: + raise NotAchievedException("Expected non-zero %s" % fieldname) + + # it's kind of crap - but any command-ack will stop the + # calibration + self.mav.mav.command_ack_send(0, 1) + self.wait_statustext("Calibration successful") + def MagFail(self): '''test failover of compass in EKF''' # we want both EK2 and EK3 @@ -10944,6 +11005,7 @@ def tests2b(self): # this block currently around 9.5mins here self.CameraLogMessages, self.LoiterToGuidedHomeVSOrigin, self.GuidedModeThrust, + self.CompassMot, ]) return ret @@ -10975,6 +11037,7 @@ def disabled_tests(self): "FlyMissionTwice": "See https://github.com/ArduPilot/ardupilot/pull/18561", "GPSForYawCompassLearn": "Vehicle currently crashed in spectacular fashion", "GuidedModeThrust": "land detector raises internal error as we're not saying we're about to take off but just did", + "CompassMot": "Cuases an arithmetic exception in the EKF", }