2022-03-02 23:25:54 -04:00
|
|
|
#!/usr/bin/env python3
|
2016-10-25 02:59:42 -03:00
|
|
|
|
|
|
|
import pexpect, time, sys
|
|
|
|
from pymavlink import mavutil
|
|
|
|
|
|
|
|
def wait_heartbeat(mav, timeout=10):
|
|
|
|
'''wait for a heartbeat'''
|
|
|
|
start_time = time.time()
|
|
|
|
while time.time() < start_time+timeout:
|
|
|
|
if mav.recv_match(type='HEARTBEAT', blocking=True, timeout=0.5) is not None:
|
|
|
|
return
|
2017-09-24 05:44:30 -03:00
|
|
|
raise Exception("Failed to get heartbeat")
|
2016-10-25 02:59:42 -03:00
|
|
|
|
|
|
|
def wait_mode(mav, modes, timeout=10):
|
|
|
|
'''wait for one of a set of flight modes'''
|
|
|
|
start_time = time.time()
|
|
|
|
last_mode = None
|
|
|
|
while time.time() < start_time+timeout:
|
|
|
|
wait_heartbeat(mav, timeout=10)
|
|
|
|
if mav.flightmode != last_mode:
|
|
|
|
print("Flightmode %s" % mav.flightmode)
|
|
|
|
last_mode = mav.flightmode
|
|
|
|
if mav.flightmode in modes:
|
|
|
|
return
|
|
|
|
print("Failed to get mode from %s" % modes)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2022-03-02 23:25:54 -04:00
|
|
|
def wait_prearm_ok(mav, timeout=30):
|
|
|
|
'''wait for pre-arm OK'''
|
|
|
|
start_time = time.time()
|
|
|
|
last_mode = None
|
|
|
|
while time.time() < start_time+timeout:
|
|
|
|
m = mav.recv_match(type='SYS_STATUS', blocking=True, timeout=2)
|
|
|
|
if m is None:
|
|
|
|
return
|
|
|
|
if m.onboard_control_sensors_health & mavutil.mavlink.MAV_SYS_STATUS_PREARM_CHECK != 0:
|
|
|
|
print("Prearm OK")
|
|
|
|
return
|
|
|
|
print("Failed to get pre-arm OK")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-10-25 02:59:42 -03:00
|
|
|
def wait_time(mav, simtime):
|
|
|
|
'''wait for simulation time to pass'''
|
|
|
|
imu = mav.recv_match(type='RAW_IMU', blocking=True)
|
|
|
|
t1 = imu.time_usec*1.0e-6
|
|
|
|
while True:
|
|
|
|
imu = mav.recv_match(type='RAW_IMU', blocking=True)
|
|
|
|
t2 = imu.time_usec*1.0e-6
|
|
|
|
if t2 - t1 > simtime:
|
|
|
|
break
|
|
|
|
|
2020-11-05 19:38:31 -04:00
|
|
|
cmd = '../Tools/autotest/sim_vehicle.py -D -f quadplane'
|
2022-03-02 23:25:54 -04:00
|
|
|
mavproxy = pexpect.spawn(cmd, logfile=sys.stdout.buffer, timeout=30)
|
2020-09-18 09:36:33 -03:00
|
|
|
mavproxy.expect("ArduPilot Ready")
|
2016-10-25 02:59:42 -03:00
|
|
|
|
|
|
|
mav = mavutil.mavlink_connection('127.0.0.1:14550')
|
|
|
|
|
2020-11-05 19:38:31 -04:00
|
|
|
mavproxy.send('speedup 40\n')
|
2022-03-02 23:25:54 -04:00
|
|
|
wait_prearm_ok(mav)
|
|
|
|
mavproxy.send('mode guided\n')
|
|
|
|
wait_mode(mav, ['GUIDED'])
|
2020-11-05 19:38:31 -04:00
|
|
|
mavproxy.send('arm throttle\n')
|
2022-03-02 23:25:54 -04:00
|
|
|
mavproxy.send('takeoff 40\n')
|
|
|
|
wait_time(mav, 30)
|
|
|
|
mavproxy.send('mode cruise\n')
|
|
|
|
wait_mode(mav, ['CRUISE'])
|
|
|
|
wait_time(mav, 10)
|
|
|
|
mavproxy.send('mode qrtl\n')
|
|
|
|
wait_mode(mav, ['QRTL'])
|
|
|
|
mavproxy.send('module load console\n')
|
|
|
|
mavproxy.send('module load map\n')
|
|
|
|
mavproxy.logfile = None
|
|
|
|
mavproxy.interact()
|