autotest: add test for Copter compassmot

This commit is contained in:
Peter Barker 2021-10-16 10:17:33 +11:00 committed by Peter Barker
parent 5b69ff6e65
commit 7f61acedd3
1 changed files with 63 additions and 0 deletions

View File

@ -2055,6 +2055,67 @@ class AutoTestCopter(vehicle_test_suite.TestSuite):
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 @@ class AutoTestCopter(vehicle_test_suite.TestSuite):
self.CameraLogMessages,
self.LoiterToGuidedHomeVSOrigin,
self.GuidedModeThrust,
self.CompassMot,
])
return ret
@ -10975,6 +11037,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite):
"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",
}