From 0abeca15e2f8928592c2556668a5b67309b83ec7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Nov 2022 10:07:43 +1100 Subject: [PATCH] autotest: added scripting aerobatics test --- Tools/autotest/arduplane.py | 79 +++++++++++++++++++++++++++++++++++++ Tools/autotest/common.py | 20 +++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/Tools/autotest/arduplane.py b/Tools/autotest/arduplane.py index 75968e03b1..77ae8e0c28 100644 --- a/Tools/autotest/arduplane.py +++ b/Tools/autotest/arduplane.py @@ -3958,6 +3958,84 @@ class AutoTestPlane(AutoTest): self.disarm_vehicle(force=True) self.reboot_sitl() + def AerobaticsScripting(self): + '''Fixed Wing Aerobatics''' + applet_script = "Aerobatics/FixedWing/plane_aerobatics.lua" + trick72 = "Aerobatics/FixedWing/trick72.txt" + + model = "plane-3d" + + self.customise_SITL_commandline( + [], + model=model, + defaults_filepath="", + wipe=True) + + self.context_push() + self.install_applet_script(applet_script) + self.install_applet_script(trick72) + self.context_collect('STATUSTEXT') + self.reboot_sitl() + + self.set_parameter("TRIK_ENABLE", 1) + self.set_rc(7, 1000) # disable tricks + + self.scripting_restart() + self.wait_text("Enabled 3 aerobatic tricks", check_context=True) + self.set_parameters({ + "TRIK1_ID": 72, + "RC7_OPTION" : 300, # activation switch + "RC9_OPTION" : 301, # selection switch + }) + + self.wait_ready_to_arm() + self.change_mode("TAKEOFF") + self.arm_vehicle() + self.wait_altitude(30, 40, timeout=30, relative=True) + self.change_mode("CRUISE") + + self.set_rc(9, 1000) # select first trick + self.delay_sim_time(1) + self.set_rc(7, 1500) # show selected trick + + self.wait_text("Trick 1 selected (SuperAirShow)", check_context=True) + self.set_rc(7, 2000) # activate trick + self.wait_text("Trick 1 started (SuperAirShow)", check_context=True) + + highest_error = 0 + while True: + m = self.mav.recv_match(type='NAMED_VALUE_FLOAT', blocking=True, timeout=2) + if not m: + break + if m.name != 'PERR': + continue + highest_error = max(highest_error, m.value) + if highest_error > 12: + raise NotAchievedException("path error %.1f" % m.value) + + if highest_error == 0: + raise NotAchievedException("path error not reported") + self.progress("Finished trick, max error=%.1fm" % highest_error) + self.disarm_vehicle(force=True) + + self.remove_example_script(applet_script) + self.remove_example_script(trick72) + messages = self.context_collection('STATUSTEXT') + self.context_pop() + self.reboot_sitl() + + # check all messages to see if we got all tricks + tricks = ["Loop", "HalfReverseCubanEight", "ScaleFigureEight", "Immelmann", + "Split-S", "RollingCircle", "HumptyBump", "HalfCubanEight", + "Upline45", "Downline45", "HalfReverseCubanEight", + "Finishing SuperAirShow!"] + texts = [m.text for m in messages] + for t in tricks: + if t in texts: + self.progress("Completed trick %s" % t) + else: + raise NotAchievedException("Missing trick %s" % t) + def tests(self): '''return list of all tests''' ret = super(AutoTestPlane, self).tests() @@ -4035,6 +4113,7 @@ class AutoTestPlane(AutoTest): self.HIGH_LATENCY2, self.MidAirDisarmDisallowed, self.EmbeddedParamParser, + self.AerobaticsScripting, ]) return ret diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index f4e0ef6067..d1f5081f78 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -2021,6 +2021,15 @@ class AutoTest(ABC): self.progress("Calling initialise-after-reboot") self.initialise_after_reboot_sitl() + def scripting_restart(self): + '''restart scripting subsystem''' + self.progress("Restarting Scripting") + self.run_cmd_int( + mavutil.mavlink.MAV_CMD_SCRIPTING, + mavutil.mavlink.SCRIPTING_CMD_STOP_AND_RESTART, + 0, 0, 0, 0, 0, 0, + timeout=5) + def set_streamrate(self, streamrate, timeout=20, stream=mavutil.mavlink.MAV_DATA_STREAM_ALL): '''set MAV_DATA_STREAM_ALL; timeout is wallclock time''' tstart = time.time() @@ -7058,8 +7067,11 @@ Also, ignores heartbeats not from our target system''' def script_test_source_path(self, scriptname): return os.path.join(self.rootdir(), "libraries", "AP_Scripting", "tests", scriptname) + def script_applet_source_path(self, scriptname): + return os.path.join(self.rootdir(), "libraries", "AP_Scripting", "applets", scriptname) + def installed_script_path(self, scriptname): - return os.path.join("scripts", scriptname) + return os.path.join("scripts", os.path.basename(scriptname)) def install_script(self, source, scriptname): dest = self.installed_script_path(scriptname) @@ -7077,8 +7089,12 @@ Also, ignores heartbeats not from our target system''' source = self.script_test_source_path(scriptname) self.install_script(source, scriptname) + def install_applet_script(self, scriptname): + source = self.script_applet_source_path(scriptname) + self.install_script(source, scriptname) + def remove_example_script(self, scriptname): - dest = self.installed_script_path(scriptname) + dest = self.installed_script_path(os.path.basename(scriptname)) try: os.unlink(dest) except IOError: