2011-11-12 07:13:17 -04:00
|
|
|
# fly ArduPlane in SIL
|
|
|
|
|
|
|
|
import util, pexpect, sys, time, math, shutil, os
|
|
|
|
from common import *
|
2013-06-18 03:27:21 -03:00
|
|
|
from pymavlink import mavutil
|
|
|
|
import random
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
# get location of scripts
|
|
|
|
testdir=os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
2012-08-29 04:17:38 -03:00
|
|
|
HOME_LOCATION='-35.362938,149.165085,585,354'
|
2011-12-18 03:57:20 -04:00
|
|
|
WIND="0,180,0.2" # speed,direction,variance
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
homeloc = None
|
|
|
|
|
|
|
|
def takeoff(mavproxy, mav):
|
|
|
|
'''takeoff get to 30m altitude'''
|
2015-04-12 20:28:24 -03:00
|
|
|
|
|
|
|
# wait for EKF to settle
|
|
|
|
wait_seconds(mav, 15)
|
|
|
|
|
|
|
|
mavproxy.send('arm throttle\n')
|
|
|
|
mavproxy.expect('ARMED')
|
|
|
|
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('switch 4\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
|
|
|
|
# some rudder to counteract the prop torque
|
2011-12-18 03:57:20 -04:00
|
|
|
mavproxy.send('rc 4 1700\n')
|
|
|
|
|
|
|
|
# some up elevator to keep the tail down
|
|
|
|
mavproxy.send('rc 2 1200\n')
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2011-12-18 02:29:36 -04:00
|
|
|
# get it moving a bit first
|
2011-12-18 03:57:20 -04:00
|
|
|
mavproxy.send('rc 3 1300\n')
|
|
|
|
mav.recv_match(condition='VFR_HUD.groundspeed>6', blocking=True)
|
|
|
|
|
|
|
|
# a bit faster again, straighten rudder
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('rc 3 1600\n')
|
2011-12-18 03:57:20 -04:00
|
|
|
mavproxy.send('rc 4 1500\n')
|
2011-12-18 02:29:36 -04:00
|
|
|
mav.recv_match(condition='VFR_HUD.groundspeed>12', blocking=True)
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2011-12-18 03:57:20 -04:00
|
|
|
# hit the gas harder now, and give it some more elevator
|
|
|
|
mavproxy.send('rc 2 1100\n')
|
2013-07-22 00:27:06 -03:00
|
|
|
mavproxy.send('rc 3 2000\n')
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
# gain a bit of altitude
|
2013-07-22 00:27:06 -03:00
|
|
|
if not wait_altitude(mav, homeloc.alt+150, homeloc.alt+180, timeout=30):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
# level off
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
print("TAKEOFF COMPLETE")
|
|
|
|
return True
|
|
|
|
|
|
|
|
def fly_left_circuit(mavproxy, mav):
|
|
|
|
'''fly a left circuit, 200m on a side'''
|
|
|
|
mavproxy.send('switch 4\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
2011-12-02 00:21:15 -04:00
|
|
|
mavproxy.send('rc 3 2000\n')
|
2012-02-13 20:19:31 -04:00
|
|
|
if not wait_level_flight(mavproxy, mav):
|
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
print("Flying left circuit")
|
|
|
|
# do 4 turns
|
|
|
|
for i in range(0,4):
|
|
|
|
# hard left
|
|
|
|
print("Starting turn %u" % i)
|
|
|
|
mavproxy.send('rc 1 1000\n')
|
2012-07-04 02:59:35 -03:00
|
|
|
if not wait_heading(mav, 270 - (90*i), accuracy=10):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
print("Starting leg %u" % i)
|
2012-04-02 21:42:53 -03:00
|
|
|
if not wait_distance(mav, 100, accuracy=20):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
print("Circuit complete")
|
|
|
|
return True
|
|
|
|
|
|
|
|
def fly_RTL(mavproxy, mav):
|
|
|
|
'''fly to home'''
|
2011-12-02 00:21:15 -04:00
|
|
|
print("Flying home in RTL")
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('switch 2\n')
|
|
|
|
wait_mode(mav, 'RTL')
|
2013-01-16 00:16:26 -04:00
|
|
|
if not wait_location(mav, homeloc, accuracy=120,
|
2012-02-13 20:19:31 -04:00
|
|
|
target_altitude=homeloc.alt+100, height_accuracy=20,
|
2013-07-16 00:23:48 -03:00
|
|
|
timeout=180):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
print("RTL Complete")
|
|
|
|
return True
|
|
|
|
|
2012-02-13 20:19:31 -04:00
|
|
|
def fly_LOITER(mavproxy, mav, num_circles=4):
|
2011-11-12 07:13:17 -04:00
|
|
|
'''loiter where we are'''
|
2012-02-13 20:19:31 -04:00
|
|
|
print("Testing LOITER for %u turns" % num_circles)
|
2012-05-03 02:39:21 -03:00
|
|
|
mavproxy.send('loiter\n')
|
2011-11-12 07:13:17 -04:00
|
|
|
wait_mode(mav, 'LOITER')
|
2013-07-16 00:23:48 -03:00
|
|
|
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
|
|
|
print("Initial altitude %u\n" % initial_alt)
|
|
|
|
|
2012-02-13 20:19:31 -04:00
|
|
|
while num_circles > 0:
|
2012-08-27 00:19:21 -03:00
|
|
|
if not wait_heading(mav, 0, accuracy=10, timeout=60):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2012-08-27 00:19:21 -03:00
|
|
|
if not wait_heading(mav, 180, accuracy=10, timeout=60):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
|
|
|
num_circles -= 1
|
|
|
|
print("Loiter %u circles left" % num_circles)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2013-10-17 03:22:01 -03:00
|
|
|
print("Final altitude %u initial %u\n" % (final_alt, initial_alt))
|
2013-07-16 00:23:48 -03:00
|
|
|
|
|
|
|
mavproxy.send('mode FBWA\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
|
|
|
print("Failed to maintain altitude")
|
|
|
|
return False
|
|
|
|
|
2012-02-13 20:19:31 -04:00
|
|
|
print("Completed Loiter OK")
|
2011-11-12 07:13:17 -04:00
|
|
|
return True
|
|
|
|
|
2013-07-16 00:23:48 -03:00
|
|
|
def fly_CIRCLE(mavproxy, mav, num_circles=1):
|
|
|
|
'''circle where we are'''
|
|
|
|
print("Testing CIRCLE for %u turns" % num_circles)
|
|
|
|
mavproxy.send('mode CIRCLE\n')
|
|
|
|
wait_mode(mav, 'CIRCLE')
|
|
|
|
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
|
|
|
print("Initial altitude %u\n" % initial_alt)
|
|
|
|
|
|
|
|
while num_circles > 0:
|
|
|
|
if not wait_heading(mav, 0, accuracy=10, timeout=60):
|
|
|
|
return False
|
|
|
|
if not wait_heading(mav, 180, accuracy=10, timeout=60):
|
|
|
|
return False
|
|
|
|
num_circles -= 1
|
|
|
|
print("CIRCLE %u circles left" % num_circles)
|
|
|
|
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2013-10-17 03:22:01 -03:00
|
|
|
print("Final altitude %u initial %u\n" % (final_alt, initial_alt))
|
2013-07-16 00:23:48 -03:00
|
|
|
|
|
|
|
mavproxy.send('mode FBWA\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
|
|
|
print("Failed to maintain altitude")
|
|
|
|
return False
|
|
|
|
|
|
|
|
print("Completed CIRCLE OK")
|
|
|
|
return True
|
|
|
|
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2011-11-13 21:59:59 -04:00
|
|
|
def wait_level_flight(mavproxy, mav, accuracy=5, timeout=30):
|
|
|
|
'''wait for level flight'''
|
2015-04-12 20:28:24 -03:00
|
|
|
tstart = get_sim_time(mav)
|
2012-02-13 20:19:31 -04:00
|
|
|
print("Waiting for level flight")
|
2013-10-09 19:53:51 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
2015-04-12 20:28:24 -03:00
|
|
|
while get_sim_time(mav) < tstart + timeout:
|
2011-11-13 21:59:59 -04:00
|
|
|
m = mav.recv_match(type='ATTITUDE', blocking=True)
|
|
|
|
roll = math.degrees(m.roll)
|
|
|
|
pitch = math.degrees(m.pitch)
|
|
|
|
print("Roll=%.1f Pitch=%.1f" % (roll, pitch))
|
|
|
|
if math.fabs(roll) <= accuracy and math.fabs(pitch) <= accuracy:
|
2012-02-13 20:19:31 -04:00
|
|
|
print("Attained level flight")
|
2011-11-13 21:59:59 -04:00
|
|
|
return True
|
|
|
|
print("Failed to attain level flight")
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2013-07-16 00:23:48 -03:00
|
|
|
def change_altitude(mavproxy, mav, altitude, accuracy=30):
|
2011-11-12 07:13:17 -04:00
|
|
|
'''get to a given altitude'''
|
2013-07-16 00:23:48 -03:00
|
|
|
mavproxy.send('mode FBWA\n')
|
2011-11-12 07:13:17 -04:00
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
alt_error = mav.messages['VFR_HUD'].alt - altitude
|
|
|
|
if alt_error > 0:
|
|
|
|
mavproxy.send('rc 2 2000\n')
|
|
|
|
else:
|
|
|
|
mavproxy.send('rc 2 1000\n')
|
2012-02-13 20:19:31 -04:00
|
|
|
if not wait_altitude(mav, altitude-accuracy/2, altitude+accuracy/2):
|
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
print("Reached target altitude at %u" % mav.messages['VFR_HUD'].alt)
|
2011-11-13 21:59:59 -04:00
|
|
|
return wait_level_flight(mavproxy, mav)
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
def axial_left_roll(mavproxy, mav, count=1):
|
|
|
|
'''fly a left axial roll'''
|
|
|
|
# full throttle!
|
|
|
|
mavproxy.send('rc 3 2000\n')
|
2013-07-16 00:23:48 -03:00
|
|
|
if not change_altitude(mavproxy, mav, homeloc.alt+300):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
# fly the roll in manual
|
2011-11-13 21:59:59 -04:00
|
|
|
mavproxy.send('switch 6\n')
|
|
|
|
wait_mode(mav, 'MANUAL')
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
while count > 0:
|
|
|
|
print("Starting roll")
|
|
|
|
mavproxy.send('rc 1 1000\n')
|
2013-07-16 00:23:48 -03:00
|
|
|
if not wait_roll(mav, -150, accuracy=90):
|
2013-10-09 19:53:51 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2013-07-16 00:23:48 -03:00
|
|
|
if not wait_roll(mav, 150, accuracy=90):
|
2013-10-09 19:53:51 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2013-07-16 00:23:48 -03:00
|
|
|
if not wait_roll(mav, 0, accuracy=90):
|
2013-10-09 19:53:51 -03:00
|
|
|
mavproxy.send('rc 1 1500\n')
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-12 07:13:17 -04:00
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
mavproxy.send('switch 4\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
mavproxy.send('rc 3 1700\n')
|
2011-11-13 21:59:59 -04:00
|
|
|
return wait_level_flight(mavproxy, mav)
|
|
|
|
|
|
|
|
|
|
|
|
def inside_loop(mavproxy, mav, count=1):
|
|
|
|
'''fly a inside loop'''
|
|
|
|
# full throttle!
|
|
|
|
mavproxy.send('rc 3 2000\n')
|
2013-07-16 00:23:48 -03:00
|
|
|
if not change_altitude(mavproxy, mav, homeloc.alt+300):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
2011-11-13 21:59:59 -04:00
|
|
|
|
|
|
|
# fly the loop in manual
|
|
|
|
mavproxy.send('switch 6\n')
|
|
|
|
wait_mode(mav, 'MANUAL')
|
|
|
|
|
|
|
|
while count > 0:
|
|
|
|
print("Starting loop")
|
|
|
|
mavproxy.send('rc 2 1000\n')
|
2012-08-26 22:44:57 -03:00
|
|
|
if not wait_pitch(mav, -60, accuracy=20):
|
2012-02-13 20:19:31 -04:00
|
|
|
return False
|
|
|
|
if not wait_pitch(mav, 0, accuracy=20):
|
|
|
|
return False
|
2011-11-13 21:59:59 -04:00
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
mavproxy.send('switch 4\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
mavproxy.send('rc 3 1700\n')
|
|
|
|
return wait_level_flight(mavproxy, mav)
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
|
2013-07-16 00:23:48 -03:00
|
|
|
def test_stabilize(mavproxy, mav, count=1):
|
|
|
|
'''fly stabilize mode'''
|
|
|
|
# full throttle!
|
|
|
|
mavproxy.send('rc 3 2000\n')
|
|
|
|
mavproxy.send('rc 2 1300\n')
|
|
|
|
if not change_altitude(mavproxy, mav, homeloc.alt+300):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
mavproxy.send("mode STABILIZE\n")
|
|
|
|
wait_mode(mav, 'STABILIZE')
|
|
|
|
|
|
|
|
count = 1
|
|
|
|
while count > 0:
|
|
|
|
print("Starting roll")
|
|
|
|
mavproxy.send('rc 1 2000\n')
|
|
|
|
if not wait_roll(mav, -150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not wait_roll(mav, 150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not wait_roll(mav, 0, accuracy=90):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
if not wait_roll(mav, 0, accuracy=5):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
mavproxy.send('mode FBWA\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
mavproxy.send('rc 3 1700\n')
|
|
|
|
return wait_level_flight(mavproxy, mav)
|
|
|
|
|
|
|
|
def test_acro(mavproxy, mav, count=1):
|
|
|
|
'''fly ACRO mode'''
|
|
|
|
# full throttle!
|
|
|
|
mavproxy.send('rc 3 2000\n')
|
|
|
|
mavproxy.send('rc 2 1300\n')
|
|
|
|
if not change_altitude(mavproxy, mav, homeloc.alt+300):
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
mavproxy.send("mode ACRO\n")
|
|
|
|
wait_mode(mav, 'ACRO')
|
|
|
|
|
|
|
|
count = 1
|
|
|
|
while count > 0:
|
|
|
|
print("Starting roll")
|
|
|
|
mavproxy.send('rc 1 1000\n')
|
|
|
|
if not wait_roll(mav, -150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not wait_roll(mav, 150, accuracy=90):
|
|
|
|
return False
|
|
|
|
if not wait_roll(mav, 0, accuracy=90):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
mavproxy.send('mode FBWA\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
|
|
|
|
wait_level_flight(mavproxy, mav)
|
|
|
|
|
|
|
|
mavproxy.send("mode ACRO\n")
|
|
|
|
wait_mode(mav, 'ACRO')
|
|
|
|
|
|
|
|
count = 2
|
|
|
|
while count > 0:
|
|
|
|
print("Starting loop")
|
|
|
|
mavproxy.send('rc 2 1000\n')
|
|
|
|
if not wait_pitch(mav, -60, accuracy=20):
|
|
|
|
return False
|
|
|
|
if not wait_pitch(mav, 0, accuracy=20):
|
|
|
|
return False
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
mavproxy.send('mode FBWA\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
mavproxy.send('rc 3 1700\n')
|
|
|
|
return wait_level_flight(mavproxy, mav)
|
|
|
|
|
|
|
|
|
|
|
|
def test_FBWB(mavproxy, mav, count=1, mode='FBWB'):
|
|
|
|
'''fly FBWB or CRUISE mode'''
|
|
|
|
mavproxy.send("mode %s\n" % mode)
|
|
|
|
wait_mode(mav, mode)
|
|
|
|
mavproxy.send('rc 3 1700\n')
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
|
2015-01-21 20:33:25 -04:00
|
|
|
# lock in the altitude by asking for an altitude change then releasing
|
|
|
|
mavproxy.send('rc 2 1000\n')
|
|
|
|
wait_distance(mav, 50, accuracy=20)
|
|
|
|
mavproxy.send('rc 2 1500\n')
|
|
|
|
wait_distance(mav, 50, accuracy=20)
|
|
|
|
|
2013-07-16 00:23:48 -03:00
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
|
|
|
print("Initial altitude %u\n" % initial_alt)
|
|
|
|
|
|
|
|
print("Flying right circuit")
|
|
|
|
# do 4 turns
|
|
|
|
for i in range(0,4):
|
|
|
|
# hard left
|
|
|
|
print("Starting turn %u" % i)
|
|
|
|
mavproxy.send('rc 1 1800\n')
|
|
|
|
if not wait_heading(mav, 0 + (90*i), accuracy=20, timeout=60):
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 1 1500\n')
|
|
|
|
print("Starting leg %u" % i)
|
|
|
|
if not wait_distance(mav, 100, accuracy=20):
|
|
|
|
return False
|
|
|
|
print("Circuit complete")
|
|
|
|
|
|
|
|
print("Flying rudder left circuit")
|
|
|
|
# do 4 turns
|
|
|
|
for i in range(0,4):
|
|
|
|
# hard left
|
|
|
|
print("Starting turn %u" % i)
|
2014-02-23 21:08:33 -04:00
|
|
|
mavproxy.send('rc 4 1900\n')
|
2013-07-16 00:23:48 -03:00
|
|
|
if not wait_heading(mav, 360 - (90*i), accuracy=20, timeout=60):
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
return False
|
|
|
|
mavproxy.send('rc 4 1500\n')
|
|
|
|
print("Starting leg %u" % i)
|
|
|
|
if not wait_distance(mav, 100, accuracy=20):
|
|
|
|
return False
|
|
|
|
print("Circuit complete")
|
|
|
|
|
|
|
|
m = mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2013-10-17 03:22:01 -03:00
|
|
|
print("Final altitude %u initial %u\n" % (final_alt, initial_alt))
|
2013-07-16 00:23:48 -03:00
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
mavproxy.send('mode FBWA\n')
|
|
|
|
wait_mode(mav, 'FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
|
|
|
print("Failed to maintain altitude")
|
|
|
|
return False
|
|
|
|
|
|
|
|
return wait_level_flight(mavproxy, mav)
|
|
|
|
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
def setup_rc(mavproxy):
|
|
|
|
'''setup RC override control'''
|
|
|
|
for chan in [1,2,4,5,6,7]:
|
|
|
|
mavproxy.send('rc %u 1500\n' % chan)
|
|
|
|
mavproxy.send('rc 3 1000\n')
|
|
|
|
mavproxy.send('rc 8 1800\n')
|
|
|
|
|
|
|
|
|
|
|
|
def fly_mission(mavproxy, mav, filename, height_accuracy=-1, target_altitude=None):
|
|
|
|
'''fly a mission from a file'''
|
|
|
|
global homeloc
|
2012-02-13 20:19:31 -04:00
|
|
|
print("Flying mission %s" % filename)
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('wp load %s\n' % filename)
|
2015-11-25 21:52:19 -04:00
|
|
|
mavproxy.expect('Flight plan received')
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy.send('wp list\n')
|
|
|
|
mavproxy.expect('Requesting [0-9]+ waypoints')
|
|
|
|
mavproxy.send('switch 1\n') # auto mode
|
|
|
|
wait_mode(mav, 'AUTO')
|
2011-12-18 20:23:38 -04:00
|
|
|
if not wait_waypoint(mav, 1, 7, max_dist=60):
|
2011-11-12 07:13:17 -04:00
|
|
|
return False
|
2011-12-18 20:23:38 -04:00
|
|
|
if not wait_groundspeed(mav, 0, 0.5, timeout=60):
|
2011-11-12 07:13:17 -04:00
|
|
|
return False
|
|
|
|
print("Mission OK")
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2016-04-11 05:05:39 -03:00
|
|
|
def fly_ArduPlane(viewerip=None, map=False, valgrind=False):
|
2011-11-12 07:13:17 -04:00
|
|
|
'''fly ArduPlane in SIL
|
|
|
|
|
|
|
|
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
|
|
|
|
'''
|
2011-12-02 00:21:15 -04:00
|
|
|
global homeloc
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2012-08-26 22:44:57 -03:00
|
|
|
options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10'
|
2011-11-12 07:13:17 -04:00
|
|
|
if viewerip:
|
2011-12-02 00:21:15 -04:00
|
|
|
options += " --out=%s:14550" % viewerip
|
2013-05-02 07:03:36 -03:00
|
|
|
if map:
|
2013-05-31 02:31:59 -03:00
|
|
|
options += ' --map'
|
2011-11-13 21:20:55 -04:00
|
|
|
|
2015-05-10 19:06:31 -03:00
|
|
|
sil = util.start_SIL('ArduPlane', wipe=True, model='jsbsim', home=HOME_LOCATION, speedup=10)
|
2015-03-24 12:04:48 -03:00
|
|
|
print("Starting MAVProxy")
|
2011-11-13 21:20:55 -04:00
|
|
|
mavproxy = util.start_MAVProxy_SIL('ArduPlane', options=options)
|
2015-03-24 12:04:48 -03:00
|
|
|
util.expect_setup_callback(mavproxy, expect_callback)
|
|
|
|
|
2015-06-30 01:06:17 -03:00
|
|
|
mavproxy.expect('Telemetry log: (\S+)')
|
2015-03-24 12:04:48 -03:00
|
|
|
mavproxy.expect('Received [0-9]+ parameters',timeout=3000)
|
2011-11-13 21:20:55 -04:00
|
|
|
|
|
|
|
# setup test parameters
|
|
|
|
mavproxy.send("param load %s/ArduPlane.parm\n" % testdir)
|
|
|
|
mavproxy.expect('Loaded [0-9]+ parameters')
|
|
|
|
|
2014-02-16 22:57:26 -04:00
|
|
|
mavproxy.send("param fetch\n")
|
|
|
|
|
2011-11-13 21:20:55 -04:00
|
|
|
# restart with new parms
|
|
|
|
util.pexpect_close(mavproxy)
|
|
|
|
util.pexpect_close(sil)
|
2011-12-02 00:21:15 -04:00
|
|
|
|
2016-04-11 05:05:39 -03:00
|
|
|
sil = util.start_SIL('ArduPlane', model='jsbsim', home=HOME_LOCATION, speedup=10, valgrind=valgrind)
|
2011-11-12 07:13:17 -04:00
|
|
|
mavproxy = util.start_MAVProxy_SIL('ArduPlane', options=options)
|
2015-06-30 01:06:17 -03:00
|
|
|
mavproxy.expect('Telemetry log: (\S+)')
|
2011-11-12 07:13:17 -04:00
|
|
|
logfile = mavproxy.match.group(1)
|
|
|
|
print("LOGFILE %s" % logfile)
|
|
|
|
|
2013-04-28 02:01:31 -03:00
|
|
|
buildlog = util.reltopdir("../buildlogs/ArduPlane-test.tlog")
|
2011-11-12 07:13:17 -04:00
|
|
|
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
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
util.expect_setup_callback(mavproxy, expect_callback)
|
|
|
|
|
2015-03-24 12:04:48 -03:00
|
|
|
mavproxy.expect('Received [0-9]+ parameters')
|
|
|
|
|
2011-12-02 00:21:15 -04:00
|
|
|
expect_list_clear()
|
2015-05-10 19:06:31 -03:00
|
|
|
expect_list_extend([sil, mavproxy])
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2011-12-02 00:21:15 -04:00
|
|
|
print("Started simulator")
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
# get a mavlink connection going
|
|
|
|
try:
|
|
|
|
mav = mavutil.mavlink_connection('127.0.0.1:19550', robust_parsing=True)
|
|
|
|
except Exception, msg:
|
|
|
|
print("Failed to start mavlink connection on 127.0.0.1:19550" % msg)
|
|
|
|
raise
|
|
|
|
mav.message_hooks.append(message_hook)
|
2011-11-27 23:13:38 -04:00
|
|
|
mav.idle_hooks.append(idle_hook)
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
failed = False
|
|
|
|
e = 'None'
|
|
|
|
try:
|
2012-04-27 00:32:22 -03:00
|
|
|
print("Waiting for a heartbeat with mavlink protocol %s" % mav.WIRE_PROTOCOL_VERSION)
|
2011-11-12 07:13:17 -04:00
|
|
|
mav.wait_heartbeat()
|
2012-04-27 00:32:22 -03:00
|
|
|
print("Setting up RC parameters")
|
2011-11-12 07:13:17 -04:00
|
|
|
setup_rc(mavproxy)
|
2012-04-27 00:32:22 -03:00
|
|
|
print("Waiting for GPS fix")
|
2012-11-18 20:56:46 -04:00
|
|
|
mav.recv_match(condition='VFR_HUD.alt>10', blocking=True)
|
2012-04-27 00:32:22 -03:00
|
|
|
mav.wait_gps_fix()
|
2012-11-18 20:56:46 -04:00
|
|
|
while mav.location().alt < 10:
|
|
|
|
mav.wait_gps_fix()
|
2012-04-27 00:32:22 -03:00
|
|
|
homeloc = mav.location()
|
2011-11-12 07:13:17 -04:00
|
|
|
print("Home location: %s" % homeloc)
|
|
|
|
if not takeoff(mavproxy, mav):
|
2011-11-13 20:26:34 -04:00
|
|
|
print("Failed takeoff")
|
2011-11-12 07:13:17 -04:00
|
|
|
failed = True
|
|
|
|
if not fly_left_circuit(mavproxy, mav):
|
2011-11-13 20:26:34 -04:00
|
|
|
print("Failed left circuit")
|
2011-11-12 07:13:17 -04:00
|
|
|
failed = True
|
|
|
|
if not axial_left_roll(mavproxy, mav, 1):
|
2011-11-13 20:26:34 -04:00
|
|
|
print("Failed left roll")
|
2011-11-12 07:13:17 -04:00
|
|
|
failed = True
|
2011-11-13 21:59:59 -04:00
|
|
|
if not inside_loop(mavproxy, mav):
|
|
|
|
print("Failed inside loop")
|
|
|
|
failed = True
|
2013-07-16 00:23:48 -03:00
|
|
|
if not test_stabilize(mavproxy, mav):
|
|
|
|
print("Failed stabilize test")
|
|
|
|
failed = True
|
|
|
|
if not test_acro(mavproxy, mav):
|
|
|
|
print("Failed ACRO test")
|
|
|
|
failed = True
|
|
|
|
if not test_FBWB(mavproxy, mav):
|
|
|
|
print("Failed FBWB test")
|
|
|
|
failed = True
|
|
|
|
if not test_FBWB(mavproxy, mav, mode='CRUISE'):
|
|
|
|
print("Failed CRUISE test")
|
|
|
|
failed = True
|
2011-11-12 07:13:17 -04:00
|
|
|
if not fly_RTL(mavproxy, mav):
|
2011-11-13 20:26:34 -04:00
|
|
|
print("Failed RTL")
|
2011-11-12 07:13:17 -04:00
|
|
|
failed = True
|
2012-02-13 20:19:31 -04:00
|
|
|
if not fly_LOITER(mavproxy, mav):
|
|
|
|
print("Failed LOITER")
|
|
|
|
failed = True
|
2013-07-16 00:23:48 -03:00
|
|
|
if not fly_CIRCLE(mavproxy, mav):
|
|
|
|
print("Failed CIRCLE")
|
|
|
|
failed = True
|
2011-11-12 07:13:17 -04:00
|
|
|
if not fly_mission(mavproxy, mav, os.path.join(testdir, "ap1.txt"), height_accuracy = 10,
|
|
|
|
target_altitude=homeloc.alt+100):
|
2011-11-13 20:26:34 -04:00
|
|
|
print("Failed mission")
|
2011-11-12 07:13:17 -04:00
|
|
|
failed = True
|
2013-12-28 06:47:12 -04:00
|
|
|
if not log_download(mavproxy, mav, util.reltopdir("../buildlogs/ArduPlane-log.bin")):
|
|
|
|
print("Failed log download")
|
|
|
|
failed = True
|
2011-11-12 07:13:17 -04:00
|
|
|
except pexpect.TIMEOUT, e:
|
2012-07-04 02:59:35 -03:00
|
|
|
print("Failed with timeout")
|
2011-11-12 07:13:17 -04:00
|
|
|
failed = True
|
|
|
|
|
2011-12-02 00:21:15 -04:00
|
|
|
mav.close()
|
2011-11-12 07:13:17 -04:00
|
|
|
util.pexpect_close(mavproxy)
|
|
|
|
util.pexpect_close(sil)
|
|
|
|
|
|
|
|
if os.path.exists('ArduPlane-valgrind.log'):
|
|
|
|
os.chmod('ArduPlane-valgrind.log', 0644)
|
|
|
|
shutil.copy("ArduPlane-valgrind.log", util.reltopdir("../buildlogs/ArduPlane-valgrind.log"))
|
|
|
|
|
|
|
|
if failed:
|
|
|
|
print("FAILED: %s" % e)
|
|
|
|
return False
|
|
|
|
return True
|