2013-07-10 01:03:40 -03:00
|
|
|
# fly ArduCopter in SITL
|
|
|
|
# Flight mode switch positions are set-up in arducopter.param to be
|
|
|
|
# switch 1 = Circle
|
|
|
|
# switch 2 = Land
|
|
|
|
# switch 3 = RTL
|
|
|
|
# switch 4 = Auto
|
|
|
|
# switch 5 = Loiter
|
|
|
|
# switch 6 = Stabilize
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
import math
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import time
|
|
|
|
|
|
|
|
import pexpect
|
2013-06-18 03:27:21 -03:00
|
|
|
from pymavlink import mavutil, mavwp
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
from common import *
|
|
|
|
from pysim import util
|
2011-10-31 04:29:52 -03:00
|
|
|
|
|
|
|
# get location of scripts
|
2016-07-31 07:22:06 -03:00
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
HOME = mavutil.location(-35.362938, 149.165085, 584, 270)
|
|
|
|
AVCHOME = mavutil.location(40.072842, -105.230575, 1586, 0)
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2011-11-01 20:26:24 -03:00
|
|
|
homeloc = None
|
2011-11-13 04:24:25 -04:00
|
|
|
num_wp = 0
|
2016-07-11 22:04:40 -03:00
|
|
|
speedup_default = 10
|
2011-11-01 20:26:24 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2016-06-03 23:31:55 -03:00
|
|
|
def hover(mavproxy, mav, hover_throttle=1500):
|
2012-07-06 03:48:50 -03:00
|
|
|
mavproxy.send('rc 3 %u\n' % hover_throttle)
|
2012-02-19 16:38:57 -04:00
|
|
|
return True
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2011-11-13 06:14:58 -04:00
|
|
|
def arm_motors(mavproxy, mav):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Arm motors."""
|
2011-11-09 05:27:36 -04:00
|
|
|
print("Arming motors")
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2011-11-13 06:20:10 -04:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
mavproxy.send('rc 4 2000\n')
|
2015-11-29 03:39:32 -04:00
|
|
|
mavproxy.expect('APM: Arming motors')
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy.send('rc 4 1500\n')
|
2013-05-29 02:33:32 -03:00
|
|
|
mav.motors_armed_wait()
|
2011-10-30 23:50:34 -03:00
|
|
|
print("MOTORS ARMED OK")
|
2011-11-09 22:12:43 -04:00
|
|
|
return True
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2011-11-13 06:14:58 -04:00
|
|
|
def disarm_motors(mavproxy, mav):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Disarm motors."""
|
2011-11-09 05:27:36 -04:00
|
|
|
print("Disarming motors")
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
mavproxy.send('rc 4 1000\n')
|
2015-11-29 03:39:32 -04:00
|
|
|
mavproxy.expect('APM: Disarming motors')
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy.send('rc 4 1500\n')
|
2013-05-29 02:33:32 -03:00
|
|
|
mav.motors_disarmed_wait()
|
2011-10-30 23:50:34 -03:00
|
|
|
print("MOTORS DISARMED OK")
|
2011-11-09 22:12:43 -04:00
|
|
|
return True
|
2011-11-09 01:43:18 -04:00
|
|
|
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
def takeoff(mavproxy, mav, alt_min=30, takeoff_throttle=1700):
|
|
|
|
"""Takeoff get to 30m altitude."""
|
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2011-11-13 06:20:10 -04:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
2012-07-06 03:48:50 -03:00
|
|
|
mavproxy.send('rc 3 %u\n' % takeoff_throttle)
|
2011-12-16 00:39:05 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
if (m.alt < alt_min):
|
|
|
|
wait_altitude(mav, alt_min, (alt_min + 5))
|
2012-02-19 16:38:57 -04:00
|
|
|
hover(mavproxy, mav)
|
2011-10-30 23:50:34 -03:00
|
|
|
print("TAKEOFF COMPLETE")
|
2011-11-09 22:12:43 -04:00
|
|
|
return True
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# loiter - fly south west, then hold loiter within 5m position and altitude
|
2014-04-07 10:25:38 -03:00
|
|
|
def loiter(mavproxy, mav, holdtime=10, maxaltchange=5, maxdistchange=5):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Hold loiter position."""
|
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2011-11-13 06:20:10 -04:00
|
|
|
wait_mode(mav, 'LOITER')
|
2013-05-02 23:22:15 -03:00
|
|
|
|
|
|
|
# first aim south east
|
|
|
|
print("turn south east")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-05-02 23:22:15 -03:00
|
|
|
if not wait_heading(mav, 170):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# fly south east 50m
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 2 1100\n')
|
|
|
|
if not wait_distance(mav, 50):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
# wait for copter to slow moving
|
|
|
|
if not wait_groundspeed(mav, 0, 2):
|
|
|
|
return False
|
|
|
|
|
2015-04-08 00:15:14 -03:00
|
|
|
success = True
|
2011-10-30 23:50:34 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
start_altitude = m.alt
|
2012-04-27 00:32:22 -03:00
|
|
|
start = mav.location()
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
tholdstart = get_sim_time(mav)
|
2011-10-30 23:50:34 -03:00
|
|
|
print("Holding loiter at %u meters for %u seconds" % (start_altitude, holdtime))
|
2015-04-07 20:25:11 -03:00
|
|
|
while get_sim_time(mav) < tstart + holdtime:
|
2011-10-30 23:50:34 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
2012-04-27 00:32:22 -03:00
|
|
|
pos = mav.location()
|
2011-12-16 00:39:05 -04:00
|
|
|
delta = get_distance(start, pos)
|
2015-04-08 00:15:14 -03:00
|
|
|
alt_delta = math.fabs(m.alt - start_altitude)
|
2011-12-16 00:39:05 -04:00
|
|
|
print("Loiter Dist: %.2fm, alt:%u" % (delta, m.alt))
|
2015-04-08 00:15:14 -03:00
|
|
|
if alt_delta > maxaltchange:
|
|
|
|
print("Loiter alt shifted %u meters (> limit of %u)" % (alt_delta, maxaltchange))
|
|
|
|
success = False
|
2013-05-02 23:22:15 -03:00
|
|
|
if delta > maxdistchange:
|
2015-04-08 00:15:14 -03:00
|
|
|
print("Loiter shifted %u meters (> limit of %u)" % (delta, maxdistchange))
|
|
|
|
success = False
|
|
|
|
if success:
|
|
|
|
print("Loiter OK for %u seconds" % holdtime)
|
|
|
|
else:
|
|
|
|
print("Loiter FAILED")
|
|
|
|
return success
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2012-08-19 00:33:21 -03:00
|
|
|
def change_alt(mavproxy, mav, alt_min, climb_throttle=1920, descend_throttle=1080):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Change altitude."""
|
2011-12-16 00:39:05 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
if(m.alt < alt_min):
|
|
|
|
print("Rise to alt:%u from %u" % (alt_min, m.alt))
|
2012-07-06 03:48:50 -03:00
|
|
|
mavproxy.send('rc 3 %u\n' % climb_throttle)
|
2011-12-16 00:39:05 -04:00
|
|
|
wait_altitude(mav, alt_min, (alt_min + 5))
|
|
|
|
else:
|
|
|
|
print("Lower to alt:%u from %u" % (alt_min, m.alt))
|
2012-07-06 03:48:50 -03:00
|
|
|
mavproxy.send('rc 3 %u\n' % descend_throttle)
|
2016-07-31 07:22:06 -03:00
|
|
|
wait_altitude(mav, (alt_min - 5), alt_min)
|
2012-02-19 16:38:57 -04:00
|
|
|
hover(mavproxy, mav)
|
2011-12-16 00:39:05 -04:00
|
|
|
return True
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# fly a square in stabilize mode
|
2015-04-08 00:15:14 -03:00
|
|
|
def fly_square(mavproxy, mav, side=50, timeout=300):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Fly a square, flying N then E ."""
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
2015-04-08 00:15:14 -03:00
|
|
|
success = True
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# ensure all sticks in the middle
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
mavproxy.send('rc 3 1500\n')
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# switch to loiter mode temporarily to stop us from rising
|
|
|
|
mavproxy.send('switch 5\n')
|
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
|
|
|
# first aim north
|
|
|
|
print("turn right towards north")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-05-02 23:22:15 -03:00
|
|
|
if not wait_heading(mav, 10):
|
2015-04-08 00:15:14 -03:00
|
|
|
print("Failed to reach heading")
|
|
|
|
success = False
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.send('rc 4 1500\n')
|
2016-10-13 21:40:23 -03:00
|
|
|
mav.recv_match(condition='RC_CHANNELS.chan4_raw==1500', blocking=True)
|
2011-10-31 04:29:52 -03:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# save bottom left corner of box as waypoint
|
|
|
|
print("Save WP 1 & 2")
|
|
|
|
save_wp(mavproxy, mav)
|
|
|
|
|
|
|
|
# switch back to stabilize mode
|
2016-06-03 23:31:55 -03:00
|
|
|
mavproxy.send('rc 3 1500\n')
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('switch 6\n')
|
|
|
|
wait_mode(mav, 'STABILIZE')
|
|
|
|
|
|
|
|
# pitch forward to fly north
|
2011-10-31 04:29:52 -03:00
|
|
|
print("Going north %u meters" % side)
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 2 1300\n')
|
2011-11-09 22:12:43 -04:00
|
|
|
if not wait_distance(mav, side):
|
2016-07-31 07:22:06 -03:00
|
|
|
print("Failed to reach distance of %u" % side)
|
2015-04-08 00:15:14 -03:00
|
|
|
success = False
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# save top left corner of square as waypoint
|
2011-12-16 00:39:05 -04:00
|
|
|
print("Save WP 3")
|
2011-11-13 04:24:25 -04:00
|
|
|
save_wp(mavproxy, mav)
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# roll right to fly east
|
2011-10-31 04:29:52 -03:00
|
|
|
print("Going east %u meters" % side)
|
2012-11-30 17:08:40 -04:00
|
|
|
mavproxy.send('rc 1 1700\n')
|
2011-11-09 22:12:43 -04:00
|
|
|
if not wait_distance(mav, side):
|
2016-07-31 07:22:06 -03:00
|
|
|
print("Failed to reach distance of %u" % side)
|
2015-04-08 00:15:14 -03:00
|
|
|
success = False
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# save top right corner of square as waypoint
|
2011-12-16 00:39:05 -04:00
|
|
|
print("Save WP 4")
|
2011-11-13 04:24:25 -04:00
|
|
|
save_wp(mavproxy, mav)
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# pitch back to fly south
|
2011-10-31 04:29:52 -03:00
|
|
|
print("Going south %u meters" % side)
|
2012-11-30 17:08:40 -04:00
|
|
|
mavproxy.send('rc 2 1700\n')
|
2011-11-09 22:12:43 -04:00
|
|
|
if not wait_distance(mav, side):
|
2016-07-31 07:22:06 -03:00
|
|
|
print("Failed to reach distance of %u" % side)
|
2015-04-08 00:15:14 -03:00
|
|
|
success = False
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.send('rc 2 1500\n')
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# save bottom right corner of square as waypoint
|
2011-12-16 00:39:05 -04:00
|
|
|
print("Save WP 5")
|
2011-11-13 04:24:25 -04:00
|
|
|
save_wp(mavproxy, mav)
|
2011-10-31 04:29:52 -03:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# roll left to fly west
|
2011-10-31 04:29:52 -03:00
|
|
|
print("Going west %u meters" % side)
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 1 1300\n')
|
2011-11-09 22:12:43 -04:00
|
|
|
if not wait_distance(mav, side):
|
2016-07-31 07:22:06 -03:00
|
|
|
print("Failed to reach distance of %u" % side)
|
2015-04-08 00:15:14 -03:00
|
|
|
success = False
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# save bottom left corner of square (should be near home) as waypoint
|
2011-12-16 00:39:05 -04:00
|
|
|
print("Save WP 6")
|
2011-11-13 04:24:25 -04:00
|
|
|
save_wp(mavproxy, mav)
|
|
|
|
|
2015-04-08 00:15:14 -03:00
|
|
|
# descend to 10m
|
|
|
|
print("Descend to 10m in Loiter")
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2015-04-08 00:15:14 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
mavproxy.send('rc 3 1300\n')
|
|
|
|
time_left = timeout - (get_sim_time(mav) - tstart)
|
|
|
|
print("timeleft = %u" % time_left)
|
|
|
|
if time_left < 20:
|
|
|
|
time_left = 20
|
|
|
|
if not wait_altitude(mav, -10, 10, time_left):
|
|
|
|
print("Failed to reach alt of 10m")
|
|
|
|
success = False
|
|
|
|
save_wp(mavproxy, mav)
|
|
|
|
|
|
|
|
return success
|
2011-10-31 04:29:52 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2012-07-06 03:48:50 -03:00
|
|
|
def fly_RTL(mavproxy, mav, side=60, timeout=250):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Return, land."""
|
2012-01-06 02:13:20 -04:00
|
|
|
print("# Enter RTL")
|
|
|
|
mavproxy.send('switch 3\n')
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
while get_sim_time(mav) < tstart + timeout:
|
2012-01-06 02:13:20 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
2012-04-27 00:32:22 -03:00
|
|
|
pos = mav.location()
|
2013-05-02 23:22:15 -03:00
|
|
|
home_distance = get_distance(HOME, pos)
|
|
|
|
print("Alt: %u HomeDistance: %.0f" % (m.alt, home_distance))
|
|
|
|
if(m.alt <= 1 and home_distance < 10):
|
2012-01-06 02:13:20 -04:00
|
|
|
return True
|
2013-05-02 23:22:15 -03:00
|
|
|
return False
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
def fly_throttle_failsafe(mavproxy, mav, side=60, timeout=180):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Fly east, Failsafe, return, land."""
|
2013-05-02 23:22:15 -03:00
|
|
|
|
|
|
|
# switch to loiter mode temporarily to stop us from rising
|
|
|
|
mavproxy.send('switch 5\n')
|
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
|
|
|
# first aim east
|
|
|
|
print("turn east")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-05-02 23:22:15 -03:00
|
|
|
if not wait_heading(mav, 135):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
2012-01-06 02:13:20 -04:00
|
|
|
|
2016-06-03 23:31:55 -03:00
|
|
|
# raise throttle slightly to avoid hitting the ground
|
|
|
|
mavproxy.send('rc 3 1600\n')
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# switch to stabilize mode
|
2012-01-06 14:22:13 -04:00
|
|
|
mavproxy.send('switch 6\n')
|
|
|
|
wait_mode(mav, 'STABILIZE')
|
2012-02-19 16:38:57 -04:00
|
|
|
hover(mavproxy, mav)
|
2012-01-06 14:22:13 -04:00
|
|
|
failed = False
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# fly east 60 meters
|
2012-01-06 14:22:13 -04:00
|
|
|
print("# Going forward %u meters" % side)
|
|
|
|
mavproxy.send('rc 2 1350\n')
|
|
|
|
if not wait_distance(mav, side, 5, 60):
|
|
|
|
failed = True
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# pull throttle low
|
2012-01-06 14:22:13 -04:00
|
|
|
print("# Enter Failsafe")
|
|
|
|
mavproxy.send('rc 3 900\n')
|
2013-07-10 01:03:40 -03:00
|
|
|
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
while get_sim_time(mav) < tstart + timeout:
|
2012-01-06 14:22:13 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
2012-04-27 00:32:22 -03:00
|
|
|
pos = mav.location()
|
2012-02-19 07:51:52 -04:00
|
|
|
home_distance = get_distance(HOME, pos)
|
|
|
|
print("Alt: %u HomeDistance: %.0f" % (m.alt, home_distance))
|
2013-07-10 01:03:40 -03:00
|
|
|
# check if we've reached home
|
2012-02-19 07:51:52 -04:00
|
|
|
if m.alt <= 1 and home_distance < 10:
|
2013-07-10 01:03:40 -03:00
|
|
|
# reduce throttle
|
2012-01-06 14:22:13 -04:00
|
|
|
mavproxy.send('rc 3 1100\n')
|
2013-07-10 01:03:40 -03:00
|
|
|
# switch back to stabilize
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 2\n') # land mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'LAND')
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
|
|
|
print("Reached failsafe home OK")
|
2012-01-06 14:22:13 -04:00
|
|
|
return True
|
2012-07-06 03:48:50 -03:00
|
|
|
print("Failed to land on failsafe RTL - timed out after %u seconds" % timeout)
|
2013-07-10 01:03:40 -03:00
|
|
|
# reduce throttle
|
|
|
|
mavproxy.send('rc 3 1100\n')
|
|
|
|
# switch back to stabilize mode
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 2\n') # land mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'LAND')
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
2012-02-19 07:51:52 -04:00
|
|
|
return False
|
2012-01-06 14:22:13 -04:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-10-02 05:45:10 -03:00
|
|
|
def fly_battery_failsafe(mavproxy, mav, timeout=30):
|
|
|
|
# assume failure
|
|
|
|
success = False
|
|
|
|
|
|
|
|
# switch to loiter mode so that we hold position
|
|
|
|
mavproxy.send('switch 5\n')
|
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
mavproxy.send("rc 3 1500\n")
|
|
|
|
|
|
|
|
# enable battery failsafe
|
|
|
|
mavproxy.send("param set FS_BATT_ENABLE 1\n")
|
|
|
|
|
|
|
|
# trigger low voltage
|
|
|
|
mavproxy.send('param set SIM_BATT_VOLTAGE 10\n')
|
|
|
|
|
|
|
|
# wait for LAND mode
|
2014-04-30 03:16:37 -03:00
|
|
|
new_mode = wait_mode(mav, 'LAND')
|
|
|
|
if new_mode == 'LAND':
|
2013-10-02 05:45:10 -03:00
|
|
|
success = True
|
|
|
|
|
|
|
|
# disable battery failsafe
|
|
|
|
mavproxy.send('param set FS_BATT_ENABLE 0\n')
|
|
|
|
|
|
|
|
# return status
|
|
|
|
if success:
|
|
|
|
print("Successfully entered LAND mode after battery failsafe")
|
|
|
|
else:
|
2014-04-30 03:16:37 -03:00
|
|
|
print("Failed to enter LAND mode after battery failsafe")
|
2013-10-02 05:45:10 -03:00
|
|
|
|
|
|
|
return success
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-05-19 03:32:54 -03:00
|
|
|
# fly_stability_patch - fly south, then hold loiter within 5m position and altitude and reduce 1 motor to 60% efficiency
|
2013-07-10 08:54:12 -03:00
|
|
|
def fly_stability_patch(mavproxy, mav, holdtime=30, maxaltchange=5, maxdistchange=10):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Hold loiter position."""
|
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2013-05-19 03:32:54 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
|
|
|
# first south
|
|
|
|
print("turn south")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-05-19 03:32:54 -03:00
|
|
|
if not wait_heading(mav, 180):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# fly west 80m
|
2013-05-19 03:32:54 -03:00
|
|
|
mavproxy.send('rc 2 1100\n')
|
|
|
|
if not wait_distance(mav, 80):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
# wait for copter to slow moving
|
|
|
|
if not wait_groundspeed(mav, 0, 2):
|
|
|
|
return False
|
|
|
|
|
2015-04-08 00:15:14 -03:00
|
|
|
success = True
|
2013-05-19 03:32:54 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
start_altitude = m.alt
|
|
|
|
start = mav.location()
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
tholdstart = get_sim_time(mav)
|
2013-05-19 03:32:54 -03:00
|
|
|
print("Holding loiter at %u meters for %u seconds" % (start_altitude, holdtime))
|
|
|
|
|
|
|
|
# cut motor 1 to 55% efficiency
|
2016-04-03 22:28:28 -03:00
|
|
|
print("Cutting motor 1 to 60% efficiency")
|
|
|
|
mavproxy.send('param set SIM_ENGINE_MUL 0.60\n')
|
2013-05-19 03:32:54 -03:00
|
|
|
|
2015-04-07 20:25:11 -03:00
|
|
|
while get_sim_time(mav) < tstart + holdtime:
|
2013-05-19 03:32:54 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
pos = mav.location()
|
|
|
|
delta = get_distance(start, pos)
|
2015-04-08 00:15:14 -03:00
|
|
|
alt_delta = math.fabs(m.alt - start_altitude)
|
2013-05-19 03:32:54 -03:00
|
|
|
print("Loiter Dist: %.2fm, alt:%u" % (delta, m.alt))
|
2015-04-08 00:15:14 -03:00
|
|
|
if alt_delta > maxaltchange:
|
|
|
|
print("Loiter alt shifted %u meters (> limit of %u)" % (alt_delta, maxaltchange))
|
|
|
|
success = False
|
2013-05-19 03:32:54 -03:00
|
|
|
if delta > maxdistchange:
|
2015-04-08 00:15:14 -03:00
|
|
|
print("Loiter shifted %u meters (> limit of %u)" % (delta, maxdistchange))
|
|
|
|
success = False
|
|
|
|
|
2013-07-10 08:54:12 -03:00
|
|
|
# restore motor 1 to 100% efficiency
|
|
|
|
mavproxy.send('param set SIM_ENGINE_MUL 1.0\n')
|
2015-04-08 00:15:14 -03:00
|
|
|
|
|
|
|
if success:
|
2016-07-31 07:22:06 -03:00
|
|
|
print("Stability patch and Loiter OK for %u seconds" % holdtime)
|
2015-04-08 00:15:14 -03:00
|
|
|
else:
|
|
|
|
print("Stability Patch FAILED")
|
|
|
|
|
|
|
|
return success
|
2013-05-19 03:32:54 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-05-19 04:19:59 -03:00
|
|
|
# fly_fence_test - fly east until you hit the horizontal circular fence
|
|
|
|
def fly_fence_test(mavproxy, mav, timeout=180):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Hold loiter position."""
|
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2013-05-19 04:19:59 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
2016-06-20 04:46:07 -03:00
|
|
|
# enable fence, disable avoidance
|
2013-05-19 04:19:59 -03:00
|
|
|
mavproxy.send('param set FENCE_ENABLE 1\n')
|
2016-06-20 04:46:07 -03:00
|
|
|
mavproxy.send('param set AVOID_ENABLE 0\n')
|
2013-05-19 04:19:59 -03:00
|
|
|
|
|
|
|
# first east
|
|
|
|
print("turn east")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-05-19 04:19:59 -03:00
|
|
|
if not wait_heading(mav, 160):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
|
|
|
|
# fly forward (east) at least 20m
|
|
|
|
pitching_forward = True
|
|
|
|
mavproxy.send('rc 2 1100\n')
|
|
|
|
if not wait_distance(mav, 20):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# start timer
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
while get_sim_time(mav) < tstart + timeout:
|
2013-05-19 04:19:59 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
pos = mav.location()
|
|
|
|
home_distance = get_distance(HOME, pos)
|
|
|
|
print("Alt: %u HomeDistance: %.0f" % (m.alt, home_distance))
|
|
|
|
# recenter pitch sticks once we reach home so we don't fly off again
|
2016-07-31 07:22:06 -03:00
|
|
|
if pitching_forward and home_distance < 10:
|
2013-05-19 04:19:59 -03:00
|
|
|
pitching_forward = False
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
# disable fence
|
|
|
|
mavproxy.send('param set FENCE_ENABLE 0\n')
|
|
|
|
if m.alt <= 1 and home_distance < 10:
|
2013-07-10 01:03:40 -03:00
|
|
|
# reduce throttle
|
2013-05-19 04:19:59 -03:00
|
|
|
mavproxy.send('rc 3 1000\n')
|
2013-07-10 01:03:40 -03:00
|
|
|
# switch mode to stabilize
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 2\n') # land mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'LAND')
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
|
|
|
print("Reached home OK")
|
2013-05-19 04:19:59 -03:00
|
|
|
return True
|
2016-06-20 04:46:07 -03:00
|
|
|
|
|
|
|
# disable fence, enable avoidance
|
2013-05-19 04:19:59 -03:00
|
|
|
mavproxy.send('param set FENCE_ENABLE 0\n')
|
2016-06-20 04:46:07 -03:00
|
|
|
mavproxy.send('param set AVOID_ENABLE 1\n')
|
|
|
|
|
2013-07-10 01:03:40 -03:00
|
|
|
# reduce throttle
|
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
# switch mode to stabilize
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 2\n') # land mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'LAND')
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 6\n') # stabilize mode
|
2013-07-10 01:03:40 -03:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
|
|
|
print("Fence test failed to reach home - timed out after %u seconds" % timeout)
|
2013-05-19 04:19:59 -03:00
|
|
|
return False
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-09-22 23:45:30 -03:00
|
|
|
def show_gps_and_sim_positions(mavproxy, on_off):
|
2016-07-31 07:22:06 -03:00
|
|
|
if on_off is True:
|
2013-09-22 23:45:30 -03:00
|
|
|
# turn on simulator display of gps and actual position
|
|
|
|
mavproxy.send('map set showgpspos 1\n')
|
|
|
|
mavproxy.send('map set showsimpos 1\n')
|
|
|
|
else:
|
|
|
|
# turn off simulator display of gps and actual position
|
|
|
|
mavproxy.send('map set showgpspos 0\n')
|
|
|
|
mavproxy.send('map set showsimpos 0\n')
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
|
2016-08-01 09:23:53 -03:00
|
|
|
def fly_gps_glitch_loiter_test(mavproxy, mav, use_map=False, timeout=30, max_distance=20):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""fly_gps_glitch_loiter_test.
|
|
|
|
|
|
|
|
Fly south east in loiter and test reaction to gps glitch."""
|
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2013-09-19 03:51:18 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
|
|
|
# turn on simulator display of gps and actual position
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, True)
|
|
|
|
|
2013-09-19 03:51:18 -03:00
|
|
|
# set-up gps glitch array
|
2016-07-31 07:22:06 -03:00
|
|
|
glitch_lat = [0.0002996, 0.0006958, 0.0009431, 0.0009991, 0.0009444, 0.0007716, 0.0006221]
|
|
|
|
glitch_lon = [0.0000717, 0.0000912, 0.0002761, 0.0002626, 0.0002807, 0.0002049, 0.0001304]
|
2013-09-19 03:51:18 -03:00
|
|
|
glitch_num = len(glitch_lat)
|
|
|
|
print("GPS Glitches:")
|
2016-07-31 07:22:06 -03:00
|
|
|
for i in range(1, glitch_num):
|
|
|
|
print("glitch %d %.7f %.7f" % (i, glitch_lat[i], glitch_lon[i]))
|
2013-09-19 03:51:18 -03:00
|
|
|
|
|
|
|
# turn south east
|
|
|
|
print("turn south east")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-09-19 03:51:18 -03:00
|
|
|
if not wait_heading(mav, 150):
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, False)
|
2013-09-19 03:51:18 -03:00
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
|
|
|
|
# fly forward (south east) at least 60m
|
|
|
|
mavproxy.send('rc 2 1100\n')
|
|
|
|
if not wait_distance(mav, 60):
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, False)
|
2013-09-19 03:51:18 -03:00
|
|
|
return False
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
# wait for copter to slow down
|
2015-04-15 05:04:32 -03:00
|
|
|
if not wait_groundspeed(mav, 0, 1):
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, False)
|
2013-09-19 03:51:18 -03:00
|
|
|
return False
|
|
|
|
|
|
|
|
# record time and position
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
2015-04-15 05:04:32 -03:00
|
|
|
tnow = tstart
|
2013-09-19 03:51:18 -03:00
|
|
|
start_pos = sim_location(mav)
|
2015-04-08 00:15:14 -03:00
|
|
|
success = True
|
2013-09-19 03:51:18 -03:00
|
|
|
|
|
|
|
# initialise current glitch
|
2016-07-31 07:22:06 -03:00
|
|
|
glitch_current = 0
|
2013-09-19 03:51:18 -03:00
|
|
|
print("Apply first glitch")
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X %.7f\n' % glitch_lat[glitch_current])
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y %.7f\n' % glitch_lon[glitch_current])
|
|
|
|
|
|
|
|
# record position for 30 seconds
|
2015-04-15 05:04:32 -03:00
|
|
|
while tnow < tstart + timeout:
|
|
|
|
tnow = get_sim_time(mav)
|
|
|
|
desired_glitch_num = int((tnow - tstart) * 2.2)
|
|
|
|
if desired_glitch_num > glitch_current and glitch_current != -1:
|
|
|
|
glitch_current = desired_glitch_num
|
2013-09-19 03:51:18 -03:00
|
|
|
# turn off glitching if we've reached the end of the glitch list
|
|
|
|
if glitch_current >= glitch_num:
|
|
|
|
glitch_current = -1
|
2015-04-15 05:04:32 -03:00
|
|
|
print("Completed Glitches")
|
2013-09-19 03:51:18 -03:00
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X 0\n')
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y 0\n')
|
|
|
|
else:
|
2015-04-15 05:04:32 -03:00
|
|
|
print("Applying glitch %u" % glitch_current)
|
2016-07-31 07:22:06 -03:00
|
|
|
# move onto the next glitch
|
2013-09-19 03:51:18 -03:00
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X %.7f\n' % glitch_lat[glitch_current])
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y %.7f\n' % glitch_lon[glitch_current])
|
|
|
|
|
2015-04-15 05:04:32 -03:00
|
|
|
# start displaying distance moved after all glitches applied
|
|
|
|
if (glitch_current == -1):
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
curr_pos = sim_location(mav)
|
|
|
|
moved_distance = get_distance(curr_pos, start_pos)
|
|
|
|
print("Alt: %u Moved: %.0f" % (m.alt, moved_distance))
|
|
|
|
if moved_distance > max_distance:
|
|
|
|
print("Moved over %u meters, Failed!" % max_distance)
|
|
|
|
success = False
|
2013-09-19 03:51:18 -03:00
|
|
|
|
|
|
|
# disable gps glitch
|
|
|
|
if glitch_current != -1:
|
|
|
|
glitch_current = -1
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X 0\n')
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y 0\n')
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, False)
|
2013-09-19 03:51:18 -03:00
|
|
|
|
2015-04-08 00:15:14 -03:00
|
|
|
if success:
|
|
|
|
print("GPS glitch test passed! stayed within %u meters for %u seconds" % (max_distance, timeout))
|
|
|
|
else:
|
|
|
|
print("GPS glitch test FAILED!")
|
|
|
|
return success
|
2013-09-19 03:51:18 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-09-22 23:45:30 -03:00
|
|
|
# fly_gps_glitch_auto_test - fly mission and test reaction to gps glitch
|
2016-08-01 09:23:53 -03:00
|
|
|
def fly_gps_glitch_auto_test(mavproxy, mav, use_map=False, timeout=120):
|
2013-09-22 23:45:30 -03:00
|
|
|
|
|
|
|
# set-up gps glitch array
|
2016-07-31 07:22:06 -03:00
|
|
|
glitch_lat = [0.0002996, 0.0006958, 0.0009431, 0.0009991, 0.0009444, 0.0007716, 0.0006221]
|
|
|
|
glitch_lon = [0.0000717, 0.0000912, 0.0002761, 0.0002626, 0.0002807, 0.0002049, 0.0001304]
|
2013-09-22 23:45:30 -03:00
|
|
|
glitch_num = len(glitch_lat)
|
|
|
|
print("GPS Glitches:")
|
2016-07-31 07:22:06 -03:00
|
|
|
for i in range(1, glitch_num):
|
|
|
|
print("glitch %d %.7f %.7f" % (i, glitch_lat[i], glitch_lon[i]))
|
2013-09-22 23:45:30 -03:00
|
|
|
|
|
|
|
# Fly mission #1
|
2014-11-05 04:28:36 -04:00
|
|
|
print("# Load copter_glitch_mission")
|
2013-09-22 23:45:30 -03:00
|
|
|
if not load_mission_from_file(mavproxy, mav, os.path.join(testdir, "copter_glitch_mission.txt")):
|
|
|
|
print("load copter_glitch_mission failed")
|
|
|
|
return False
|
|
|
|
|
|
|
|
# turn on simulator display of gps and actual position
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, True)
|
2013-09-22 23:45:30 -03:00
|
|
|
|
|
|
|
# load the waypoint count
|
|
|
|
global homeloc
|
|
|
|
global num_wp
|
|
|
|
print("test: Fly a mission from 1 to %u" % num_wp)
|
|
|
|
mavproxy.send('wp set 1\n')
|
|
|
|
|
|
|
|
# switch into AUTO mode and raise throttle
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 4\n') # auto mode
|
2013-09-22 23:45:30 -03:00
|
|
|
wait_mode(mav, 'AUTO')
|
|
|
|
mavproxy.send('rc 3 1500\n')
|
|
|
|
|
|
|
|
# wait until 100m from home
|
2013-09-26 02:43:04 -03:00
|
|
|
if not wait_distance(mav, 100, 5, 60):
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, False)
|
2013-09-22 23:45:30 -03:00
|
|
|
return False
|
|
|
|
|
|
|
|
# record time and position
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
2015-04-15 05:04:32 -03:00
|
|
|
tnow = tstart
|
2013-09-22 23:45:30 -03:00
|
|
|
|
|
|
|
# initialise current glitch
|
2016-07-31 07:22:06 -03:00
|
|
|
glitch_current = 0
|
2013-09-22 23:45:30 -03:00
|
|
|
print("Apply first glitch")
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X %.7f\n' % glitch_lat[glitch_current])
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y %.7f\n' % glitch_lon[glitch_current])
|
|
|
|
|
|
|
|
# record position for 30 seconds
|
|
|
|
while glitch_current < glitch_num:
|
2015-04-15 05:04:32 -03:00
|
|
|
tnow = get_sim_time(mav)
|
2016-04-21 02:25:18 -03:00
|
|
|
desired_glitch_num = int((tnow - tstart) * 2.2)
|
2015-04-15 05:04:32 -03:00
|
|
|
if desired_glitch_num > glitch_current and glitch_current != -1:
|
|
|
|
glitch_current = desired_glitch_num
|
2013-09-22 23:45:30 -03:00
|
|
|
# apply next glitch
|
|
|
|
if glitch_current < glitch_num:
|
2015-04-15 05:04:32 -03:00
|
|
|
print("Applying glitch %u" % glitch_current)
|
2013-09-22 23:45:30 -03:00
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X %.7f\n' % glitch_lat[glitch_current])
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y %.7f\n' % glitch_lon[glitch_current])
|
|
|
|
|
|
|
|
# turn off glitching
|
2015-04-15 05:04:32 -03:00
|
|
|
print("Completed Glitches")
|
2013-09-22 23:45:30 -03:00
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_X 0\n')
|
|
|
|
mavproxy.send('param set SIM_GPS_GLITCH_Y 0\n')
|
|
|
|
|
|
|
|
# continue with the mission
|
2016-05-11 20:06:12 -03:00
|
|
|
ret = wait_waypoint(mav, 0, num_wp-1, timeout=500)
|
2014-04-07 10:25:38 -03:00
|
|
|
|
|
|
|
# wait for arrival back home
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
pos = mav.location()
|
|
|
|
dist_to_home = get_distance(HOME, pos)
|
|
|
|
while dist_to_home > 5:
|
2015-10-12 02:17:59 -03:00
|
|
|
if get_sim_time(mav) > (tstart + timeout):
|
|
|
|
print("GPS Glitch testing failed - exceeded timeout %u seconds" % timeout)
|
|
|
|
ret = False
|
|
|
|
break
|
2014-04-07 10:25:38 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
pos = mav.location()
|
|
|
|
dist_to_home = get_distance(HOME, pos)
|
|
|
|
print("Dist from home: %u" % dist_to_home)
|
2013-09-22 23:45:30 -03:00
|
|
|
|
|
|
|
# turn off simulator display of gps and actual position
|
2016-08-01 09:23:53 -03:00
|
|
|
if (use_map):
|
|
|
|
show_gps_and_sim_positions(mavproxy, False)
|
2013-09-22 23:45:30 -03:00
|
|
|
|
|
|
|
print("GPS Glitch test Auto completed: passed=%s" % ret)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
# fly_simple - assumes the simple bearing is initialised to be directly north
|
2013-05-02 23:22:15 -03:00
|
|
|
# flies a box with 100m west, 15 seconds north, 50 seconds east, 15 seconds south
|
2013-10-05 10:23:19 -03:00
|
|
|
def fly_simple(mavproxy, mav, side=50, timeout=120):
|
2013-05-02 23:22:15 -03:00
|
|
|
|
2013-10-05 06:25:17 -03:00
|
|
|
failed = False
|
|
|
|
|
|
|
|
# hold position in loiter
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2013-10-05 06:25:17 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# set SIMPLE mode for all flight modes
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('param set SIMPLE 63\n')
|
2012-01-06 02:13:20 -04:00
|
|
|
|
2013-07-10 01:03:40 -03:00
|
|
|
# switch to stabilize mode
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy.send('switch 6\n')
|
2011-11-13 06:20:10 -04:00
|
|
|
wait_mode(mav, 'STABILIZE')
|
2016-06-03 23:31:55 -03:00
|
|
|
mavproxy.send('rc 3 1500\n')
|
2012-02-19 18:20:51 -04:00
|
|
|
|
2013-10-05 10:23:19 -03:00
|
|
|
# fly south 50m
|
|
|
|
print("# Flying south %u meters" % side)
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 1 1300\n')
|
|
|
|
if not wait_distance(mav, side, 5, 60):
|
2011-12-16 00:39:05 -04:00
|
|
|
failed = True
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
2011-10-31 04:29:52 -03:00
|
|
|
|
2013-10-05 10:23:19 -03:00
|
|
|
# fly west 8 seconds
|
|
|
|
print("# Flying west for 8 seconds")
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 2 1300\n')
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
while get_sim_time(mav) < (tstart + 8):
|
2011-12-16 00:39:05 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
2015-04-07 20:25:11 -03:00
|
|
|
delta = (get_sim_time(mav) - tstart)
|
2016-07-31 07:22:06 -03:00
|
|
|
# print("%u" % delta)
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
2013-10-05 10:23:19 -03:00
|
|
|
# fly north 25 meters
|
|
|
|
print("# Flying north %u meters" % (side/2.0))
|
2013-05-02 23:22:15 -03:00
|
|
|
mavproxy.send('rc 1 1700\n')
|
|
|
|
if not wait_distance(mav, side/2, 5, 60):
|
|
|
|
failed = True
|
2011-12-16 00:39:05 -04:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-10-05 10:23:19 -03:00
|
|
|
# fly east 8 seconds
|
|
|
|
print("# Flying east for 8 seconds")
|
2012-11-30 17:08:40 -04:00
|
|
|
mavproxy.send('rc 2 1700\n')
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
while get_sim_time(mav) < (tstart + 8):
|
2013-05-02 23:22:15 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
2015-04-07 20:25:11 -03:00
|
|
|
delta = (get_sim_time(mav) - tstart)
|
2016-07-31 07:22:06 -03:00
|
|
|
# print("%u" % delta)
|
2011-12-16 00:39:05 -04:00
|
|
|
mavproxy.send('rc 2 1500\n')
|
2013-05-02 23:22:15 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# restore to default
|
2011-12-16 00:39:05 -04:00
|
|
|
mavproxy.send('param set SIMPLE 0\n')
|
2013-05-02 23:22:15 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# hover in place
|
2012-02-19 16:38:57 -04:00
|
|
|
hover(mavproxy, mav)
|
2011-12-16 00:39:05 -04:00
|
|
|
return not failed
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
# fly_super_simple - flies a circle around home for 45 seconds
|
2013-10-05 10:23:19 -03:00
|
|
|
def fly_super_simple(mavproxy, mav, timeout=45):
|
2013-10-05 06:25:17 -03:00
|
|
|
|
|
|
|
failed = False
|
|
|
|
|
|
|
|
# hold position in loiter
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2013-10-05 06:25:17 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
|
2013-10-05 10:23:19 -03:00
|
|
|
# fly forward 20m
|
2013-10-05 06:25:17 -03:00
|
|
|
print("# Flying forward 20 meters")
|
|
|
|
mavproxy.send('rc 2 1300\n')
|
|
|
|
if not wait_distance(mav, 20, 5, 60):
|
|
|
|
failed = True
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# set SUPER SIMPLE mode for all flight modes
|
2013-10-05 06:25:17 -03:00
|
|
|
mavproxy.send('param set SUPER_SIMPLE 63\n')
|
|
|
|
|
|
|
|
# switch to stabilize mode
|
|
|
|
mavproxy.send('switch 6\n')
|
|
|
|
wait_mode(mav, 'STABILIZE')
|
2016-06-03 23:31:55 -03:00
|
|
|
mavproxy.send('rc 3 1500\n')
|
2013-10-05 06:25:17 -03:00
|
|
|
|
|
|
|
# start copter yawing slowly
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1550\n')
|
2013-10-05 06:25:17 -03:00
|
|
|
|
|
|
|
# roll left for timeout seconds
|
|
|
|
print("# rolling left from pilot's point of view for %u seconds" % timeout)
|
|
|
|
mavproxy.send('rc 1 1300\n')
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
while get_sim_time(mav) < (tstart + timeout):
|
2013-10-05 06:25:17 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
2015-04-07 20:25:11 -03:00
|
|
|
delta = (get_sim_time(mav) - tstart)
|
2013-10-05 06:25:17 -03:00
|
|
|
|
|
|
|
# stop rolling and yawing
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# restore simple mode parameters to default
|
2013-10-05 06:25:17 -03:00
|
|
|
mavproxy.send('param set SUPER_SIMPLE 0\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# hover in place
|
2013-10-05 06:25:17 -03:00
|
|
|
hover(mavproxy, mav)
|
|
|
|
return not failed
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
# fly_circle - flies a circle with 20m radius
|
2013-06-27 04:55:52 -03:00
|
|
|
def fly_circle(mavproxy, mav, maxaltchange=10, holdtime=36):
|
2011-12-16 00:39:05 -04:00
|
|
|
|
2013-07-10 01:03:40 -03:00
|
|
|
# hold position in loiter
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2013-06-01 06:20:57 -03:00
|
|
|
wait_mode(mav, 'LOITER')
|
2011-11-13 08:50:04 -04:00
|
|
|
|
2013-06-01 06:20:57 -03:00
|
|
|
# face west
|
|
|
|
print("turn west")
|
2016-11-06 21:00:24 -04:00
|
|
|
mavproxy.send('rc 4 1580\n')
|
2013-06-01 06:20:57 -03:00
|
|
|
if not wait_heading(mav, 270):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# set CIRCLE radius
|
2014-02-14 02:50:17 -04:00
|
|
|
mavproxy.send('param set CIRCLE_RADIUS 3000\n')
|
2013-06-01 06:20:57 -03:00
|
|
|
|
|
|
|
# fly forward (east) at least 100m
|
|
|
|
mavproxy.send('rc 2 1100\n')
|
|
|
|
if not wait_distance(mav, 100):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# return pitch stick back to middle
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
2011-11-01 08:31:01 -03:00
|
|
|
|
2013-06-01 06:20:57 -03:00
|
|
|
# set CIRCLE mode
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 1\n') # circle mode
|
2011-11-13 08:50:04 -04:00
|
|
|
wait_mode(mav, 'CIRCLE')
|
2013-06-01 06:20:57 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# wait
|
2011-11-13 04:24:25 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
start_altitude = m.alt
|
2015-04-07 20:25:11 -03:00
|
|
|
tstart = get_sim_time(mav)
|
|
|
|
tholdstart = get_sim_time(mav)
|
2011-11-13 04:24:25 -04:00
|
|
|
print("Circle at %u meters for %u seconds" % (start_altitude, holdtime))
|
2015-04-07 20:25:11 -03:00
|
|
|
while get_sim_time(mav) < tstart + holdtime:
|
2011-11-13 04:24:25 -04:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
print("heading %u" % m.heading)
|
2011-11-01 08:31:01 -03:00
|
|
|
|
2011-11-13 04:24:25 -04:00
|
|
|
print("CIRCLE OK for %u seconds" % holdtime)
|
|
|
|
return True
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2014-04-07 10:25:38 -03:00
|
|
|
# fly_auto_test - fly mission which tests a significant number of commands
|
|
|
|
def fly_auto_test(mavproxy, mav):
|
|
|
|
|
|
|
|
# Fly mission #1
|
2014-11-05 04:28:36 -04:00
|
|
|
print("# Load copter_mission")
|
2014-04-07 10:25:38 -03:00
|
|
|
if not load_mission_from_file(mavproxy, mav, os.path.join(testdir, "copter_mission.txt")):
|
|
|
|
print("load copter_mission failed")
|
|
|
|
return False
|
|
|
|
|
|
|
|
# load the waypoint count
|
|
|
|
global homeloc
|
|
|
|
global num_wp
|
|
|
|
print("test: Fly a mission from 1 to %u" % num_wp)
|
|
|
|
mavproxy.send('wp set 1\n')
|
|
|
|
|
|
|
|
# switch into AUTO mode and raise throttle
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 4\n') # auto mode
|
2014-04-07 10:25:38 -03:00
|
|
|
wait_mode(mav, 'AUTO')
|
|
|
|
mavproxy.send('rc 3 1500\n')
|
|
|
|
|
|
|
|
# fly the mission
|
2016-05-11 20:06:12 -03:00
|
|
|
ret = wait_waypoint(mav, 0, num_wp-1, timeout=500)
|
2014-04-07 10:25:38 -03:00
|
|
|
|
2016-05-12 03:52:02 -03:00
|
|
|
# land if mission failed
|
2016-07-31 07:22:06 -03:00
|
|
|
if ret is False:
|
2016-05-12 03:52:02 -03:00
|
|
|
land(mavproxy, mav)
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2014-04-07 10:25:38 -03:00
|
|
|
# set throttle to minimum
|
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
|
|
|
|
# wait for disarm
|
|
|
|
mav.motors_disarmed_wait()
|
|
|
|
print("MOTORS DISARMED OK")
|
|
|
|
|
|
|
|
print("Auto mission completed: passed=%s" % ret)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2014-04-07 23:00:47 -03:00
|
|
|
# fly_avc_test - fly AVC mission
|
|
|
|
def fly_avc_test(mavproxy, mav):
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2014-04-07 23:00:47 -03:00
|
|
|
# upload mission from file
|
2014-11-05 04:28:36 -04:00
|
|
|
print("# Load copter_AVC2013_mission")
|
2014-04-07 23:00:47 -03:00
|
|
|
if not load_mission_from_file(mavproxy, mav, os.path.join(testdir, "copter_AVC2013_mission.txt")):
|
2014-11-05 04:28:36 -04:00
|
|
|
print("load copter_AVC2013_mission failed")
|
2014-04-07 23:00:47 -03:00
|
|
|
return False
|
|
|
|
|
|
|
|
# load the waypoint count
|
|
|
|
global homeloc
|
|
|
|
global num_wp
|
|
|
|
print("Fly AVC mission from 1 to %u" % num_wp)
|
|
|
|
mavproxy.send('wp set 1\n')
|
|
|
|
|
|
|
|
# switch into AUTO mode and raise throttle
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 4\n') # auto mode
|
2014-04-07 23:00:47 -03:00
|
|
|
wait_mode(mav, 'AUTO')
|
|
|
|
mavproxy.send('rc 3 1500\n')
|
|
|
|
|
|
|
|
# fly the mission
|
2016-05-11 20:06:12 -03:00
|
|
|
ret = wait_waypoint(mav, 0, num_wp-1, timeout=500)
|
2014-04-07 23:00:47 -03:00
|
|
|
|
|
|
|
# set throttle to minimum
|
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
|
|
|
|
# wait for disarm
|
|
|
|
mav.motors_disarmed_wait()
|
|
|
|
print("MOTORS DISARMED OK")
|
|
|
|
|
|
|
|
print("AVC mission completed: passed=%s" % ret)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-06-01 06:20:57 -03:00
|
|
|
def land(mavproxy, mav, timeout=60):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Land the quad."""
|
2013-06-01 06:20:57 -03:00
|
|
|
print("STARTING LANDING")
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 2\n') # land mode
|
2013-06-01 06:20:57 -03:00
|
|
|
wait_mode(mav, 'LAND')
|
|
|
|
print("Entered Landing Mode")
|
|
|
|
ret = wait_altitude(mav, -5, 1)
|
|
|
|
print("LANDING: ok= %s" % ret)
|
|
|
|
return ret
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
def fly_mission(mavproxy, mav, height_accuracy=-1.0, target_altitude=None):
|
|
|
|
"""Fly a mission from a file."""
|
2011-11-01 20:26:24 -03:00
|
|
|
global homeloc
|
2011-11-13 04:24:25 -04:00
|
|
|
global num_wp
|
2011-11-28 14:25:16 -04:00
|
|
|
print("test: Fly a mission from 1 to %u" % num_wp)
|
|
|
|
mavproxy.send('wp set 1\n')
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 4\n') # auto mode
|
2011-11-13 08:50:04 -04:00
|
|
|
wait_mode(mav, 'AUTO')
|
2016-05-11 20:06:12 -03:00
|
|
|
ret = wait_waypoint(mav, 0, num_wp-1, timeout=500)
|
2015-11-29 06:46:31 -04:00
|
|
|
expect_msg = "Reached command #%u" % (num_wp-1)
|
2014-11-05 04:28:36 -04:00
|
|
|
if (ret):
|
|
|
|
mavproxy.expect(expect_msg)
|
2011-11-14 02:56:33 -04:00
|
|
|
print("test: MISSION COMPLETE: passed=%s" % ret)
|
2011-11-13 08:50:04 -04:00
|
|
|
# wait here until ready
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('switch 5\n') # loiter mode
|
2011-11-13 08:50:04 -04:00
|
|
|
wait_mode(mav, 'LOITER')
|
|
|
|
return ret
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2011-11-14 02:56:33 -04:00
|
|
|
def load_mission_from_file(mavproxy, mav, filename):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Load a mission from a file to flight controller."""
|
2011-11-14 02:56:33 -04:00
|
|
|
global num_wp
|
2011-11-01 08:31:01 -03:00
|
|
|
mavproxy.send('wp load %s\n' % filename)
|
2015-11-25 21:52:19 -04:00
|
|
|
mavproxy.expect('Flight plan received')
|
2011-11-01 08:31:01 -03:00
|
|
|
mavproxy.send('wp list\n')
|
|
|
|
mavproxy.expect('Requesting [0-9]+ waypoints')
|
2014-11-05 04:28:36 -04:00
|
|
|
|
|
|
|
# update num_wp
|
|
|
|
wploader = mavwp.MAVWPLoader()
|
|
|
|
wploader.load(filename)
|
|
|
|
num_wp = wploader.count()
|
2011-11-14 02:56:33 -04:00
|
|
|
return True
|
2011-11-01 08:31:01 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2011-11-14 02:56:33 -04:00
|
|
|
def save_mission_to_file(mavproxy, mav, filename):
|
|
|
|
global num_wp
|
|
|
|
mavproxy.send('wp save %s\n' % filename)
|
|
|
|
mavproxy.expect('Saved ([0-9]+) waypoints')
|
|
|
|
num_wp = int(mavproxy.match.group(1))
|
|
|
|
print("num_wp: %d" % num_wp)
|
2011-11-13 08:50:04 -04:00
|
|
|
return True
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2011-10-30 23:50:34 -03:00
|
|
|
def setup_rc(mavproxy):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Setup RC override control."""
|
|
|
|
for chan in range(1, 9):
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy.send('rc %u 1500\n' % chan)
|
|
|
|
# zero throttle
|
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2016-10-09 21:09:47 -03:00
|
|
|
def fly_ArduCopter(binary, viewerip=None, use_map=False, valgrind=False, gdb=False, frame='+', params_file=None):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Fly ArduCopter in SITL.
|
2011-11-10 17:03:27 -04:00
|
|
|
|
|
|
|
you can pass viewerip as an IP address to optionally send fg and
|
|
|
|
mavproxy packets too for local viewing of the flight in real time
|
2016-07-31 07:22:06 -03:00
|
|
|
"""
|
2011-12-02 00:21:15 -04:00
|
|
|
global homeloc
|
2011-11-01 08:31:01 -03:00
|
|
|
|
2015-05-05 03:32:14 -03:00
|
|
|
home = "%f,%f,%u,%u" % (HOME.lat, HOME.lng, HOME.alt, HOME.heading)
|
2016-10-09 21:09:47 -03:00
|
|
|
sitl = util.start_SITL(binary, wipe=True, model=frame, home=home, speedup=speedup_default)
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy = util.start_MAVProxy_SITL('ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter')
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.expect('Received [0-9]+ parameters')
|
|
|
|
|
|
|
|
# setup test parameters
|
2016-10-09 21:09:47 -03:00
|
|
|
if params_file is None:
|
|
|
|
params_file = "{testdir}/default_params/copter.parm"
|
|
|
|
mavproxy.send("param load %s\n" % params_file.format(testdir=testdir))
|
2011-10-31 04:29:52 -03:00
|
|
|
mavproxy.expect('Loaded [0-9]+ parameters')
|
2016-05-27 07:54:12 -03:00
|
|
|
mavproxy.send("param set LOG_REPLAY 1\n")
|
|
|
|
mavproxy.send("param set LOG_DISARMED 1\n")
|
|
|
|
time.sleep(3)
|
2011-10-31 04:29:52 -03:00
|
|
|
|
|
|
|
# reboot with new parameters
|
2011-11-09 00:45:18 -04:00
|
|
|
util.pexpect_close(mavproxy)
|
2016-07-31 07:22:06 -03:00
|
|
|
util.pexpect_close(sitl)
|
2011-11-28 14:25:16 -04:00
|
|
|
|
2016-10-09 21:09:47 -03:00
|
|
|
sitl = util.start_SITL(binary, model=frame, home=home, speedup=speedup_default, valgrind=valgrind, gdb=gdb)
|
2011-12-12 08:07:46 -04:00
|
|
|
options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter --streamrate=5'
|
2011-11-10 17:03:27 -04:00
|
|
|
if viewerip:
|
|
|
|
options += ' --out=%s:14550' % viewerip
|
2016-08-01 09:23:53 -03:00
|
|
|
if use_map:
|
2013-05-29 02:33:32 -03:00
|
|
|
options += ' --map'
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy = util.start_MAVProxy_SITL('ArduCopter', options=options)
|
2015-06-30 01:06:17 -03:00
|
|
|
mavproxy.expect('Telemetry log: (\S+)')
|
2011-10-30 23:50:34 -03:00
|
|
|
logfile = mavproxy.match.group(1)
|
|
|
|
print("LOGFILE %s" % logfile)
|
2011-11-09 05:27:36 -04:00
|
|
|
|
2013-04-28 02:01:31 -03:00
|
|
|
buildlog = util.reltopdir("../buildlogs/ArduCopter-test.tlog")
|
2011-11-09 05:27:36 -04:00
|
|
|
print("buildlog=%s" % buildlog)
|
2016-07-31 07:22:06 -03:00
|
|
|
copy_tlog = False
|
2011-11-09 05:27:36 -04:00
|
|
|
if os.path.exists(buildlog):
|
|
|
|
os.unlink(buildlog)
|
2013-06-24 00:06:11 -03:00
|
|
|
try:
|
|
|
|
os.link(logfile, buildlog)
|
|
|
|
except Exception:
|
2016-07-31 07:22:06 -03:00
|
|
|
print("WARN: Failed to create symlink: " + logfile + " => " + buildlog + ", Will copy tlog manually to target location")
|
|
|
|
copy_tlog = True
|
2011-11-09 05:27:36 -04:00
|
|
|
|
2012-01-09 03:07:51 -04:00
|
|
|
# the received parameters can come before or after the ready to fly message
|
|
|
|
mavproxy.expect(['Received [0-9]+ parameters', 'Ready to FLY'])
|
|
|
|
mavproxy.expect(['Received [0-9]+ parameters', 'Ready to FLY'])
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2011-11-01 08:31:01 -03:00
|
|
|
util.expect_setup_callback(mavproxy, expect_callback)
|
|
|
|
|
2011-12-02 00:21:15 -04:00
|
|
|
expect_list_clear()
|
2016-07-31 07:22:06 -03:00
|
|
|
expect_list_extend([sitl, mavproxy])
|
2011-11-01 08:31:01 -03:00
|
|
|
|
2011-10-30 23:50:34 -03:00
|
|
|
# get a mavlink connection going
|
2011-11-09 05:27:36 -04:00
|
|
|
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:
|
2011-11-09 05:27:36 -04:00
|
|
|
print("Failed to start mavlink connection on 127.0.0.1:19550" % msg)
|
|
|
|
raise
|
2011-11-01 08:31:01 -03:00
|
|
|
mav.message_hooks.append(message_hook)
|
2011-11-27 22:52:54 -04:00
|
|
|
mav.idle_hooks.append(idle_hook)
|
2011-10-30 23:50:34 -03:00
|
|
|
|
|
|
|
failed = False
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "None"
|
|
|
|
|
2011-10-30 23:50:34 -03:00
|
|
|
try:
|
|
|
|
mav.wait_heartbeat()
|
|
|
|
setup_rc(mavproxy)
|
2012-04-27 00:32:22 -03:00
|
|
|
homeloc = mav.location()
|
2011-12-12 07:07:53 -04:00
|
|
|
|
2016-07-04 21:45:33 -03:00
|
|
|
# wait for EKF and GPS checks to pass
|
|
|
|
wait_seconds(mav, 30)
|
2015-03-13 23:03:15 -03:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Arm
|
2011-12-16 00:39:05 -04:00
|
|
|
print("# Arm motors")
|
2011-11-13 06:14:58 -04:00
|
|
|
if not arm_motors(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "arm_motors failed"
|
|
|
|
print(failed_test_msg)
|
2011-11-09 22:12:43 -04:00
|
|
|
failed = True
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2011-12-16 00:39:05 -04:00
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-09-19 03:51:18 -03:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Fly a square in Stabilize mode
|
|
|
|
print("#")
|
2013-10-05 06:25:17 -03:00
|
|
|
print("########## Fly a square and save WPs with CH7 switch ##########")
|
2013-05-02 23:22:15 -03:00
|
|
|
print("#")
|
|
|
|
if not fly_square(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_square failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-02 23:22:15 -03:00
|
|
|
failed = True
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# save the stored mission to file
|
|
|
|
print("# Save out the CH7 mission to file")
|
|
|
|
if not save_mission_to_file(mavproxy, mav, os.path.join(testdir, "ch7_mission.txt")):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "save_mission_to_file failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-02 23:22:15 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# fly the stored mission
|
|
|
|
print("# Fly CH7 saved mission")
|
2016-07-31 07:22:06 -03:00
|
|
|
if not fly_mission(mavproxy, mav, height_accuracy=0.5, target_altitude=10):
|
2014-11-05 04:28:36 -04:00
|
|
|
failed_test_msg = "fly ch7_mission failed"
|
2014-04-30 03:16:37 -03:00
|
|
|
print(failed_test_msg)
|
2012-01-06 02:13:20 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Throttle Failsafe
|
|
|
|
print("#")
|
|
|
|
print("########## Test Failsafe ##########")
|
|
|
|
print("#")
|
|
|
|
if not fly_throttle_failsafe(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_throttle_failsafe failed"
|
|
|
|
print(failed_test_msg)
|
2012-01-06 14:22:13 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Takeoff
|
2012-01-06 14:22:13 -04:00
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2012-01-06 14:22:13 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-10-02 05:45:10 -03:00
|
|
|
# Battery failsafe
|
|
|
|
if not fly_battery_failsafe(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_battery_failsafe failed"
|
|
|
|
print(failed_test_msg)
|
2013-10-02 05:45:10 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# Takeoff
|
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-10-02 05:45:10 -03:00
|
|
|
failed = True
|
|
|
|
|
2013-05-19 04:19:59 -03:00
|
|
|
# Stability patch
|
|
|
|
print("#")
|
|
|
|
print("########## Test Stability Patch ##########")
|
|
|
|
print("#")
|
|
|
|
if not fly_stability_patch(mavproxy, mav, 30):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_stability_patch failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-19 04:19:59 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# RTL
|
|
|
|
print("# RTL #")
|
|
|
|
if not fly_RTL(mavproxy, mav):
|
2015-04-16 03:03:13 -03:00
|
|
|
failed_test_msg = "fly_RTL after stab patch failed"
|
2014-04-30 03:16:37 -03:00
|
|
|
print(failed_test_msg)
|
2013-05-19 04:19:59 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# Takeoff
|
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-19 04:19:59 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# Fence test
|
|
|
|
print("#")
|
|
|
|
print("########## Test Horizontal Fence ##########")
|
|
|
|
print("#")
|
|
|
|
if not fly_fence_test(mavproxy, mav, 180):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_fence_test failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-19 04:19:59 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# Takeoff
|
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-19 04:19:59 -03:00
|
|
|
failed = True
|
|
|
|
|
2013-09-22 23:45:30 -03:00
|
|
|
# Fly GPS Glitch Loiter test
|
|
|
|
print("# GPS Glitch Loiter Test")
|
2016-08-01 09:23:53 -03:00
|
|
|
if not fly_gps_glitch_loiter_test(mavproxy, mav, use_map):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_gps_glitch_loiter_test failed"
|
|
|
|
print(failed_test_msg)
|
2013-09-22 23:45:30 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# RTL after GPS Glitch Loiter test
|
|
|
|
print("# RTL #")
|
|
|
|
if not fly_RTL(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_RTL failed"
|
|
|
|
print(failed_test_msg)
|
2013-09-22 23:45:30 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# Fly GPS Glitch test in auto mode
|
|
|
|
print("# GPS Glitch Auto Test")
|
2016-08-01 09:23:53 -03:00
|
|
|
if not fly_gps_glitch_auto_test(mavproxy, mav, use_map):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_gps_glitch_auto_test failed"
|
|
|
|
print(failed_test_msg)
|
2013-09-22 23:45:30 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# take-off ahead of next test
|
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-09-22 23:45:30 -03:00
|
|
|
failed = True
|
|
|
|
|
2014-04-07 10:25:38 -03:00
|
|
|
# Loiter for 10 seconds
|
2013-05-02 23:22:15 -03:00
|
|
|
print("#")
|
2014-04-07 10:25:38 -03:00
|
|
|
print("########## Test Loiter for 10 seconds ##########")
|
2013-05-02 23:22:15 -03:00
|
|
|
print("#")
|
2013-10-09 01:02:38 -03:00
|
|
|
if not loiter(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "loiter failed"
|
|
|
|
print(failed_test_msg)
|
2011-12-16 00:39:05 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Loiter Climb
|
|
|
|
print("#")
|
2014-04-07 10:25:38 -03:00
|
|
|
print("# Loiter - climb to 30m")
|
2013-05-02 23:22:15 -03:00
|
|
|
print("#")
|
2014-04-07 10:25:38 -03:00
|
|
|
if not change_alt(mavproxy, mav, 30):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "change_alt climb failed"
|
|
|
|
print(failed_test_msg)
|
2011-12-16 00:39:05 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Loiter Descend
|
|
|
|
print("#")
|
|
|
|
print("# Loiter - descend to 20m")
|
|
|
|
print("#")
|
2011-12-16 00:39:05 -04:00
|
|
|
if not change_alt(mavproxy, mav, 20):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "change_alt descend failed"
|
|
|
|
print(failed_test_msg)
|
2011-12-16 00:39:05 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# RTL
|
|
|
|
print("#")
|
|
|
|
print("########## Test RTL ##########")
|
|
|
|
print("#")
|
|
|
|
if not fly_RTL(mavproxy, mav):
|
2015-04-16 03:03:13 -03:00
|
|
|
failed_test_msg = "fly_RTL after Loiter climb/descend failed"
|
2014-04-30 03:16:37 -03:00
|
|
|
print(failed_test_msg)
|
2011-11-09 22:12:43 -04:00
|
|
|
failed = True
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Takeoff
|
|
|
|
print("# Takeoff")
|
2011-12-16 00:39:05 -04:00
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2011-12-16 00:39:05 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# Simple mode
|
2011-12-16 00:39:05 -04:00
|
|
|
print("# Fly in SIMPLE mode")
|
|
|
|
if not fly_simple(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_simple failed"
|
|
|
|
print(failed_test_msg)
|
2011-12-16 00:39:05 -04:00
|
|
|
failed = True
|
|
|
|
|
2013-05-02 23:22:15 -03:00
|
|
|
# RTL
|
|
|
|
print("#")
|
|
|
|
print("########## Test RTL ##########")
|
|
|
|
print("#")
|
|
|
|
if not fly_RTL(mavproxy, mav):
|
2015-04-16 03:03:13 -03:00
|
|
|
failed_test_msg = "fly_RTL after simple mode failed"
|
2014-04-30 03:16:37 -03:00
|
|
|
print(failed_test_msg)
|
2013-05-02 23:22:15 -03:00
|
|
|
failed = True
|
2011-12-16 00:39:05 -04:00
|
|
|
|
2013-06-01 06:20:57 -03:00
|
|
|
# Takeoff
|
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-06-01 06:20:57 -03:00
|
|
|
failed = True
|
|
|
|
|
2013-10-05 06:25:17 -03:00
|
|
|
# Fly a circle in super simple mode
|
|
|
|
print("# Fly a circle in SUPER SIMPLE mode")
|
|
|
|
if not fly_super_simple(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_super_simple failed"
|
|
|
|
print(failed_test_msg)
|
2013-10-05 06:25:17 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# RTL
|
|
|
|
print("# RTL #")
|
|
|
|
if not fly_RTL(mavproxy, mav):
|
2015-04-16 03:03:13 -03:00
|
|
|
failed_test_msg = "fly_RTL after super simple mode failed"
|
2014-04-30 03:16:37 -03:00
|
|
|
print(failed_test_msg)
|
2013-10-05 06:25:17 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# Takeoff
|
|
|
|
print("# Takeoff")
|
|
|
|
if not takeoff(mavproxy, mav, 10):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "takeoff failed"
|
|
|
|
print(failed_test_msg)
|
2013-10-05 06:25:17 -03:00
|
|
|
failed = True
|
|
|
|
|
2013-06-01 06:20:57 -03:00
|
|
|
# Circle mode
|
|
|
|
print("# Fly CIRCLE mode")
|
|
|
|
if not fly_circle(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_circle failed"
|
|
|
|
print(failed_test_msg)
|
2013-06-01 06:20:57 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
# RTL
|
|
|
|
print("#")
|
|
|
|
print("########## Test RTL ##########")
|
|
|
|
print("#")
|
|
|
|
if not fly_RTL(mavproxy, mav):
|
2015-04-16 03:03:13 -03:00
|
|
|
failed_test_msg = "fly_RTL after circle failed"
|
2014-04-30 03:16:37 -03:00
|
|
|
print(failed_test_msg)
|
2013-06-01 06:20:57 -03:00
|
|
|
failed = True
|
|
|
|
|
2014-04-07 10:25:38 -03:00
|
|
|
print("# Fly copter mission")
|
|
|
|
if not fly_auto_test(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_auto_test failed"
|
|
|
|
print(failed_test_msg)
|
2011-11-13 04:24:25 -04:00
|
|
|
failed = True
|
2011-11-13 08:50:04 -04:00
|
|
|
else:
|
2014-04-07 10:25:38 -03:00
|
|
|
print("Flew copter mission OK")
|
2011-11-13 04:24:25 -04:00
|
|
|
|
2015-04-15 05:04:32 -03:00
|
|
|
# wait for disarm
|
|
|
|
mav.motors_disarmed_wait()
|
|
|
|
|
2013-12-28 06:47:12 -04:00
|
|
|
if not log_download(mavproxy, mav, util.reltopdir("../buildlogs/ArduCopter-log.bin")):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "log_download failed"
|
|
|
|
print(failed_test_msg)
|
2013-12-28 06:47:12 -04:00
|
|
|
failed = True
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
except pexpect.TIMEOUT as failed_test_msg:
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "Timeout"
|
2011-10-30 23:50:34 -03:00
|
|
|
failed = True
|
|
|
|
|
2011-12-02 00:21:15 -04:00
|
|
|
mav.close()
|
2011-11-09 00:45:18 -04:00
|
|
|
util.pexpect_close(mavproxy)
|
2016-07-31 07:22:06 -03:00
|
|
|
util.pexpect_close(sitl)
|
2011-10-30 23:50:34 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
valgrind_log = sitl.valgrind_log_filepath()
|
2016-05-27 03:45:25 -03:00
|
|
|
if os.path.exists(valgrind_log):
|
|
|
|
os.chmod(valgrind_log, 0644)
|
|
|
|
shutil.copy(valgrind_log, util.reltopdir("../buildlogs/ArduCopter-valgrind.log"))
|
2011-11-01 08:31:01 -03:00
|
|
|
|
2014-07-07 14:25:32 -03:00
|
|
|
# [2014/05/07] FC Because I'm doing a cross machine build (source is on host, build is on guest VM) I cannot hard link
|
|
|
|
# This flag tells me that I need to copy the data out
|
2016-07-31 07:22:06 -03:00
|
|
|
if copy_tlog:
|
2014-07-07 14:25:32 -03:00
|
|
|
shutil.copy(logfile, buildlog)
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2011-10-30 23:50:34 -03:00
|
|
|
if failed:
|
2014-04-30 03:16:37 -03:00
|
|
|
print("FAILED: %s" % failed_test_msg)
|
2011-11-09 01:15:53 -04:00
|
|
|
return False
|
|
|
|
return True
|
2013-05-29 02:33:32 -03:00
|
|
|
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
def fly_CopterAVC(binary, viewerip=None, use_map=False, valgrind=False, gdb=False):
|
|
|
|
"""Fly ArduCopter in SITL for AVC2013 mission."""
|
2013-05-29 02:33:32 -03:00
|
|
|
global homeloc
|
|
|
|
|
2015-05-05 03:32:14 -03:00
|
|
|
home = "%f,%f,%u,%u" % (AVCHOME.lat, AVCHOME.lng, AVCHOME.alt, AVCHOME.heading)
|
2016-07-31 07:22:06 -03:00
|
|
|
sitl = util.start_SITL(binary, wipe=True, model='heli', home=home, speedup=speedup_default)
|
|
|
|
mavproxy = util.start_MAVProxy_SITL('ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550')
|
2013-05-29 02:33:32 -03:00
|
|
|
mavproxy.expect('Received [0-9]+ parameters')
|
|
|
|
|
|
|
|
# setup test parameters
|
2016-08-03 17:48:36 -03:00
|
|
|
mavproxy.send("param load %s/default_params/copter-heli.parm\n" % testdir)
|
2013-05-29 02:33:32 -03:00
|
|
|
mavproxy.expect('Loaded [0-9]+ parameters')
|
2016-05-27 07:54:12 -03:00
|
|
|
mavproxy.send("param set LOG_REPLAY 1\n")
|
|
|
|
mavproxy.send("param set LOG_DISARMED 1\n")
|
|
|
|
time.sleep(3)
|
2013-05-29 02:33:32 -03:00
|
|
|
|
|
|
|
# reboot with new parameters
|
|
|
|
util.pexpect_close(mavproxy)
|
2016-07-31 07:22:06 -03:00
|
|
|
util.pexpect_close(sitl)
|
2013-05-29 02:33:32 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
sitl = util.start_SITL(binary, model='heli', home=home, speedup=speedup_default, valgrind=valgrind, gdb=gdb)
|
2015-05-27 05:13:55 -03:00
|
|
|
options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=5'
|
2013-05-29 02:33:32 -03:00
|
|
|
if viewerip:
|
|
|
|
options += ' --out=%s:14550' % viewerip
|
2016-07-31 07:22:06 -03:00
|
|
|
if use_map:
|
2013-05-29 02:33:32 -03:00
|
|
|
options += ' --map'
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy = util.start_MAVProxy_SITL('ArduCopter', options=options)
|
2015-06-30 01:06:17 -03:00
|
|
|
mavproxy.expect('Telemetry log: (\S+)')
|
2013-05-29 02:33:32 -03:00
|
|
|
logfile = mavproxy.match.group(1)
|
|
|
|
print("LOGFILE %s" % logfile)
|
|
|
|
|
|
|
|
buildlog = util.reltopdir("../buildlogs/CopterAVC-test.tlog")
|
|
|
|
print("buildlog=%s" % buildlog)
|
|
|
|
if os.path.exists(buildlog):
|
|
|
|
os.unlink(buildlog)
|
2013-06-24 00:06:11 -03:00
|
|
|
try:
|
|
|
|
os.link(logfile, buildlog)
|
|
|
|
except Exception:
|
|
|
|
pass
|
2013-05-29 02:33:32 -03:00
|
|
|
|
|
|
|
# the received parameters can come before or after the ready to fly message
|
|
|
|
mavproxy.expect(['Received [0-9]+ parameters', 'Ready to FLY'])
|
|
|
|
mavproxy.expect(['Received [0-9]+ parameters', 'Ready to FLY'])
|
|
|
|
|
|
|
|
util.expect_setup_callback(mavproxy, expect_callback)
|
|
|
|
|
|
|
|
expect_list_clear()
|
2016-07-31 07:22:06 -03:00
|
|
|
expect_list_extend([sitl, mavproxy])
|
2013-05-29 02:33:32 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
if use_map:
|
2013-05-29 03:55:23 -03:00
|
|
|
mavproxy.send('map icon 40.072467969730496 -105.2314389590174\n')
|
2016-07-31 07:22:06 -03:00
|
|
|
mavproxy.send('map icon 40.072600990533829 -105.23146100342274\n')
|
2013-05-29 03:55:23 -03:00
|
|
|
|
2013-05-29 02:33:32 -03: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:
|
2013-05-29 02:33:32 -03:00
|
|
|
print("Failed to start mavlink connection on 127.0.0.1:19550" % msg)
|
|
|
|
raise
|
|
|
|
mav.message_hooks.append(message_hook)
|
|
|
|
mav.idle_hooks.append(idle_hook)
|
|
|
|
|
|
|
|
failed = False
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "None"
|
|
|
|
|
2013-05-29 02:33:32 -03:00
|
|
|
try:
|
|
|
|
mav.wait_heartbeat()
|
|
|
|
setup_rc(mavproxy)
|
|
|
|
homeloc = mav.location()
|
|
|
|
|
2015-05-27 05:13:55 -03:00
|
|
|
print("Lowering rotor speed")
|
|
|
|
mavproxy.send('rc 8 1000\n')
|
|
|
|
|
2016-07-04 21:45:33 -03:00
|
|
|
# wait for EKF and GPS checks to pass
|
|
|
|
wait_seconds(mav, 30)
|
2015-03-21 09:51:41 -03:00
|
|
|
|
2013-05-29 02:33:32 -03:00
|
|
|
# Arm
|
|
|
|
print("# Arm motors")
|
|
|
|
if not arm_motors(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "arm_motors failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-29 02:33:32 -03:00
|
|
|
failed = True
|
|
|
|
|
2015-05-27 05:13:55 -03:00
|
|
|
print("Raising rotor speed")
|
|
|
|
mavproxy.send('rc 8 2000\n')
|
|
|
|
|
2014-04-07 23:00:47 -03:00
|
|
|
print("# Fly AVC mission")
|
|
|
|
if not fly_avc_test(mavproxy, mav):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "fly_avc_test failed"
|
|
|
|
print(failed_test_msg)
|
2013-05-29 02:33:32 -03:00
|
|
|
failed = True
|
|
|
|
else:
|
2014-04-07 23:00:47 -03:00
|
|
|
print("Flew AVC mission OK")
|
2013-05-29 02:33:32 -03:00
|
|
|
|
2015-05-27 05:13:55 -03:00
|
|
|
print("Lowering rotor speed")
|
|
|
|
mavproxy.send('rc 8 1000\n')
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# mission includes disarm at end so should be ok to download logs now
|
2013-12-28 06:47:12 -04:00
|
|
|
if not log_download(mavproxy, mav, util.reltopdir("../buildlogs/CopterAVC-log.bin")):
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "log_download failed"
|
|
|
|
print(failed_test_msg)
|
2013-12-28 06:47:12 -04:00
|
|
|
failed = True
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
except pexpect.TIMEOUT as failed_test_msg:
|
2014-04-30 03:16:37 -03:00
|
|
|
failed_test_msg = "Timeout"
|
2013-05-29 02:33:32 -03:00
|
|
|
failed = True
|
|
|
|
|
|
|
|
mav.close()
|
|
|
|
util.pexpect_close(mavproxy)
|
2016-07-31 07:22:06 -03:00
|
|
|
util.pexpect_close(sitl)
|
2013-05-29 02:33:32 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
valgrind_log = sitl.valgrind_log_filepath()
|
2016-05-27 03:45:25 -03:00
|
|
|
if os.path.exists(valgrind_log):
|
|
|
|
os.chmod(valgrind_log, 0644)
|
|
|
|
shutil.copy(valgrind_log, util.reltopdir("../buildlogs/Helicopter-valgrind.log"))
|
|
|
|
|
2013-05-29 02:33:32 -03:00
|
|
|
if failed:
|
2014-06-05 23:40:47 -03:00
|
|
|
print("FAILED: %s" % failed_test_msg)
|
2013-05-29 02:33:32 -03:00
|
|
|
return False
|
|
|
|
return True
|