2017-02-21 13:32:26 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Fly ArduPlane QuadPlane in SITL
|
2016-11-08 07:06:05 -04:00
|
|
|
from __future__ import print_function
|
2016-07-31 07:22:06 -03:00
|
|
|
import os
|
|
|
|
import pexpect
|
|
|
|
import shutil
|
2016-01-09 01:27:03 -04:00
|
|
|
from pymavlink import mavutil
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
from common import *
|
|
|
|
from pysim import util
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
# get location of scripts
|
2016-07-31 07:22:06 -03:00
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
HOME_LOCATION = '-27.274439,151.290064,343,8.7'
|
|
|
|
MISSION = 'ArduPlane-Missions/Dalby-OBC2016.txt'
|
|
|
|
FENCE = 'ArduPlane-Missions/Dalby-OBC2016-fence.txt'
|
|
|
|
WIND = "0,180,0.2" # speed,direction,variance
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
homeloc = None
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2016-01-09 01:50:17 -04:00
|
|
|
def fly_mission(mavproxy, mav, filename, fence, height_accuracy=-1):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Fly a mission from a file."""
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Flying mission %s" % filename)
|
2016-01-09 01:27:03 -04:00
|
|
|
mavproxy.send('wp load %s\n' % filename)
|
|
|
|
mavproxy.expect('Flight plan received')
|
2016-01-09 01:50:17 -04:00
|
|
|
mavproxy.send('fence load %s\n' % fence)
|
2016-01-09 01:27:03 -04:00
|
|
|
mavproxy.send('wp list\n')
|
|
|
|
mavproxy.expect('Requesting [0-9]+ waypoints')
|
|
|
|
mavproxy.send('mode AUTO\n')
|
|
|
|
wait_mode(mav, 'AUTO')
|
2016-07-20 06:44:14 -03:00
|
|
|
if not wait_waypoint(mav, 1, 19, max_dist=60, timeout=1200):
|
2016-01-09 01:50:17 -04:00
|
|
|
return False
|
|
|
|
mavproxy.expect('DISARMED')
|
|
|
|
# wait for blood sample here
|
2016-07-20 06:44:14 -03:00
|
|
|
mavproxy.send('wp set 20\n')
|
2017-08-16 10:55:21 -03:00
|
|
|
arm_vehicle(mavproxy, mav)
|
2016-07-20 06:44:14 -03:00
|
|
|
if not wait_waypoint(mav, 20, 34, max_dist=60, timeout=1200):
|
2016-01-09 01:27:03 -04:00
|
|
|
return False
|
|
|
|
mavproxy.expect('DISARMED')
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Mission OK")
|
2016-01-09 01:27:03 -04:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2017-08-26 01:59:36 -03:00
|
|
|
def fly_QuadPlane(binary, viewerip=None, use_map=False, valgrind=False, gdb=False, gdbserver=False, speedup=10):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Fly QuadPlane in SITL.
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
you can pass viewerip as an IP address to optionally send fg and
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy packets too for local viewing of the flight in real time.
|
|
|
|
"""
|
2016-01-09 01:27:03 -04:00
|
|
|
global homeloc
|
|
|
|
|
|
|
|
options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10'
|
|
|
|
if viewerip:
|
|
|
|
options += " --out=%s:14550" % viewerip
|
2016-07-31 07:22:06 -03:00
|
|
|
if use_map:
|
2016-01-09 01:27:03 -04:00
|
|
|
options += ' --map'
|
|
|
|
|
2017-08-26 01:59:36 -03:00
|
|
|
sitl = util.start_SITL(binary, model='quadplane', wipe=True, home=HOME_LOCATION, speedup=speedup,
|
2017-07-07 01:05:04 -03:00
|
|
|
defaults_file=os.path.join(testdir, 'default_params/quadplane.parm'), valgrind=valgrind, gdb=gdb, gdbserver=gdbserver)
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy = util.start_MAVProxy_SITL('QuadPlane', options=options)
|
2016-01-09 01:27:03 -04:00
|
|
|
mavproxy.expect('Telemetry log: (\S+)')
|
|
|
|
logfile = mavproxy.match.group(1)
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("LOGFILE %s" % logfile)
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
buildlog = util.reltopdir("../buildlogs/QuadPlane-test.tlog")
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("buildlog=%s" % buildlog)
|
2016-01-09 01:27:03 -04:00
|
|
|
if os.path.exists(buildlog):
|
|
|
|
os.unlink(buildlog)
|
|
|
|
try:
|
|
|
|
os.link(logfile, buildlog)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
util.expect_setup_callback(mavproxy, expect_callback)
|
|
|
|
|
|
|
|
mavproxy.expect('Received [0-9]+ parameters')
|
|
|
|
|
|
|
|
expect_list_clear()
|
2016-07-31 07:22:06 -03:00
|
|
|
expect_list_extend([sitl, mavproxy])
|
2016-01-09 01:27:03 -04:00
|
|
|
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Started simulator")
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
# get a mavlink connection going
|
|
|
|
try:
|
|
|
|
mav = mavutil.mavlink_connection('127.0.0.1:19550', robust_parsing=True)
|
2016-07-31 07:22:06 -03:00
|
|
|
except Exception as msg:
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Failed to start mavlink connection on 127.0.0.1:19550" % msg)
|
2016-01-09 01:27:03 -04:00
|
|
|
raise
|
|
|
|
mav.message_hooks.append(message_hook)
|
|
|
|
mav.idle_hooks.append(idle_hook)
|
|
|
|
|
|
|
|
failed = False
|
|
|
|
e = 'None'
|
|
|
|
try:
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Waiting for a heartbeat with mavlink protocol %s" % mav.WIRE_PROTOCOL_VERSION)
|
2016-01-09 01:27:03 -04:00
|
|
|
mav.wait_heartbeat()
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Waiting for GPS fix")
|
2016-01-09 01:27:03 -04:00
|
|
|
mav.recv_match(condition='VFR_HUD.alt>10', blocking=True)
|
|
|
|
mav.wait_gps_fix()
|
|
|
|
while mav.location().alt < 10:
|
|
|
|
mav.wait_gps_fix()
|
|
|
|
homeloc = mav.location()
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Home location: %s" % homeloc)
|
2016-01-09 01:27:03 -04:00
|
|
|
|
2016-07-04 21:45:33 -03:00
|
|
|
# wait for EKF and GPS checks to pass
|
|
|
|
wait_seconds(mav, 30)
|
2016-01-09 01:27:03 -04:00
|
|
|
|
2017-08-16 10:55:21 -03:00
|
|
|
arm_vehicle(mavproxy, mav)
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2016-01-09 01:50:17 -04:00
|
|
|
if not fly_mission(mavproxy, mav,
|
|
|
|
os.path.join(testdir, "ArduPlane-Missions/Dalby-OBC2016.txt"),
|
|
|
|
os.path.join(testdir, "ArduPlane-Missions/Dalby-OBC2016-fence.txt")):
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Failed mission")
|
2016-01-09 01:27:03 -04:00
|
|
|
failed = True
|
2016-07-31 07:22:06 -03:00
|
|
|
except pexpect.TIMEOUT as e:
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("Failed with timeout")
|
2016-01-09 01:27:03 -04:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
mav.close()
|
|
|
|
util.pexpect_close(mavproxy)
|
2016-07-31 07:22:06 -03:00
|
|
|
util.pexpect_close(sitl)
|
2016-01-09 01:27:03 -04:00
|
|
|
|
2016-11-08 06:53:54 -04:00
|
|
|
valgrind_log = util.valgrind_log_filepath(binary=binary, model='quadplane')
|
2016-05-27 03:45:25 -03:00
|
|
|
if os.path.exists(valgrind_log):
|
2016-11-08 07:06:05 -04:00
|
|
|
os.chmod(valgrind_log, 0o644)
|
2016-05-27 03:45:25 -03:00
|
|
|
shutil.copy(valgrind_log, util.reltopdir("../buildlogs/QuadPlane-valgrind.log"))
|
2016-01-09 01:27:03 -04:00
|
|
|
|
|
|
|
if failed:
|
2017-11-14 00:30:31 -04:00
|
|
|
progress("FAILED: %s" % e)
|
2016-01-09 01:27:03 -04:00
|
|
|
return False
|
|
|
|
return True
|