2017-02-21 13:32:26 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# Fly ArduPlane in SITL
|
2016-11-08 07:06:05 -04:00
|
|
|
from __future__ import print_function
|
2016-07-31 07:22:06 -03:00
|
|
|
import math
|
|
|
|
import os
|
|
|
|
|
|
|
|
import pexpect
|
2013-06-18 03:27:21 -03:00
|
|
|
from pymavlink import mavutil
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
from pysim import util
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
from common import AutoTest
|
|
|
|
|
2011-11-12 07:13:17 -04:00
|
|
|
# get location of scripts
|
2016-07-31 07:22:06 -03:00
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2018-03-05 11:14:34 -04:00
|
|
|
HOME = mavutil.location(-35.362938, 149.165085, 585, 354)
|
2016-07-31 07:22:06 -03:00
|
|
|
WIND = "0,180,0.2" # speed,direction,variance
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
class AutoTestPlane(AutoTest):
|
|
|
|
def __init__(self,
|
|
|
|
binary,
|
|
|
|
valgrind=False,
|
|
|
|
gdb=False,
|
|
|
|
speedup=10,
|
|
|
|
frame=None,
|
|
|
|
params=None,
|
2018-03-15 08:31:19 -03:00
|
|
|
gdbserver=False,
|
|
|
|
**kwargs):
|
|
|
|
super(AutoTestPlane, self).__init__(**kwargs)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.binary = binary
|
|
|
|
self.valgrind = valgrind
|
|
|
|
self.gdb = gdb
|
|
|
|
self.frame = frame
|
|
|
|
self.params = params
|
|
|
|
self.gdbserver = gdbserver
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.home = "%f,%f,%u,%u" % (HOME.lat,
|
|
|
|
HOME.lng,
|
|
|
|
HOME.alt,
|
|
|
|
HOME.heading)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.homeloc = None
|
|
|
|
self.speedup = speedup
|
|
|
|
self.speedup_default = 10
|
|
|
|
|
|
|
|
self.sitl = None
|
|
|
|
self.hasInit = False
|
|
|
|
|
2018-03-15 08:54:34 -03:00
|
|
|
self.log_name = "ArduPlane"
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def init(self):
|
|
|
|
if self.frame is None:
|
|
|
|
self.frame = 'plane-elevrev'
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
defaults_file = os.path.join(testdir,
|
|
|
|
'default_params/plane-jsbsim.parm')
|
|
|
|
self.sitl = util.start_SITL(self.binary,
|
|
|
|
wipe=True,
|
|
|
|
model=self.frame,
|
|
|
|
home=self.home,
|
|
|
|
speedup=self.speedup,
|
|
|
|
defaults_file=defaults_file,
|
|
|
|
valgrind=self.valgrind,
|
|
|
|
gdb=self.gdb,
|
|
|
|
gdbserver=self.gdbserver)
|
2018-03-15 08:31:19 -03:00
|
|
|
self.mavproxy = util.start_MAVProxy_SITL(
|
|
|
|
'ArduPlane', options=self.mavproxy_options())
|
2018-03-20 08:34:59 -03:00
|
|
|
self.mavproxy.expect('Telemetry log: (\S+)\r\n')
|
2018-03-05 11:14:34 -04:00
|
|
|
logfile = self.mavproxy.match.group(1)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("LOGFILE %s" % logfile)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
buildlog = self.buildlogs_path("ArduPlane-test.tlog")
|
|
|
|
self.progress("buildlog=%s" % buildlog)
|
2018-03-05 11:14:34 -04:00
|
|
|
if os.path.exists(buildlog):
|
|
|
|
os.unlink(buildlog)
|
|
|
|
try:
|
|
|
|
os.link(logfile, buildlog)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.mavproxy.expect('Received [0-9]+ parameters')
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
util.expect_setup_callback(self.mavproxy, self.expect_callback)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.expect_list_clear()
|
|
|
|
self.expect_list_extend([self.sitl, self.mavproxy])
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Started simulator")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
# get a mavlink connection going
|
2018-03-14 08:08:53 -03:00
|
|
|
connection_string = '127.0.0.1:19550'
|
2018-03-05 11:14:34 -04:00
|
|
|
try:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.mav = mavutil.mavlink_connection(connection_string,
|
|
|
|
robust_parsing=True)
|
2018-03-05 11:14:34 -04:00
|
|
|
except Exception as msg:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed to start mavlink connection on %s: %s"
|
|
|
|
% (connection_string, msg))
|
2018-03-05 11:14:34 -04:00
|
|
|
raise
|
2018-03-14 08:08:53 -03:00
|
|
|
self.mav.message_hooks.append(self.message_hook)
|
|
|
|
self.mav.idle_hooks.append(self.idle_hook)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.hasInit = True
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Ready to start testing!")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def takeoff(self):
|
|
|
|
"""Takeoff get to 30m altitude."""
|
|
|
|
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
# some rudder to counteract the prop torque
|
|
|
|
self.set_rc(4, 1700)
|
|
|
|
|
|
|
|
# some up elevator to keep the tail down
|
|
|
|
self.set_rc(2, 1200)
|
|
|
|
|
|
|
|
# get it moving a bit first
|
|
|
|
self.set_rc(3, 1300)
|
|
|
|
self.mav.recv_match(condition='VFR_HUD.groundspeed>6', blocking=True)
|
|
|
|
|
|
|
|
# a bit faster again, straighten rudder
|
|
|
|
self.set_rc(3, 1600)
|
|
|
|
self.set_rc(4, 1500)
|
|
|
|
self.mav.recv_match(condition='VFR_HUD.groundspeed>12', blocking=True)
|
|
|
|
|
|
|
|
# hit the gas harder now, and give it some more elevator
|
|
|
|
self.set_rc(2, 1100)
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
|
|
|
|
# gain a bit of altitude
|
2018-03-14 08:08:53 -03:00
|
|
|
if not self.wait_altitude(self.homeloc.alt+150,
|
|
|
|
self.homeloc.alt+180,
|
|
|
|
timeout=30):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# level off
|
|
|
|
self.set_rc(2, 1500)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("TAKEOFF COMPLETE")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def fly_left_circuit(self):
|
|
|
|
"""Fly a left circuit, 200m on a side."""
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
if not self.wait_level_flight():
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2018-03-14 08:08:53 -03:00
|
|
|
|
|
|
|
self.progress("Flying left circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# do 4 turns
|
|
|
|
for i in range(0, 4):
|
|
|
|
# hard left
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting turn %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1000)
|
|
|
|
if not self.wait_heading(270 - (90*i), accuracy=10):
|
|
|
|
return False
|
|
|
|
self.set_rc(1, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
if not self.wait_distance(100, accuracy=20):
|
|
|
|
return False
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Circuit complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
|
|
|
|
|
|
|
def fly_RTL(self):
|
|
|
|
"""Fly to home."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying home in RTL")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('switch 2\n')
|
|
|
|
self.wait_mode('RTL')
|
2018-03-14 08:08:53 -03:00
|
|
|
if not self.wait_location(self.homeloc,
|
|
|
|
accuracy=120,
|
|
|
|
target_altitude=self.homeloc.alt+100,
|
|
|
|
height_accuracy=20,
|
2018-03-05 11:14:34 -04:00
|
|
|
timeout=180):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("RTL Complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
|
|
|
|
|
|
|
def fly_LOITER(self, num_circles=4):
|
|
|
|
"""Loiter where we are."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Testing LOITER for %u turns" % num_circles)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('loiter\n')
|
|
|
|
self.wait_mode('LOITER')
|
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Initial altitude %u\n" % initial_alt)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
while num_circles > 0:
|
|
|
|
if not self.wait_heading(0, accuracy=10, timeout=60):
|
|
|
|
return False
|
|
|
|
if not self.wait_heading(180, accuracy=10, timeout=60):
|
|
|
|
return False
|
|
|
|
num_circles -= 1
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Loiter %u circles left" % num_circles)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Final altitude %u initial %u\n" %
|
|
|
|
(final_alt, initial_alt))
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed to maintain altitude")
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Completed Loiter OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def fly_CIRCLE(self, num_circles=1):
|
|
|
|
"""Circle where we are."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Testing CIRCLE for %u turns" % num_circles)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('mode CIRCLE\n')
|
|
|
|
self.wait_mode('CIRCLE')
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Initial altitude %u\n" % initial_alt)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
while num_circles > 0:
|
|
|
|
if not self.wait_heading(0, accuracy=10, timeout=60):
|
|
|
|
return False
|
|
|
|
if not self.wait_heading(180, accuracy=10, timeout=60):
|
|
|
|
return False
|
|
|
|
num_circles -= 1
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("CIRCLE %u circles left" % num_circles)
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Final altitude %u initial %u\n" %
|
|
|
|
(final_alt, initial_alt))
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
if abs(final_alt - initial_alt) > 20:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed to maintain altitude")
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-13 21:59:59 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Completed CIRCLE OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
|
|
|
|
|
|
|
def wait_level_flight(self, accuracy=5, timeout=30):
|
|
|
|
"""Wait for level flight."""
|
|
|
|
tstart = self.get_sim_time()
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Waiting for level flight")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1500)
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
self.set_rc(4, 1500)
|
|
|
|
while self.get_sim_time() < tstart + timeout:
|
|
|
|
m = self.mav.recv_match(type='ATTITUDE', blocking=True)
|
|
|
|
roll = math.degrees(m.roll)
|
|
|
|
pitch = math.degrees(m.pitch)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Roll=%.1f Pitch=%.1f" % (roll, pitch))
|
2018-03-05 11:14:34 -04:00
|
|
|
if math.fabs(roll) <= accuracy and math.fabs(pitch) <= accuracy:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Attained level flight")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed to attain level flight")
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-13 21:59:59 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def change_altitude(self, altitude, accuracy=30):
|
|
|
|
"""Get to a given altitude."""
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
alt_error = self.mav.messages['VFR_HUD'].alt - altitude
|
|
|
|
if alt_error > 0:
|
|
|
|
self.set_rc(2, 2000)
|
|
|
|
else:
|
|
|
|
self.set_rc(2, 1000)
|
|
|
|
if not self.wait_altitude(altitude-accuracy/2, altitude+accuracy/2):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Reached target altitude at %u" %
|
|
|
|
self.mav.messages['VFR_HUD'].alt)
|
2018-03-05 11:14:34 -04:00
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def axial_left_roll(self, count=1):
|
|
|
|
"""Fly a left axial roll."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
if not self.change_altitude(self.homeloc.alt+300):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# fly the roll in manual
|
|
|
|
self.mavproxy.send('switch 6\n')
|
|
|
|
self.wait_mode('MANUAL')
|
|
|
|
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1000)
|
|
|
|
if not self.wait_roll(-150, accuracy=90):
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
return False
|
|
|
|
if not self.wait_roll(150, accuracy=90):
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
return False
|
|
|
|
if not self.wait_roll(0, accuracy=90):
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def inside_loop(self, count=1):
|
|
|
|
"""Fly a inside loop."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
if not self.change_altitude(self.homeloc.alt+300):
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# fly the loop in manual
|
|
|
|
self.mavproxy.send('switch 6\n')
|
|
|
|
self.wait_mode('MANUAL')
|
|
|
|
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting loop")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1000)
|
|
|
|
if not self.wait_pitch(-60, accuracy=20):
|
|
|
|
return False
|
|
|
|
if not self.wait_pitch(0, accuracy=20):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def test_stabilize(self, count=1):
|
|
|
|
"""Fly stabilize mode."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
self.set_rc(2, 1300)
|
|
|
|
if not self.change_altitude(self.homeloc.alt+300):
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
self.mavproxy.send("mode STABILIZE\n")
|
|
|
|
self.wait_mode('STABILIZE')
|
|
|
|
|
|
|
|
count = 1
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 2000)
|
|
|
|
if not self.wait_roll(-150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not self.wait_roll(150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not self.wait_roll(0, accuracy=90):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
if not self.wait_roll(0, accuracy=5):
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def test_acro(self, count=1):
|
|
|
|
"""Fly ACRO mode."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
self.set_rc(2, 1300)
|
|
|
|
if not self.change_altitude(self.homeloc.alt+300):
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
self.mavproxy.send("mode ACRO\n")
|
|
|
|
self.wait_mode('ACRO')
|
|
|
|
|
|
|
|
count = 1
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1000)
|
|
|
|
if not self.wait_roll(-150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not self.wait_roll(150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not self.wait_roll(0, accuracy=90):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
self.wait_level_flight()
|
|
|
|
|
|
|
|
self.mavproxy.send("mode ACRO\n")
|
|
|
|
self.wait_mode('ACRO')
|
|
|
|
|
|
|
|
count = 2
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting loop")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1000)
|
|
|
|
if not self.wait_pitch(-60, accuracy=20):
|
|
|
|
return False
|
|
|
|
if not self.wait_pitch(0, accuracy=20):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def test_FBWB(self, count=1, mode='FBWB'):
|
|
|
|
"""Fly FBWB or CRUISE mode."""
|
|
|
|
self.mavproxy.send("mode %s\n" % mode)
|
|
|
|
self.wait_mode(mode)
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
# lock in the altitude by asking for an altitude change then releasing
|
|
|
|
self.set_rc(2, 1000)
|
|
|
|
self.wait_distance(50, accuracy=20)
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
self.wait_distance(50, accuracy=20)
|
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Initial altitude %u\n" % initial_alt)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying right circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# do 4 turns
|
|
|
|
for i in range(0, 4):
|
|
|
|
# hard left
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting turn %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1800)
|
|
|
|
if not self.wait_heading(0 + (90*i), accuracy=20, timeout=60):
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
return False
|
|
|
|
self.set_rc(1, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
if not self.wait_distance(100, accuracy=20):
|
|
|
|
return False
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Circuit complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying rudder left circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# do 4 turns
|
|
|
|
for i in range(0, 4):
|
|
|
|
# hard left
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting turn %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1900)
|
|
|
|
if not self.wait_heading(360 - (90*i), accuracy=20, timeout=60):
|
|
|
|
self.set_rc(4, 1500)
|
|
|
|
return False
|
|
|
|
self.set_rc(4, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
if not self.wait_distance(100, accuracy=20):
|
|
|
|
return False
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Circuit complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Final altitude %u initial %u\n" %
|
|
|
|
(final_alt, initial_alt))
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed to maintain altitude")
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def fly_mission(self, filename, height_accuracy=-1, target_altitude=None):
|
|
|
|
"""Fly a mission from a file."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying mission %s" % filename)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('wp load %s\n' % filename)
|
|
|
|
self.mavproxy.expect('Flight plan received')
|
|
|
|
self.mavproxy.send('wp list\n')
|
|
|
|
self.mavproxy.expect('Requesting [0-9]+ waypoints')
|
|
|
|
self.mavproxy.send('switch 1\n') # auto mode
|
|
|
|
self.wait_mode('AUTO')
|
|
|
|
if not self.wait_waypoint(1, 7, max_dist=60):
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
2018-03-05 11:14:34 -04:00
|
|
|
if not self.wait_groundspeed(0, 0.5, timeout=60):
|
2013-07-16 00:23:48 -03:00
|
|
|
return False
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.expect("Auto disarmed")
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Mission OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
return True
|
|
|
|
|
|
|
|
def autotest(self):
|
|
|
|
"""Autotest ArduPlane in SITL."""
|
|
|
|
if not self.hasInit:
|
|
|
|
self.init()
|
|
|
|
|
|
|
|
failed = False
|
|
|
|
fail_list = []
|
|
|
|
e = 'None'
|
|
|
|
try:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Waiting for a heartbeat with mavlink protocol %s"
|
|
|
|
% self.mav.WIRE_PROTOCOL_VERSION)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mav.wait_heartbeat()
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Setting up RC parameters")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc_default()
|
|
|
|
self.set_rc(3, 1000)
|
|
|
|
self.set_rc(8, 1800)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Waiting for GPS fix")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mav.recv_match(condition='VFR_HUD.alt>10', blocking=True)
|
|
|
|
self.mav.wait_gps_fix()
|
|
|
|
while self.mav.location().alt < 10:
|
|
|
|
self.mav.wait_gps_fix()
|
|
|
|
self.homeloc = self.mav.location()
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Home location: %s" % self.homeloc)
|
2018-03-05 11:14:34 -04:00
|
|
|
if not self.takeoff():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed takeoff")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("takeoff")
|
|
|
|
if not self.fly_left_circuit():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed left circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("left_circuit")
|
|
|
|
if not self.axial_left_roll(1):
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed left roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("left_roll")
|
|
|
|
if not self.inside_loop():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed inside loop")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("inside_loop")
|
|
|
|
if not self.test_stabilize():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed stabilize test")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("stabilize")
|
|
|
|
if not self.test_acro():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed ACRO test")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("acro")
|
|
|
|
if not self.test_FBWB():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed FBWB test")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("fbwb")
|
|
|
|
if not self.test_FBWB(mode='CRUISE'):
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed CRUISE test")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("cruise")
|
|
|
|
if not self.fly_RTL():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed RTL")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("RTL")
|
|
|
|
if not self.fly_LOITER():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed LOITER")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("LOITER")
|
|
|
|
if not self.fly_CIRCLE():
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed CIRCLE")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("LOITER")
|
2018-03-14 08:08:53 -03:00
|
|
|
if not self.fly_mission(os.path.join(testdir, "ap1.txt"),
|
|
|
|
height_accuracy=10,
|
2018-03-05 11:14:34 -04:00
|
|
|
target_altitude=self.homeloc.alt+100):
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed mission")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("mission")
|
2018-03-14 08:08:53 -03:00
|
|
|
if not self.log_download(self.buildlogs_path("ArduPlane-log.bin")):
|
|
|
|
self.progress("Failed log download")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("log_download")
|
|
|
|
except pexpect.TIMEOUT as e:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed with timeout")
|
2018-03-05 11:14:34 -04:00
|
|
|
failed = True
|
|
|
|
fail_list.append("timeout")
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
self.close()
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
if failed:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("FAILED: %s" % e)
|
|
|
|
self.progress("Fail list: %s" % fail_list)
|
2018-03-05 11:14:34 -04:00
|
|
|
return False
|
|
|
|
return True
|