2017-02-21 13:32:26 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Dive ArduSub in SITL
|
2017-02-24 19:22:38 -04:00
|
|
|
from __future__ import print_function
|
|
|
|
import os
|
|
|
|
|
|
|
|
import pexpect
|
|
|
|
from pymavlink import mavutil
|
|
|
|
|
|
|
|
from pysim import util
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
from common import AutoTest
|
|
|
|
|
2017-02-24 19:22:38 -04:00
|
|
|
# get location of scripts
|
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2018-03-05 11:14:34 -04:00
|
|
|
HOME = mavutil.location(33.810313, -118.393867, 0, 185)
|
2017-02-24 19:22:38 -04:00
|
|
|
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
class AutoTestSub(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,
|
2018-07-23 04:06:00 -03:00
|
|
|
breakpoints=[],
|
2018-03-15 08:31:19 -03:00
|
|
|
**kwargs):
|
|
|
|
super(AutoTestSub, 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-07-23 04:06:00 -03:00
|
|
|
self.breakpoints = breakpoints
|
2018-03-05 11:14:34 -04:00
|
|
|
|
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.sitl = None
|
|
|
|
self.hasInit = False
|
|
|
|
|
2018-03-15 08:54:34 -03:00
|
|
|
self.log_name = "ArduSub"
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def init(self):
|
|
|
|
if self.frame is None:
|
|
|
|
self.frame = 'vectored'
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.sitl = util.start_SITL(self.binary,
|
|
|
|
model=self.frame,
|
|
|
|
home=self.home,
|
|
|
|
speedup=self.speedup,
|
|
|
|
valgrind=self.valgrind,
|
|
|
|
gdb=self.gdb,
|
2018-06-26 21:56:01 -03:00
|
|
|
gdbserver=self.gdbserver,
|
2018-07-23 04:06:00 -03:00
|
|
|
breakpoints=self.breakpoints,
|
2018-06-26 21:56:01 -03:00
|
|
|
wipe=True)
|
2018-03-15 08:31:19 -03:00
|
|
|
self.mavproxy = util.start_MAVProxy_SITL(
|
|
|
|
'ArduSub', options=self.mavproxy_options())
|
2018-03-20 08:34:59 -03:00
|
|
|
self.mavproxy.expect('Telemetry log: (\S+)\r\n')
|
2018-07-31 06:49:22 -03:00
|
|
|
self.logfile = self.mavproxy.match.group(1)
|
|
|
|
self.progress("LOGFILE %s" % self.logfile)
|
|
|
|
self.try_symlink_tlog()
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-06-26 21:56:01 -03:00
|
|
|
self.progress("WAITING FOR PARAMETERS")
|
2018-03-05 11:14:34 -04:00
|
|
|
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
|
|
|
|
2018-08-03 20:20:15 -03:00
|
|
|
self.get_mavlink_connection_going()
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
self.hasInit = True
|
2018-06-26 21:56:01 -03:00
|
|
|
|
|
|
|
self.apply_defaultfile_parameters()
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Ready to start testing!")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def dive_manual(self):
|
|
|
|
self.set_rc(3, 1600)
|
|
|
|
self.set_rc(5, 1600)
|
|
|
|
self.set_rc(6, 1550)
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(50, accuracy=7, timeout=200)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1550)
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_heading(0)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1500)
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(50, accuracy=7, timeout=100)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1550)
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_heading(0)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1500)
|
|
|
|
self.set_rc(5, 1500)
|
|
|
|
self.set_rc(6, 1100)
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(75, accuracy=7, timeout=100)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc_default()
|
|
|
|
|
|
|
|
self.disarm_vehicle()
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Manual dive OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def dive_mission(self, filename):
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Executing 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('Saved [0-9]+ waypoints')
|
|
|
|
self.set_rc_default()
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.arm_vehicle()
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
self.mavproxy.send('mode auto\n')
|
|
|
|
self.wait_mode('AUTO')
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_waypoint(1, 5, max_dist=5)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
self.disarm_vehicle()
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Mission OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def autotest(self):
|
|
|
|
"""Autotest ArduSub in SITL."""
|
2018-08-20 12:47:58 -03:00
|
|
|
self.check_test_syntax(test_file=os.path.realpath(__file__))
|
2018-03-05 11:14:34 -04:00
|
|
|
if not self.hasInit:
|
|
|
|
self.init()
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.fail_list = []
|
2018-03-05 11:14:34 -04:00
|
|
|
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-08-06 09:30:42 -03:00
|
|
|
self.set_parameter("FS_GCS_ENABLE", 0)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Waiting for GPS fix")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mav.wait_gps_fix()
|
|
|
|
|
|
|
|
# wait for EKF and GPS checks to pass
|
2018-07-04 01:48:41 -03:00
|
|
|
self.progress("Waiting for ready-to-arm")
|
|
|
|
self.wait_ready_to_arm()
|
2018-08-03 06:42:19 -03:00
|
|
|
self.run_test("Arm features", self.test_arm_feature)
|
|
|
|
self.arm_vehicle()
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
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
|
|
|
self.set_rc_default()
|
2018-04-27 15:21:53 -03:00
|
|
|
|
|
|
|
self.run_test("Arm vehicle", self.arm_vehicle)
|
|
|
|
|
|
|
|
self.run_test("Dive manual", self.dive_manual)
|
|
|
|
|
2018-05-09 00:32:23 -03:00
|
|
|
self.run_test("Dive mission",
|
|
|
|
lambda: self.dive_mission(
|
|
|
|
os.path.join(testdir, "sub_mission.txt")))
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-05-09 00:32:23 -03:00
|
|
|
self.run_test("Log download",
|
|
|
|
lambda: self.log_download(
|
|
|
|
self.buildlogs_path("ArduSub-log.bin")))
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-07-31 06:50:02 -03:00
|
|
|
except pexpect.TIMEOUT:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed with timeout")
|
2018-04-27 15:21:53 -03:00
|
|
|
self.fail_list.append("Failed with timeout")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
self.close()
|
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
if len(self.fail_list):
|
|
|
|
self.progress("FAILED: %s" % self.fail_list)
|
2018-03-05 11:14:34 -04:00
|
|
|
return False
|
|
|
|
return True
|