Skip to content

Commit

Permalink
autotest: add test for Copter compassmot
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Apr 16, 2024
1 parent 5b69ff6 commit 7f61ace
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -10944,6 +11005,7 @@ def tests2b(self): # this block currently around 9.5mins here
self.CameraLogMessages,
self.LoiterToGuidedHomeVSOrigin,
self.GuidedModeThrust,
self.CompassMot,
])
return ret

Expand Down Expand Up @@ -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",
}


Expand Down

0 comments on commit 7f61ace

Please sign in to comment.