2017-02-21 13:32:26 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Drive APMrover2 in SITL
|
2016-11-08 07:06:05 -04:00
|
|
|
from __future__ import print_function
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
import os
|
|
|
|
import pexpect
|
|
|
|
import time
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
from common import AutoTest
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
from common import MsgRcvTimeoutException
|
|
|
|
from common import NotAchievedException
|
|
|
|
from common import PreconditionFailedException
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
from pysim import util
|
2012-11-27 19:43:11 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
from pymavlink import mavutil
|
|
|
|
|
2012-11-27 19:43:11 -04:00
|
|
|
# get location of scripts
|
2016-07-31 07:22:06 -03:00
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2012-11-27 19:43:11 -04:00
|
|
|
|
2017-08-16 10:55:21 -03:00
|
|
|
# HOME = mavutil.location(-35.362938, 149.165085, 584, 270)
|
2018-03-14 08:08:53 -03:00
|
|
|
HOME = mavutil.location(40.071374969556928,
|
|
|
|
-105.22978898137808,
|
|
|
|
1583.702759,
|
|
|
|
246)
|
|
|
|
|
|
|
|
|
|
|
|
class AutoTestRover(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(AutoTestRover, 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 = "APMrover2"
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def init(self):
|
|
|
|
if self.frame is None:
|
|
|
|
self.frame = 'rover'
|
|
|
|
|
2018-03-15 19:56:37 -03:00
|
|
|
self.apply_parameters_using_sitl()
|
2018-03-05 11:14:34 -04:00
|
|
|
|
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,
|
|
|
|
gdbserver=self.gdbserver)
|
2018-03-15 08:31:19 -03:00
|
|
|
self.mavproxy = util.start_MAVProxy_SITL(
|
|
|
|
'APMrover2', 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("APMrover2-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" %
|
|
|
|
connection_string)
|
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 reset_and_arm(self):
|
|
|
|
# """Reset RC, set to MANUAL and arm."""
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# # ensure all sticks in the middle
|
|
|
|
# self.set_rc_default()
|
|
|
|
# self.mavproxy.send('switch 1\n')
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# self.disarm_vehicle()
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# self.arm_vehicle()
|
|
|
|
#
|
|
|
|
# # TEST ARM RADIO
|
|
|
|
# def test_arm_motors_radio(self):
|
|
|
|
# """Test Arming motors with radio."""
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Test arming motors with radio")
|
2018-03-05 11:14:34 -04:00
|
|
|
# self.mavproxy.send('switch 6\n') # stabilize/manual mode
|
|
|
|
# self.wait_mode('MANUAL')
|
|
|
|
# self.mavproxy.send('rc 3 1500\n') # throttle at zero
|
|
|
|
# self.mavproxy.send('rc 1 2000\n') # steer full right
|
|
|
|
# self.mavproxy.expect('APM: Throttle armed')
|
|
|
|
# self.mavproxy.send('rc 1 1500\n')
|
|
|
|
#
|
|
|
|
# self.mav.motors_armed_wait()
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("MOTORS ARMED OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
# return True
|
|
|
|
#
|
|
|
|
# # TEST DISARM RADIO
|
|
|
|
# def test_disarm_motors_radio(self):
|
|
|
|
# """Test Disarm motors with radio."""
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Test disarming motors with radio")
|
2018-03-05 11:14:34 -04:00
|
|
|
# self.mavproxy.send('switch 6\n') # stabilize/manual mode
|
|
|
|
# self.wait_mode('MANUAL')
|
|
|
|
# self.mavproxy.send('rc 3 1500\n') # throttle at zero
|
|
|
|
# self.mavproxy.send('rc 1 1000\n') # steer full right
|
|
|
|
# tstart = self.get_sim_time()
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# timeout = 15
|
|
|
|
# while self.get_sim_time() < tstart + timeout:
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# if not self.mav.motors_armed():
|
|
|
|
# disarm_delay = self.get_sim_time() - tstart
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("MOTORS DISARMED OK WITH RADIO")
|
2018-03-05 11:14:34 -04:00
|
|
|
# self.mavproxy.send('rc 1 1500\n') # steer full right
|
|
|
|
# self.mavproxy.send('rc 4 1500\n') # yaw full right
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Disarm in %ss" % disarm_delay)
|
2018-03-05 11:14:34 -04:00
|
|
|
# return True
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("FAILED TO DISARM WITH RADIO")
|
2018-03-05 11:14:34 -04:00
|
|
|
# return False
|
|
|
|
#
|
|
|
|
# # TEST AUTO DISARM
|
|
|
|
# def test_autodisarm_motors(self):
|
|
|
|
# """Test Autodisarm motors."""
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Test Autodisarming motors")
|
2018-03-05 11:14:34 -04:00
|
|
|
# self.mavproxy.send('switch 6\n') # stabilize/manual mode
|
|
|
|
# # NOT IMPLEMENTED ON ROVER
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("MOTORS AUTODISARMED OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
# return True
|
|
|
|
#
|
|
|
|
# # TEST RC OVERRIDE
|
|
|
|
# # TEST RC OVERRIDE TIMEOUT
|
|
|
|
# def test_rtl(self, home, distance_min=5, timeout=250):
|
|
|
|
# """Return, land."""
|
|
|
|
# super(AutotestRover, self).test_rtl(home, distance_min, timeout)
|
|
|
|
#
|
|
|
|
# def test_mission(self, filename):
|
|
|
|
# """Test a mission from a file."""
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Test mission %s" % filename)
|
2018-03-05 11:14:34 -04:00
|
|
|
# num_wp = self.load_mission_from_file(filename)
|
|
|
|
# self.mavproxy.send('wp set 1\n')
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# self.mavproxy.send('switch 4\n') # auto mode
|
|
|
|
# self.wait_mode('AUTO')
|
|
|
|
# ret = self.wait_waypoint(0, num_wp-1, max_dist=5, timeout=500)
|
|
|
|
#
|
|
|
|
# if ret:
|
|
|
|
# self.mavproxy.expect("Mission Complete")
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# self.wait_mode('HOLD')
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("test: MISSION COMPLETE: passed=%s" % ret)
|
2018-03-05 11:14:34 -04:00
|
|
|
# return ret
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# TESTS DRIVE
|
|
|
|
##########################################################
|
|
|
|
# Drive a square in manual mode
|
|
|
|
def drive_square(self, side=50):
|
|
|
|
"""Drive a square, Driving N then E ."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("TEST SQUARE")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
# use LEARNING Mode
|
|
|
|
self.mavproxy.send('switch 5\n')
|
|
|
|
self.wait_mode('MANUAL')
|
|
|
|
|
|
|
|
# first aim north
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("\nTurn right towards north")
|
2018-04-27 15:21:53 -03:00
|
|
|
self.reach_heading_manual(10)
|
2018-03-05 11:14:34 -04:00
|
|
|
# save bottom left corner of box as waypoint
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Save WP 1 & 2")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.save_wp()
|
|
|
|
|
|
|
|
# pitch forward to fly north
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("\nGoing north %u meters" % side)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.reach_distance_manual(side)
|
2018-03-05 11:14:34 -04:00
|
|
|
# save top left corner of square as waypoint
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Save WP 3")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.save_wp()
|
|
|
|
|
|
|
|
# roll right to fly east
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("\nGoing east %u meters" % side)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.reach_heading_manual(100)
|
|
|
|
self.reach_distance_manual(side)
|
2018-03-05 11:14:34 -04:00
|
|
|
# save top right corner of square as waypoint
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Save WP 4")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.save_wp()
|
|
|
|
|
|
|
|
# pitch back to fly south
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("\nGoing south %u meters" % side)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.reach_heading_manual(190)
|
|
|
|
self.reach_distance_manual(side)
|
2018-03-05 11:14:34 -04:00
|
|
|
# save bottom right corner of square as waypoint
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Save WP 5")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.save_wp()
|
|
|
|
|
|
|
|
# roll left to fly west
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("\nGoing west %u meters" % side)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.reach_heading_manual(280)
|
|
|
|
self.reach_distance_manual(side)
|
2018-03-05 11:14:34 -04:00
|
|
|
# save bottom left corner of square (should be near home) as waypoint
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Save WP 6")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.save_wp()
|
|
|
|
|
|
|
|
def drive_left_circuit(self):
|
|
|
|
"""Drive a left circuit, 50m on a side."""
|
|
|
|
self.mavproxy.send('switch 6\n')
|
|
|
|
self.wait_mode('MANUAL')
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Driving 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)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_heading(270 - (90*i), accuracy=10)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(50, accuracy=7)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(3, 1500)
|
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
|
|
|
# def test_throttle_failsafe(self, home, distance_min=10, side=60,
|
|
|
|
# timeout=300):
|
2018-03-05 11:14:34 -04:00
|
|
|
# """Fly east, Failsafe, return, land."""
|
|
|
|
#
|
|
|
|
# self.mavproxy.send('switch 6\n') # manual mode
|
|
|
|
# self.wait_mode('MANUAL')
|
|
|
|
# self.mavproxy.send("param set FS_ACTION 1\n")
|
|
|
|
#
|
|
|
|
# # first aim east
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("turn east")
|
2018-03-05 11:14:34 -04:00
|
|
|
# if not self.reach_heading_manual(135):
|
|
|
|
# return False
|
|
|
|
#
|
|
|
|
# # fly east 60 meters
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("# Going forward %u meters" % side)
|
2018-03-05 11:14:34 -04:00
|
|
|
# if not self.reach_distance_manual(side):
|
|
|
|
# return False
|
|
|
|
#
|
|
|
|
# # pull throttle low
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("# Enter Failsafe")
|
2018-03-05 11:14:34 -04:00
|
|
|
# self.mavproxy.send('rc 3 900\n')
|
|
|
|
#
|
|
|
|
# tstart = self.get_sim_time()
|
|
|
|
# success = False
|
|
|
|
# while self.get_sim_time() < tstart + timeout and not success:
|
|
|
|
# m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
# pos = self.mav.location()
|
|
|
|
# home_distance = self.get_distance(home, pos)
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Alt: %u HomeDistance: %.0f" %
|
|
|
|
# (m.alt, home_distance))
|
2018-03-05 11:14:34 -04:00
|
|
|
# # check if we've reached home
|
|
|
|
# if home_distance <= distance_min:
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("RTL Complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
# success = True
|
|
|
|
#
|
|
|
|
# # reduce throttle
|
|
|
|
# self.mavproxy.send('rc 3 1500\n')
|
|
|
|
# self.mavproxy.expect('APM: Failsafe ended')
|
|
|
|
# self.mavproxy.send('switch 2\n') # manual mode
|
|
|
|
# self.mav.wait_heartbeat()
|
|
|
|
# self.wait_mode('MANUAL')
|
|
|
|
#
|
|
|
|
# if success:
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Reached failsafe home OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
# return True
|
|
|
|
# else:
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Failed to reach Home on failsafe RTL - "
|
|
|
|
# "timed out after %u seconds" % timeout)
|
2018-03-05 11:14:34 -04:00
|
|
|
# return False
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
# AUTOTEST ALL
|
|
|
|
#################################################
|
|
|
|
def drive_mission(self, filename):
|
|
|
|
"""Drive a mission from a file."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Driving 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 4\n') # auto mode
|
|
|
|
self.set_rc(3, 1500)
|
|
|
|
self.wait_mode('AUTO')
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_waypoint(1, 4, max_dist=5)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.wait_mode('HOLD')
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Mission OK")
|
2018-04-27 15:21:53 -03:00
|
|
|
|
|
|
|
def drive_mission_rover1(self):
|
|
|
|
self.drive_mission(os.path.join(testdir, "rover1.txt"))
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def do_get_banner(self):
|
|
|
|
self.mavproxy.send("long DO_SEND_BANNER 1\n")
|
|
|
|
start = time.time()
|
|
|
|
while True:
|
2018-03-14 08:08:53 -03:00
|
|
|
m = self.mav.recv_match(type='STATUSTEXT',
|
|
|
|
blocking=True,
|
|
|
|
timeout=1)
|
2018-03-05 11:14:34 -04:00
|
|
|
if m is not None and "ArduRover" in m.text:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("banner received: %s" % m.text)
|
2018-04-27 15:21:53 -03:00
|
|
|
return
|
2018-03-05 11:14:34 -04:00
|
|
|
if time.time() - start > 10:
|
|
|
|
break
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("banner not received")
|
2018-04-27 15:21:53 -03:00
|
|
|
raise MsgRcvTimeoutException()
|
2017-12-09 00:32:34 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def drive_brake_get_stopping_distance(self, speed):
|
|
|
|
# measure our stopping distance:
|
|
|
|
old_cruise_speed = self.get_parameter('CRUISE_SPEED')
|
|
|
|
old_accel_max = self.get_parameter('ATC_ACCEL_MAX')
|
|
|
|
|
|
|
|
# controller tends not to meet cruise speed (max of ~14 when 15
|
|
|
|
# set), thus *1.2
|
|
|
|
self.set_parameter('CRUISE_SPEED', speed*1.2)
|
|
|
|
# at time of writing, the vehicle is only capable of 10m/s/s accel
|
|
|
|
self.set_parameter('ATC_ACCEL_MAX', 15)
|
|
|
|
self.mavproxy.send("mode STEERING\n")
|
|
|
|
self.wait_mode('STEERING')
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
self.wait_groundspeed(15, 100)
|
|
|
|
initial = self.mav.location()
|
|
|
|
initial_time = time.time()
|
|
|
|
while time.time() - initial_time < 2:
|
|
|
|
# wait for a position update from the autopilot
|
|
|
|
start = self.mav.location()
|
|
|
|
if start != initial:
|
|
|
|
break
|
|
|
|
self.set_rc(3, 1500)
|
|
|
|
self.wait_groundspeed(0, 0.2) # why do we not stop?!
|
|
|
|
initial = self.mav.location()
|
|
|
|
initial_time = time.time()
|
|
|
|
while time.time() - initial_time < 2:
|
|
|
|
# wait for a position update from the autopilot
|
|
|
|
stop = self.mav.location()
|
|
|
|
if stop != initial:
|
|
|
|
break
|
|
|
|
delta = self.get_distance(start, stop)
|
|
|
|
|
|
|
|
self.set_parameter('CRUISE_SPEED', old_cruise_speed)
|
|
|
|
self.set_parameter('ATC_ACCEL_MAX', old_accel_max)
|
|
|
|
|
|
|
|
return delta
|
|
|
|
|
|
|
|
def drive_brake(self):
|
|
|
|
old_using_brake = self.get_parameter('ATC_BRAKE')
|
|
|
|
old_cruise_speed = self.get_parameter('CRUISE_SPEED')
|
|
|
|
|
|
|
|
self.set_parameter('CRUISE_SPEED', 15)
|
|
|
|
self.set_parameter('ATC_BRAKE', 0)
|
|
|
|
|
|
|
|
distance_without_brakes = self.drive_brake_get_stopping_distance(15)
|
|
|
|
|
|
|
|
# brakes on:
|
|
|
|
self.set_parameter('ATC_BRAKE', 1)
|
|
|
|
distance_with_brakes = self.drive_brake_get_stopping_distance(15)
|
|
|
|
# revert state:
|
|
|
|
self.set_parameter('ATC_BRAKE', old_using_brake)
|
|
|
|
self.set_parameter('CRUISE_SPEED', old_cruise_speed)
|
|
|
|
|
|
|
|
delta = distance_without_brakes - distance_with_brakes
|
|
|
|
if delta < distance_without_brakes * 0.05: # 5% isn't asking for much
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Brakes have negligible effect"
|
|
|
|
"(with=%0.2fm without=%0.2fm delta=%0.2fm)" %
|
|
|
|
(distance_with_brakes,
|
|
|
|
distance_without_brakes,
|
|
|
|
delta))
|
2018-04-27 15:21:53 -03:00
|
|
|
raise NotAchievedException()
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
self.progress(
|
|
|
|
"Brakes work (with=%0.2fm without=%0.2fm delta=%0.2fm)" %
|
|
|
|
(distance_with_brakes, distance_without_brakes, delta))
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def drive_rtl_mission(self):
|
2018-03-14 08:08:53 -03:00
|
|
|
mission_filepath = os.path.join(testdir,
|
|
|
|
"ArduRover-Missions",
|
|
|
|
"rtl.txt")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('wp load %s\n' % mission_filepath)
|
|
|
|
self.mavproxy.expect('Flight plan received')
|
|
|
|
self.mavproxy.send('switch 4\n') # auto mode
|
|
|
|
self.set_rc(3, 1500)
|
|
|
|
self.wait_mode('AUTO')
|
|
|
|
self.mavproxy.expect('Executing RTL')
|
|
|
|
|
|
|
|
m = self.mav.recv_match(type='NAV_CONTROLLER_OUTPUT',
|
|
|
|
blocking=True,
|
|
|
|
timeout=0.1)
|
|
|
|
if m is None:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Did not receive NAV_CONTROLLER_OUTPUT message")
|
2018-04-27 15:21:53 -03:00
|
|
|
raise MsgRcvTimeoutException()
|
2017-08-16 10:55:21 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
wp_dist_min = 5
|
|
|
|
if m.wp_dist < wp_dist_min:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Did not start at least 5 metres from destination")
|
2018-04-27 15:21:53 -03:00
|
|
|
raise PreconditionFailedException()
|
2017-08-16 10:55:21 -03:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("NAV_CONTROLLER_OUTPUT.wp_dist looks good (%u >= %u)" %
|
|
|
|
(m.wp_dist, wp_dist_min,))
|
2017-08-27 21:57:59 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
self.wait_mode('HOLD')
|
2017-09-16 08:47:46 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
pos = self.mav.location()
|
|
|
|
home_distance = self.get_distance(HOME, pos)
|
|
|
|
home_distance_max = 5
|
|
|
|
if home_distance > home_distance_max:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Did not get home (%u metres distant > %u)" %
|
|
|
|
(home_distance, home_distance_max))
|
2018-04-27 15:21:53 -03:00
|
|
|
raise NotAchievedException()
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('switch 6\n')
|
|
|
|
self.wait_mode('MANUAL')
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("RTL Mission OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-04-18 01:02:38 -03:00
|
|
|
def test_servorelayevents(self):
|
|
|
|
self.mavproxy.send("relay set 0 0\n")
|
|
|
|
off = self.get_parameter("SIM_PIN_MASK")
|
|
|
|
self.mavproxy.send("relay set 0 1\n")
|
|
|
|
on = self.get_parameter("SIM_PIN_MASK")
|
|
|
|
if on == off:
|
|
|
|
self.progress("Pin mask unchanged after relay command")
|
2018-04-27 15:21:53 -03:00
|
|
|
raise NotAchievedException()
|
2018-04-18 01:02:38 -03:00
|
|
|
self.progress("Pin mask changed after relay command")
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def autotest(self):
|
|
|
|
"""Autotest APMrover2 in SITL."""
|
|
|
|
if not self.hasInit:
|
|
|
|
self.init()
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Started simulator")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
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-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(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.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
|
|
|
self.mavproxy.send('switch 6\n') # Manual mode
|
|
|
|
self.wait_mode('MANUAL')
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Waiting reading for arm")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.wait_ready_to_arm()
|
2018-04-27 15:21:53 -03:00
|
|
|
self.arm_vehicle()
|
|
|
|
|
|
|
|
self.run_test("Drive an RTL Mission", self.drive_rtl_mission)
|
|
|
|
|
|
|
|
self.run_test("Learn/Drive Square with Ch7 option",
|
|
|
|
self.drive_square)
|
|
|
|
|
|
|
|
self.run_test("Drive Mission %s" % "rover1.txt",
|
|
|
|
self.drive_mission_rover1)
|
|
|
|
|
|
|
|
self.run_test("Drive Brake", self.drive_brake)
|
|
|
|
|
|
|
|
self.run_test("Disarm Vehicle", self.disarm_vehicle)
|
|
|
|
|
|
|
|
self.run_test("Get Banner", self.do_get_banner)
|
|
|
|
|
|
|
|
self.run_test("Get Capabilities",
|
|
|
|
self.do_get_autopilot_capabilities)
|
|
|
|
|
|
|
|
self.run_test("Set mode via MAV_COMMAND_DO_SET_MODE",
|
|
|
|
self.do_set_mode_via_command_long)
|
|
|
|
|
|
|
|
self.run_test("Test ServoRelayEvents",
|
|
|
|
self.test_servorelayevents)
|
|
|
|
|
|
|
|
self.run_test("Download logs", lambda:
|
2018-05-09 00:32:23 -03:00
|
|
|
self.log_download(
|
|
|
|
self.buildlogs_path("APMrover2-log.bin")))
|
2018-03-05 11:14:34 -04:00
|
|
|
# if not drive_left_circuit(self):
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Failed left circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# failed = True
|
|
|
|
# if not drive_RTL(self):
|
2018-03-14 08:08:53 -03:00
|
|
|
# self.progress("Failed RTL")
|
2018-03-05 11:14:34 -04:00
|
|
|
# failed = True
|
|
|
|
|
|
|
|
except pexpect.TIMEOUT as e:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Failed with timeout")
|
2018-05-09 00:32:23 -03:00
|
|
|
self.fail_list.append(("*timeout*", None))
|
2017-09-16 08:47:46 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
self.close()
|
2017-09-16 08:47:46 -03:00
|
|
|
|
2018-04-27 15:21:53 -03:00
|
|
|
if len(self.fail_list):
|
|
|
|
self.progress("FAILED STEPS: %s" % self.fail_list)
|
2018-03-05 11:14:34 -04:00
|
|
|
return False
|
|
|
|
return True
|