From 0bd9610687064a6c0357fae4fc7830b9c06c010c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 3 Jun 2021 13:54:20 +1000 Subject: [PATCH] autotest: add trivial test for BodyFrameOdom --- Tools/autotest/arducopter.py | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 3535210635..c3baa6fd95 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -2505,6 +2505,65 @@ class AutoTestCopter(AutoTest): if ex is not None: raise ex + def fly_body_frame_odom(self): + """Disable GPS navigation, enable input of VISION_POSITION_DELTA.""" + + if self.get_parameter("AHRS_EKF_TYPE") != 3: + # only tested on this EKF + return + + self.customise_SITL_commandline(["--uartF=sim:vicon:"]) + + if self.current_onboard_log_contains_message("XKFD"): + raise NotAchievedException("Found unexpected XKFD message") + + # scribble down a location we can set origin to: + self.progress("Waiting for location") + self.change_mode('LOITER') + self.wait_ready_to_arm() + + old_pos = self.mav.recv_match(type='GLOBAL_POSITION_INT', blocking=True) + print("old_pos=%s" % str(old_pos)) + + # configure EKF to use external nav instead of GPS + self.set_parameters({ + "EK3_SRC1_POSXY": 6, + "EK3_SRC1_VELXY": 6, + "EK3_SRC1_POSZ": 6, + "EK3_SRC1_VELZ": 6, + "GPS_TYPE": 0, + "VISO_TYPE": 1, + "SERIAL5_PROTOCOL": 1, + "SIM_VICON_TMASK": 8, # send VISION_POSITION_DELTA + }) + self.reboot_sitl() + # without a GPS or some sort of external prompting, AP + # doesn't send system_time messages. So prompt it: + self.mav.mav.system_time_send(int(time.time() * 1000000), 0) + self.progress("Waiting for non-zero-lat") + tstart = self.get_sim_time() + while True: + self.mav.mav.set_gps_global_origin_send(1, + old_pos.lat, + old_pos.lon, + old_pos.alt) + gpi = self.mav.recv_match(type='GLOBAL_POSITION_INT', + blocking=True) + self.progress("gpi=%s" % str(gpi)) + if gpi.lat != 0: + break + + if self.get_sim_time_cached() - tstart > 60: + raise AutoTestTimeoutException("Did not get non-zero lat") + + self.takeoff(alt_min=5, mode='ALT_HOLD', require_absolute=False, takeoff_throttle=1800) + self.change_mode('LAND') + # TODO: something more elaborate here - EKF will only aid + # relative position + self.wait_disarmed() + if not self.current_onboard_log_contains_message("XKFD"): + raise NotAchievedException("Did not find expected XKFD message") + def fly_gps_vicon_switching(self): """Fly GPS and Vicon switching test""" self.customise_SITL_commandline(["--uartF=sim:vicon:"]) @@ -7009,6 +7068,10 @@ class AutoTestCopter(AutoTest): "Fly Vision Position", self.fly_vision_position), # 24s + ("BodyFrameOdom", + "Fly Body Frame Odometry Code", + self.fly_body_frame_odom), # 24s + ("GPSViconSwitching", "Fly GPS and Vicon Switching", self.fly_gps_vicon_switching),