Created
December 22, 2016 17:53
-
-
Save tribbloid/13d1bb022c0b681a9ee4a65f1067376e to your computer and use it in GitHub Desktop.
Usually commands.download() will fail after 4-6 trials. It won't happen without MAVProxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dronekit | |
import pexpect | |
import sys | |
import time | |
from dronekit_sitl import SITL | |
sys.path.append('/home/peng/.spookystuff/pythonpath') | |
import os | |
sitl_args = ['--model', 'quad', '--home=-35.363261,149.165230,584,353'] | |
if 'SITL_SPEEDUP' in os.environ: | |
sitl_args += ['--speedup', str(os.environ['SITL_SPEEDUP'])] | |
if 'SITL_RATE' in os.environ: | |
sitl_args += ['-r', str(os.environ['SITL_RATE'])] | |
sitl = SITL() | |
sitl.download('copter', '3.3') | |
sitl.launch(sitl_args, await_ready=True, restart=True) | |
def spawnProxy(aircraft, setup, master, outs, | |
options='', logfile=sys.stdout): | |
# type: (str, bool, str, list, str, str) -> object | |
MAVPROXY = os.getenv('MAVPROXY_CMD', 'mavproxy.py') | |
cmd = MAVPROXY + ' --master=%s' % master | |
for out in outs: | |
cmd += ' --out=%s' % out | |
if setup: | |
cmd += ' --setup' | |
cmd += ' --aircraft=%s' % aircraft | |
if options is not None: | |
cmd += ' ' + options | |
print(cmd) | |
p = pexpect.spawn(cmd, logfile=logfile, timeout=60, ignore_sighup=True) | |
p.delaybeforesend = 0 | |
return p | |
p = spawnProxy( | |
aircraft="DRONE", | |
setup=False, | |
master="tcp:localhost:5760", | |
outs=["udp:localhost:12052"] | |
) | |
time.sleep(1) # wait for proxy to initialize | |
for i in range(1, 20): | |
vehicle = dronekit.connect( | |
"udp:localhost:12052", | |
wait_ready=True | |
) | |
vehicle.commands.download() | |
vehicle.commands.wait_ready() | |
vehicle.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment