Skip to content

Commit

Permalink
autotest: add QuadPlane.RealFlightHover
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlong13 committed Nov 27, 2024
1 parent 06e1fdc commit 9c0130d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tools/autotest/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ def run_step(step):
}
if opts.speedup is not None:
fly_opts["speedup"] = opts.speedup
if opts.realflight_address is not None:
fly_opts["realflight_address"] = opts.realflight_address

# handle "test.Copter" etc:
if step in tester_class_map:
Expand Down Expand Up @@ -1017,6 +1019,9 @@ def format_epilog(self, formatter):
group_sim.add_option("", "--replay",
action='store_true',
help="enable replay logging for tests")
group_sim.add_option("--realflight-address",
default=None,
help="IP address of RealFlight simulator")
parser.add_option_group(group_sim)

group_completion = optparse.OptionGroup(parser, "Completion helpers")
Expand Down
2 changes: 2 additions & 0 deletions Tools/autotest/default_params/realflight-autotest-extra.parm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SIM_RFL_OPTS,9 # Reset vehicle on start | Don't print frame rate stats
RC_PROTOCOLS,0x40000 # Only accept UDP RC input
62 changes: 62 additions & 0 deletions Tools/autotest/quadplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,64 @@ def WindEstimateConsistency(self):
self.progress("Wind estimates correlated")
break

def setup_RealFlight_vehicle(self, model, home):
'''
Restart the SITL for RealFlight. RealFlight must already be running and
the correct airport and model must be loaded.
'''
defaults_filepath = self.model_defaults_filepath(model)
extra_params = 'default_params/realflight-autotest-extra.parm'
defaults_filepath.append(os.path.join(testdir, extra_params))
self.customise_SITL_commandline(
[
f"--home={home}",
],
model=f"flightaxis:{self.realflight_address}",
defaults_filepath=defaults_filepath
)

def RealFlightHover(self, model, home):
'''
Perform a simple hover test in RealFlight. Useful for generating logs
for comparative analysis.
'''
if not self.realflight_address:
self.progress("Specify an IP address with --realflight-address or REALFLIGHT_IPADDR to run this test")
return

# Log fullrate attitude for PID Review Tool
self.set_parameters({
"LOG_BITMASK": 0x10FFFF,
})
self.setup_RealFlight_vehicle(model, home)

self.wait_ready_to_arm()
self.change_mode("QLOITER")
self.arm_vehicle()
self.set_rc(3, 2000)
self.wait_altitude(8, 12, relative=True)
self.set_rc(3, 1500)
stick_deflections = [
(2000, 1500, "Roll right"),
(1500, 1500, "Center"),
(1000, 1500, "Roll left"),
(1500, 1500, "Center"),
(1500, 2000, "Pitch forward"),
(1500, 1500, "Center"),
(1500, 1000, "Pitch back"),
(1500, 1500, "Center"),
]
n_iterations = 10
for i in range(n_iterations):
print(f"Control input cycle: {i+1}/{n_iterations}")
for roll, pitch, msg in stick_deflections:
self.progress(f"{msg}")
self.set_rc(1, roll)
self.set_rc(2, pitch)
self.delay_sim_time(0.5)
self.change_mode("QLAND")
self.wait_disarmed(timeout=120)

def tests(self):
'''return list of all tests'''

Expand Down Expand Up @@ -2123,5 +2181,9 @@ def tests(self):
self.RTL_AUTOLAND_1, # as in fly-home then go to landing sequence
self.RTL_AUTOLAND_1_FROM_GUIDED, # as in fly-home then go to landing sequence
self.AHRSFlyForwardFlag,
Test(self.RealFlightHover, speedup=1, kwargs={
'model': 'realflight-titan-cobra',
'home': 'EliField'
}),
])
return ret
2 changes: 2 additions & 0 deletions Tools/autotest/vehicle_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ def __init__(self,
dronecan_tests=False,
generate_junit=False,
enable_fgview=False,
realflight_address=None,
build_opts={}):

self.start_time = time.time()
Expand Down Expand Up @@ -1973,6 +1974,7 @@ def __init__(self,
self.in_drain_mav = False
self.tlog = None
self.enable_fgview = enable_fgview
self.realflight_address = realflight_address or os.getenv("REALFLIGHT_IPADDR")

self.rc_thread = None
self.rc_thread_should_quit = False
Expand Down

0 comments on commit 9c0130d

Please sign in to comment.