autotest: add a test for EK3_RNG_USE_HGT

This commit is contained in:
Peter Barker 2022-11-23 13:20:08 +11:00 committed by Andrew Tridgell
parent bcabaf0e74
commit 65e8f153a3
1 changed files with 57 additions and 0 deletions

View File

@ -2404,6 +2404,62 @@ class AutoTestCopter(AutoTest):
raise NotAchievedException("AUTOTUNE failed (%u seconds)" %
(self.get_sim_time() - tstart))
def EK3_RNG_USE_HGT(self):
'''basic tests for using rangefinder when speed and height below thresholds'''
# this takes advantage of some code in send_status_report
# which only reports terrain variance when using switch-height
# and using the rangefinder
self.context_push()
self.set_analog_rangefinder_parameters()
# set use-height to 20m (the parameter is a percentage of max range)
self.set_parameters({
'EK3_RNG_USE_HGT': 200000 / self.get_parameter('RNGFND1_MAX_CM'),
})
self.reboot_sitl()
# add a listener that verifies rangefinder innovations look good
alt = None
def verify_innov(mav, m):
global alt
if m.get_type() == 'GLOBAL_POSITION_INT':
alt = m.relative_alt * 0.001 # mm -> m
return
if m.get_type() != 'EKF_STATUS_REPORT':
return
if alt > 1 and alt < 8: # 8 is very low, but it takes a long time to start to use the rangefinder again
zero_variance_wanted = False
elif alt > 20:
zero_variance_wanted = True
else:
return
variance = m.terrain_alt_variance
if zero_variance_wanted and variance != 0:
raise NotAchievedException("Wanted zero variance at height %f, got %f" % (alt, variance))
elif not zero_variance_wanted and variance == 0:
raise NotAchievedException("Wanted non-zero variance at alt=%f, got zero" % alt)
self.install_message_hook_context(verify_innov)
self.takeoff(50, mode='GUIDED')
current_alt = self.mav.location().alt
target_position = mavutil.location(
-35.362938,
149.165185,
current_alt,
0
)
self.fly_guided_move_to(target_position, timeout=300)
self.change_mode('LAND')
self.wait_disarmed()
self.context_pop()
self.reboot_sitl()
def CopterMission(self):
'''fly mission which tests a significant number of commands'''
# Fly mission #1
@ -9230,6 +9286,7 @@ class AutoTestCopter(AutoTest):
self.WatchAlts,
self.GuidedEKFLaneChange,
self.Sprayer,
self.EK3_RNG_USE_HGT
])
return ret