def drive_APMrover2(viewerip=None): '''drive APMrover2 in SIL you can pass viewerip as an IP address to optionally send fg and mavproxy packets too for local viewing of the mission in real time ''' global homeloc options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10' if viewerip: options += " --out=%s:14550" % viewerip sil = util.start_SIL('APMrover2', wipe=True) mavproxy = util.start_MAVProxy_SIL('APMrover2', options=options) mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send('param set SYSID_THISMAV %u\n' % random.randint(100, 200)) mavproxy.send("param load %s/Rover.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # restart with new parms util.pexpect_close(mavproxy) util.pexpect_close(sil) sim_cmd = util.reltopdir('Tools/autotest/pysim/sim_rover.py') + ' --rate=50 --home=%f,%f,%u,%u' % ( HOME.lat, HOME.lng, HOME.alt, HOME.heading) runsim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) runsim.delaybeforesend = 0 util.pexpect_autoclose(runsim) runsim.expect('Starting at lat') sil = util.start_SIL('APMrover2') mavproxy = util.start_MAVProxy_SIL('APMrover2', options=options) mavproxy.expect('Logging to (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/APMrover2-test.mavlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) os.link(logfile, buildlog) mavproxy.expect('Received [0-9]+ parameters') util.expect_setup_callback(mavproxy, expect_callback) expect_list_clear() expect_list_extend([runsim, sil, mavproxy]) print("Started simulator") # 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
def build_examples(): '''run the build_examples.sh script''' print("Running build_examples.sh") if util.run_cmd(util.reltopdir('Tools/scripts/build_examples.sh'), dir=util.reltopdir('.')) != 0: print("Failed build_examples.sh") return False return True
def build_examples(): """run the build_examples.sh script""" print("Running build_examples.sh") if util.run_cmd(util.reltopdir("Tools/scripts/build_examples.sh"), dir=util.reltopdir(".")) != 0: print("Failed build_examples.sh") return False return True
def write_XMLresults(atype, results): '''write XML JUnit results''' from pymavlink.generator import mavtemplate t = mavtemplate.MAVTemplate() for x in glob.glob(util.reltopdir('Tools/autotest/junit.xml')): junit_xml = util.loadfile(x) f = open(util.reltopdir("../buildlogs/%s-%s" % (atype, os.path.basename(x))), mode='w') t.write(f, junit_xml, results) f.close()
def fly_ArduCopter_scripted(testname): '''fly ArduCopter in SIL ''' global homeloc sim_cmd = util.reltopdir('Tools/autotest/pysim/sim_multicopter.py') + ' --frame=%s --rate=400 --home=%f,%f,%u,%u' % ( FRAME, HOME.lat, HOME.lng, HOME.alt, HOME.heading) sim_cmd += ' --wind=6,45,.3' sil = util.start_SIL('ArduCopter', wipe=True) mavproxy = util.start_MAVProxy_SIL('ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter') mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send('param set SYSID_THISMAV %u\n' % random.randint(100, 200)) mavproxy.send("param load %s/ArduCopter.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('ArduCopter', height=HOME.alt) sim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) sim.delaybeforesend = 0 util.pexpect_autoclose(sim) options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter --streamrate=5' mavproxy = util.start_MAVProxy_SIL('ArduCopter', options=options) mavproxy.expect('Logging to (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/ArduCopter-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) os.link(logfile, buildlog) # 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, arducopter.expect_callback) expect_list_clear() expect_list_extend([sim, sil, mavproxy]) # 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
def build_all(): '''run the build_all.sh script''' print("Running build_all.sh") flags = "" if opts.incremental == True: print("Building for incremental") flags = "-i" if util.run_cmd(util.reltopdir('Tools/scripts/build_all.sh') + " " + flags , dir=util.reltopdir('.')) != 0: print("Failed build_all.sh") return False return True
def write_webresults(results): '''write webpage results''' from pymavlink.generator import mavtemplate t = mavtemplate.MAVTemplate() for h in glob.glob(util.reltopdir('Tools/autotest/web/*.html')): html = util.loadfile(h) f = open("buildlogs/%s" % os.path.basename(h), mode='w') t.write(f, html, results) f.close() for f in glob.glob(util.reltopdir('Tools/autotest/web/*.png')): shutil.copy(f, 'buildlogs/%s' % os.path.basename(f))
def convert_gpx(): '''convert any mavlog files to GPX and KML''' import glob mavlog = glob.glob(util.reltopdir("../buildlogs/*.mavlog")) for m in mavlog: util.run_cmd(util.reltopdir("../mavlink/pymavlink/examples/mavtogpx.py") + " --nofixcheck " + m) gpx = m + '.gpx' kml = m + '.kml' util.run_cmd('gpsbabel -i gpx -f %s -o kml,units=m,floating=1,extrude=1 -F %s' % (gpx, kml), checkfail=False) util.run_cmd('zip %s.kmz %s.kml' % (m, m), checkfail=False) return True
def write_webresults(results): '''write webpage results''' from pymavlink.generator import mavtemplate t = mavtemplate.MAVTemplate() for h in glob.glob(util.reltopdir('Tools/autotest/web/*.html')): html = util.loadfile(h) f = open(util.reltopdir("../buildlogs/%s" % os.path.basename(h)), mode='w') t.write(f, html, results) f.close() for f in glob.glob(util.reltopdir('Tools/autotest/web/*.png')): shutil.copy(f, util.reltopdir('../buildlogs/%s' % os.path.basename(f)))
def write_webresults(results): """write webpage results""" from pymavlink.generator import mavtemplate t = mavtemplate.MAVTemplate() for h in glob.glob(util.reltopdir("Tools/autotest/web/*.html")): html = util.loadfile(h) f = open(util.reltopdir("../buildlogs/%s" % os.path.basename(h)), mode="w") t.write(f, html, results) f.close() for f in glob.glob(util.reltopdir("Tools/autotest/web/*.png")): shutil.copy(f, util.reltopdir("../buildlogs/%s" % os.path.basename(f)))
def write_webresults(results): '''write webpage results''' sys.path.insert(0, os.path.join(util.reltopdir("../mavlink/pymavlink/generator"))) import mavtemplate t = mavtemplate.MAVTemplate() for h in glob.glob(util.reltopdir('Tools/autotest/web/*.html')): html = util.loadfile(h) f = open(util.reltopdir("../buildlogs/%s" % os.path.basename(h)), mode='w') t.write(f, html, results) f.close() for f in glob.glob(util.reltopdir('Tools/autotest/web/*.png')): shutil.copy(f, util.reltopdir('../buildlogs/%s' % os.path.basename(f)))
def convert_gpx(): '''convert any tlog files to GPX and KML''' import glob mavlog = glob.glob(util.reltopdir("../buildlogs/*.tlog")) for m in mavlog: util.run_cmd(util.reltopdir("modules/mavlink/pymavlink/tools/mavtogpx.py") + " --nofixcheck " + m) gpx = m + '.gpx' kml = m + '.kml' util.run_cmd('gpsbabel -i gpx -f %s -o kml,units=m,floating=1,extrude=1 -F %s' % (gpx, kml), checkfail=False) util.run_cmd('zip %s.kmz %s.kml' % (m, m), checkfail=False) util.run_cmd("mavflightview.py --imagefile=%s.png %s" % (m,m)) return True
def convert_gpx(): """convert any tlog files to GPX and KML""" import glob mavlog = glob.glob(util.reltopdir("../buildlogs/*.tlog")) for m in mavlog: util.run_cmd(util.reltopdir("modules/mavlink/pymavlink/tools/mavtogpx.py") + " --nofixcheck " + m) gpx = m + ".gpx" kml = m + ".kml" util.run_cmd("gpsbabel -i gpx -f %s -o kml,units=m,floating=1,extrude=1 -F %s" % (gpx, kml), checkfail=False) util.run_cmd("zip %s.kmz %s.kml" % (m, m), checkfail=False) util.run_cmd("mavflightview.py --imagefile=%s.png %s" % (m, m)) return True
def build_devrelease(): '''run the build_devrelease.sh script''' print("Running build_devrelease.sh") import shutil # copy the script as it changes git branch, which can change the script while running orig=util.reltopdir('Tools/scripts/build_devrelease.sh') copy=util.reltopdir('./build_devrelease.sh') shutil.copyfile(orig, copy) shutil.copymode(orig, copy) if util.run_cmd(copy, dir=util.reltopdir('.')) != 0: print("Failed build_devrelease.sh") return False return True
def convert_gpx(): print( "===== Converting buildlogs/*.tlog ====" ) '''convert any tlog files to GPX and KML''' import glob mavlog = glob.glob(util.reltopdir("../buildlogs/*.tlog")) for m in mavlog: util.run_cmd(util.reltopdir("../mavlink/pymavlink/tools/mavtogpx.py") + " --nofixcheck " + m) gpx = m + '.gpx' kml = m + '.kml' util.run_cmd('gpsbabel -i gpx -f %s -o kml,units=m,floating=1,extrude=1 -F %s' % (gpx, kml), checkfail=False) util.run_cmd('zip %s.kmz %s.kml' % (m, m), checkfail=False) util.run_cmd("mavflightview.py --imagefile=%s.png %s" % (m,m)) return True
def test_prerequesites(): '''check we have the right directories and tools to run tests''' print("Testing prerequesites") util.mkdir_p(util.reltopdir('../buildlogs')) if not os.path.exists(util.reltopdir('../HILTest/hil_quad.py')): print(''' You need to install HILTest in %s You can get it from git://git.samba.org/tridge/UAV/HILTest.git ''' % util.reltopdir('../HILTest')) return False return True
def write_XMLresults(atype, results): '''write XML JUnit results''' sys.path.insert( 0, os.path.join(util.reltopdir("../mavlink/pymavlink/generator"))) import mavtemplate t = mavtemplate.MAVTemplate() for x in glob.glob(util.reltopdir('Tools/autotest/junit.xml')): junit_xml = util.loadfile(x) f = open(util.reltopdir("../buildlogs/%s-%s" % (atype, os.path.basename(x))), mode='w') t.write(f, junit_xml, results) f.close()
def build_binaries(): """run the build_binaries.sh script""" print("Running build_binaries.sh") import shutil # copy the script as it changes git branch, which can change the script while running orig = util.reltopdir("Tools/scripts/build_binaries.sh") copy = util.reltopdir("./build_binaries.sh") shutil.copyfile(orig, copy) shutil.copymode(orig, copy) if util.run_cmd(copy, dir=util.reltopdir(".")) != 0: print("Failed build_binaries.sh") return False return True
def binary_path(step, debug=False): if step.find("ArduCopter") != -1: binary_name = "arducopter-quad" elif step.find("ArduPlane") != -1: binary_name = "arduplane" elif step.find("APMrover2") != -1: binary_name = "ardurover" elif step.find("AntennaTracker") != -1: binary_name = "antennatracker" elif step.find("CopterAVC") != -1: binary_name = "arducopter-heli" elif step.find("QuadPlane") != -1: binary_name = "arduplane" else: # cope with builds that don't have a specific binary return None if debug: binary_basedir = "sitl-debug" else: binary_basedir = "sitl" binary = util.reltopdir(os.path.join('build', binary_basedir, 'bin', binary_name)) if not os.path.exists(binary): if os.path.exists(binary + ".exe"): binary_path += ".exe" else: raise ValueError("Binary (%s) does not exist" % (binary,)) return binary
def get_default_params(atype, binary): '''get default parameters''' # use rover simulator so SITL is not starved of input from pymavlink import mavutil HOME=mavutil.location(40.071374969556928,-105.22978898137808,1583.702759,246) if binary.find("plane") != -1 or binary.find("rover") != -1: frame = "rover" else: frame = "+" home = "%f,%f,%u,%u" % (HOME.lat, HOME.lng, HOME.alt, HOME.heading) sil = util.start_SIL(binary, wipe=True, model=frame, home=home, speedup=10) mavproxy = util.start_MAVProxy_SIL(atype) print("Dumping defaults") idx = mavproxy.expect(['Please Run Setup', 'Saved [0-9]+ parameters to (\S+)']) if idx == 0: # we need to restart it after eeprom erase util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL(binary, model=frame, home=home, speedup=10) mavproxy = util.start_MAVProxy_SIL(atype) idx = mavproxy.expect('Saved [0-9]+ parameters to (\S+)') parmfile = mavproxy.match.group(1) dest = util.reltopdir('../buildlogs/%s-defaults.parm' % atype) shutil.copy(parmfile, dest) util.pexpect_close(mavproxy) util.pexpect_close(sil) print("Saved defaults for %s to %s" % (atype, dest)) return True
def dump_logs(atype): '''dump DataFlash logs''' print("Dumping logs for %s" % atype) sil = util.start_SIL(atype) logfile = util.reltopdir('../buildlogs/%s.flashlog' % atype) log = open(logfile, mode='w') mavproxy = util.start_MAVProxy_SIL(atype, setup=True, logfile=log) mavproxy.send('\n\n\n') print("navigating menus") mavproxy.expect(']') mavproxy.send("logs\n") mavproxy.expect("logs enabled:") lognums = [] i = mavproxy.expect(["No logs", "(\d+) logs"]) if i == 0: numlogs = 0 else: numlogs = int(mavproxy.match.group(1)) for i in range(numlogs): mavproxy.expect("Log (\d+)") lognums.append(int(mavproxy.match.group(1))) mavproxy.expect("Log]") for i in range(numlogs): print("Dumping log %u (i=%u)" % (lognums[i], i)) mavproxy.send("dump %u\n" % lognums[i]) mavproxy.expect("logs enabled:", timeout=120) mavproxy.expect("Log]") util.pexpect_close(mavproxy) util.pexpect_close(sil) log.close() print("Saved log for %s to %s" % (atype, logfile)) return True
def dump_logs(atype): '''dump DataFlash logs''' print("Dumping logs for %s" % atype) sil = util.start_SIL(atype) logfile = util.reltopdir('../buildlogs/%s.flashlog' % atype) log = open(logfile, mode='w') mavproxy = util.start_MAVProxy_SIL(atype, setup=True, logfile=log) mavproxy.send('\n\n\n') print("navigating menus") mavproxy.expect(']') mavproxy.send("logs\n") mavproxy.expect("logs enabled:") lognums = [] i = mavproxy.expect(["No logs", "(\d+) logs"]) if i == 0: numlogs = 0 else: numlogs = int(mavproxy.match.group(1)) for i in range(numlogs): mavproxy.expect("Log (\d+),") lognums.append(int(mavproxy.match.group(1))) mavproxy.expect("Log]") for i in range(numlogs): print("Dumping log %u (i=%u)" % (lognums[i], i)) mavproxy.send("dump %u\n" % lognums[i]) mavproxy.expect("logs enabled:", timeout=120) mavproxy.expect("Log]") util.pexpect_close(mavproxy) util.pexpect_close(sil) log.close() print("Saved log for %s to %s" % (atype, logfile)) return True
def fly_CopterAVC(binary, viewerip=None, map=False, valgrind=False, gdb=False): """fly ArduCopter in SIL for AVC2013 mission """ global homeloc home = "%f,%f,%u,%u" % (AVCHOME.lat, AVCHOME.lng, AVCHOME.alt, AVCHOME.heading) sil = util.start_SIL(binary, wipe=True, model="heli", home=home, speedup=speedup_default) mavproxy = util.start_MAVProxy_SIL("ArduCopter", options="--sitl=127.0.0.1:5501 --out=127.0.0.1:19550") mavproxy.expect("Received [0-9]+ parameters") # setup test parameters mavproxy.send("param load %s/Helicopter.parm\n" % testdir) mavproxy.expect("Loaded [0-9]+ parameters") mavproxy.send("param set LOG_REPLAY 1\n") mavproxy.send("param set LOG_DISARMED 1\n") time.sleep(3) # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL(binary, model="heli", home=home, speedup=speedup_default, valgrind=valgrind, gdb=gdb) options = "--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=5" if viewerip: options += " --out=%s:14550" % viewerip if map: options += " --map" mavproxy = util.start_MAVProxy_SIL("ArduCopter", options=options) mavproxy.expect("Telemetry log: (\S+)") 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) try: os.link(logfile, buildlog) except Exception: pass # 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() expect_list_extend([sil, mavproxy]) if map: mavproxy.send("map icon 40.072467969730496 -105.2314389590174\n") mavproxy.send("map icon 40.072600990533829 -105.23146100342274\n") # 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
def fly_CopterAVC(viewerip=None, map=False): '''fly ArduCopter in SIL for AVC2013 mission ''' global homeloc if TARGET != 'sitl': util.build_SIL('ArduCopter', target=TARGET) home = "%f,%f,%u,%u" % (AVCHOME.lat, AVCHOME.lng, AVCHOME.alt, AVCHOME.heading) sil = util.start_SIL('ArduCopter', wipe=True, model='heli', home=home, speedup=speedup_default) mavproxy = util.start_MAVProxy_SIL('ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550') mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send("param load %s/Helicopter.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('ArduCopter', model='heli', home=home, speedup=speedup_default) options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=5' if viewerip: options += ' --out=%s:14550' % viewerip if map: options += ' --map' mavproxy = util.start_MAVProxy_SIL('ArduCopter', options=options) mavproxy.expect('Telemetry log: (\S+)') 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) try: os.link(logfile, buildlog) except Exception: pass # 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() expect_list_extend([sil, mavproxy]) if map: mavproxy.send('map icon 40.072467969730496 -105.2314389590174\n') mavproxy.send('map icon 40.072600990533829 -105.23146100342274\n') # 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
def build_parameters(): '''run the param_parse.py script''' print("Running param_parse.py") if util.run_cmd(util.reltopdir('Tools/autotest/param_metadata/param_parse.py'), dir=util.reltopdir('.')) != 0: print("Failed param_parse.py") return False return True
def build_parameters(): """run the param_parse.py script""" print("Running param_parse.py") if util.run_cmd(util.reltopdir("Tools/autotest/param_metadata/param_parse.py"), dir=util.reltopdir(".")) != 0: print("Failed param_parse.py") return False return True
def get_default_params(atype): '''get default parameters''' # use rover simulator so SITL is not starved of input from pymavlink import mavutil HOME=mavutil.location(40.071374969556928,-105.22978898137808,1583.702759,246) sim_cmd = util.reltopdir('Tools/autotest/pysim/sim_rover.py') + ' --rate=200 --speedup=100 --home=%f,%f,%u,%u' % ( HOME.lat, HOME.lng, HOME.alt, HOME.heading) runsim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) runsim.delaybeforesend = 0 runsim.expect('Starting at lat') sil = util.start_SIL(atype, wipe=True) mavproxy = util.start_MAVProxy_SIL(atype) print("Dumping defaults") idx = mavproxy.expect(['Please Run Setup', 'Saved [0-9]+ parameters to (\S+)']) if idx == 0: # we need to restart it after eeprom erase util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL(atype) mavproxy = util.start_MAVProxy_SIL(atype) idx = mavproxy.expect('Saved [0-9]+ parameters to (\S+)') parmfile = mavproxy.match.group(1) dest = 'buildlogs/%s-defaults.parm' % atype shutil.copy(parmfile, dest) util.pexpect_close(mavproxy) util.pexpect_close(sil) util.pexpect_close(runsim) print("Saved defaults for %s to %s" % (atype, dest)) return True
def __init__(self): self.date = time.asctime() self.githash = util.run_cmd('git rev-parse HEAD', output=True, dir=util.reltopdir('.')).strip() self.tests = [] self.files = []
def binary_path(step, debug=False): if step.find("ArduCopter") != -1: binary_name = "arducopter-quad" elif step.find("ArduPlane") != -1: binary_name = "arduplane" elif step.find("APMrover2") != -1: binary_name = "ardurover" elif step.find("AntennaTracker") != -1: binary_name = "antennatracker" elif step.find("CopterAVC") != -1: binary_name = "arducopter-heli" elif step.find("QuadPlane") != -1: binary_name = "arduplane" else: raise(ValueError("Unable to determine binary name for step %s" % (step,))) if debug: binary_basedir = "sitl-debug" else: binary_basedir = "sitl" binary = util.reltopdir(os.path.join('build', binary_basedir, 'bin', binary_name)) if not os.path.exists(binary): if os.path.exists(binary + ".exe"): binary_path += ".exe" else: raise ValueError("Binary (%s) does not exist" % (binary,)) return binary
def drive_APMrover2(viewerip=None, map=False): '''drive APMrover2 in SIL you can pass viewerip as an IP address to optionally send fg and mavproxy packets too for local viewing of the mission in real time ''' global homeloc options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10' if viewerip: options += " --out=%s:14550" % viewerip if map: options += ' --map' home = "%f,%f,%u,%u" % (HOME.lat, HOME.lng, HOME.alt, HOME.heading) sil = util.start_SIL('APMrover2', wipe=True, model='rover', home=home, speedup=10) mavproxy = util.start_MAVProxy_SIL('APMrover2', options=options) print("WAITING FOR PARAMETERS") mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send("param load %s/Rover.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # restart with new parms util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('APMrover2', model='rover', home=home, speedup=10) mavproxy = util.start_MAVProxy_SIL('APMrover2', options=options) mavproxy.expect('Telemetry log: (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/APMrover2-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: pass mavproxy.expect('Received [0-9]+ parameters') util.expect_setup_callback(mavproxy, expect_callback) expect_list_clear() expect_list_extend([sil, mavproxy]) print("Started simulator") # 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
def drive_APMrover2(viewerip=None, map=False, valgrind=False): '''drive APMrover2 in SIL you can pass viewerip as an IP address to optionally send fg and mavproxy packets too for local viewing of the mission in real time ''' global homeloc options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10' if viewerip: options += " --out=%s:14550" % viewerip if map: options += ' --map' home = "%f,%f,%u,%u" % (HOME.lat, HOME.lng, HOME.alt, HOME.heading) sil = util.start_SIL('APMrover2', wipe=True, model='rover', home=home, speedup=10) mavproxy = util.start_MAVProxy_SIL('APMrover2', options=options) print("WAITING FOR PARAMETERS") mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send("param load %s/Rover.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # restart with new parms util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('APMrover2', model='rover', home=home, speedup=10, valgrind=valgrind) mavproxy = util.start_MAVProxy_SIL('APMrover2', options=options) mavproxy.expect('Telemetry log: (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/APMrover2-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: pass mavproxy.expect('Received [0-9]+ parameters') util.expect_setup_callback(mavproxy, expect_callback) expect_list_clear() expect_list_extend([sil, mavproxy]) print("Started simulator") # 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
def run_mission(mission_path, frame, home, viewerip=None): sim_cmd = util.reltopdir('Tools/autotest/pysim/sim_multicopter.py') sim_cmd += ' --frame=%s --rate=400 --home=%f,%f,%u,%u' % ( frame, home.lat, home.lng, home.alt, home.heading) sim_cmd += ' --wind=6,45,.3' if viewerip: sim_cmd += ' --fgout=%s:5503' % viewerip sil = util.start_SIL('ArduCopter', wipe=True) mavproxy = util.start_MAVProxy_SIL( 'ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter') mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send('param set SYSID_THISMAV %u\n' % random.randint(100, 200)) mavproxy.send("param load %s/autotest/ArduCopter.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') mavproxy.send('module load mmap\n') # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('ArduCopter', height=home.alt) print 'Executing command %s' % (sim_cmd,) sim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) sim.delaybeforesend = 0 util.pexpect_autoclose(sim) options = ('--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter ' '--streamrate=5') if viewerip: options += ' --out=%s:14550' % viewerip mavproxy = util.start_MAVProxy_SIL('ArduCopter', options=options) mavproxy.expect('Logging to (\S+)') logfile = mavproxy.match.group(1) print 'Saving log %s' % (logfile,) # 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']) mavproxy.send('module load mmap\n') util.expect_setup_callback(mavproxy, common.expect_callback) common.expect_list_clear() common.expect_list_extend([sim, sil, mavproxy]) # get a mavlink connection going try: mav = mavutil.mavlink_connection('127.0.0.1:19550', robust_parsing=True) except Exception, msg: error("Failed to start mavlink connection on 127.0.0.1:19550" % msg) raise
def fly_QuadPlane(binary, viewerip=None, map=False, valgrind=False, gdb=False): '''fly QuadPlane 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 ''' global homeloc options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10' if viewerip: options += " --out=%s:14550" % viewerip if map: options += ' --map' sil = util.start_SIL(binary, model='quadplane', wipe=True, home=HOME_LOCATION, speedup=10, defaults_file=os.path.join( testdir, 'default_params/quadplane.parm'), valgrind=valgrind, gdb=gdb) mavproxy = util.start_MAVProxy_SIL('QuadPlane', options=options) mavproxy.expect('Telemetry log: (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/QuadPlane-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: pass util.expect_setup_callback(mavproxy, expect_callback) mavproxy.expect('Received [0-9]+ parameters') expect_list_clear() expect_list_extend([sil, mavproxy]) print("Started simulator") # 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
def check_logs(step): '''check for log files from a step''' print("check step: ", step) if step.startswith('fly.'): vehicle = step[4:] elif step.startswith('drive.'): vehicle = step[6:] else: return logs = glob.glob("logs/*.BIN") for log in logs: bname = os.path.basename(log) newname = util.reltopdir("../buildlogs/%s-%s" % (vehicle, bname)) print("Renaming %s to %s" % (log, newname)) os.rename(log, newname) corefile = "core" if os.path.exists(corefile): newname = util.reltopdir("../buildlogs/%s.core" % vehicle) print("Renaming %s to %s" % (corefile, newname)) os.rename(corefile, newname) util.run_cmd('/bin/cp A*/A*.elf ../buildlogs', dir=util.reltopdir('.'))
def fly_ArduPlane(binary, viewerip=None, map=False, valgrind=False, gdb=False): '''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 ''' global homeloc options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10' if viewerip: options += " --out=%s:14550" % viewerip if map: options += ' --map' sil = util.start_SIL(binary, model='plane-elevrev', home=HOME_LOCATION, speedup=10, valgrind=valgrind, gdb=gdb, defaults_file=os.path.join(testdir, 'default_params/ArduPlane.parm')) mavproxy = util.start_MAVProxy_SIL('ArduPlane', options=options) mavproxy.expect('Telemetry log: (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/ArduPlane-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: pass util.expect_setup_callback(mavproxy, expect_callback) mavproxy.expect('Received [0-9]+ parameters') expect_list_clear() expect_list_extend([sil, mavproxy]) print("Started simulator") # 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
def get_default_params(atype): '''get default parameters''' sil = util.start_SIL(atype, wipe=True) mavproxy = util.start_MAVProxy_SIL(atype) print("Dumping defaults") idx = mavproxy.expect(['Please Run Setup', 'Saved [0-9]+ parameters to (\S+)']) if idx == 0: # we need to restart it after eeprom erase util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL(atype) mavproxy = util.start_MAVProxy_SIL(atype) idx = mavproxy.expect('Saved [0-9]+ parameters to (\S+)') parmfile = mavproxy.match.group(1) dest = util.reltopdir('../buildlogs/%s.defaults.txt' % atype) shutil.copy(parmfile, dest) util.pexpect_close(mavproxy) util.pexpect_close(sil) print("Saved defaults for %s to %s" % (atype, dest)) return True
def get_default_params(atype): '''get default parameters''' # use rover simulator so SITL is not starved of input from pymavlink import mavutil HOME = mavutil.location(40.071374969556928, -105.22978898137808, 1583.702759, 246) sim_cmd = util.reltopdir( 'Tools/autotest/pysim/sim_rover.py' ) + ' --rate=200 --speedup=100 --home=%f,%f,%u,%u' % ( HOME.lat, HOME.lng, HOME.alt, HOME.heading) runsim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) runsim.delaybeforesend = 0 runsim.expect('Starting at lat') sil = util.start_SIL(atype, wipe=True) mavproxy = util.start_MAVProxy_SIL(atype) print("Dumping defaults") idx = mavproxy.expect( ['Please Run Setup', 'Saved [0-9]+ parameters to (\S+)']) if idx == 0: # we need to restart it after eeprom erase util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL(atype) mavproxy = util.start_MAVProxy_SIL(atype) idx = mavproxy.expect('Saved [0-9]+ parameters to (\S+)') parmfile = mavproxy.match.group(1) dest = 'buildlogs/%s-defaults.parm' % atype shutil.copy(parmfile, dest) util.pexpect_close(mavproxy) util.pexpect_close(sil) util.pexpect_close(runsim) print("Saved defaults for %s to %s" % (atype, dest)) return True
failed = True if not fly_LOITER(mavproxy, mav): print("Failed LOITER") failed = True if not fly_CIRCLE(mavproxy, mav): print("Failed CIRCLE") failed = True if not fly_mission(mavproxy, mav, os.path.join(testdir, "ap1.txt"), height_accuracy=10, target_altitude=homeloc.alt + 100): print("Failed mission") failed = True if not log_download(mavproxy, mav, util.reltopdir("../buildlogs/ArduPlane-log.bin")): print("Failed log download") failed = True except pexpect.TIMEOUT, e: print("Failed with timeout") failed = True mav.close() util.pexpect_close(mavproxy) util.pexpect_close(sil) util.pexpect_close(runsim) if os.path.exists('ArduPlane-valgrind.log'): os.chmod('ArduPlane-valgrind.log', 0644) shutil.copy("ArduPlane-valgrind.log", util.reltopdir("../buildlogs/ArduPlane-valgrind.log"))
def fly_ArduCopter(viewerip=None, map=False): '''fly ArduCopter 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 ''' global homeloc if TARGET != 'sitl': util.build_SIL('ArduCopter', target=TARGET) home = "%f,%f,%u,%u" % (HOME.lat, HOME.lng, HOME.alt, HOME.heading) sil = util.start_SIL('ArduCopter', wipe=True, model='+', home=home, speedup=speedup_default) mavproxy = util.start_MAVProxy_SIL('ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter') mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send("param load %s/copter_params.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('ArduCopter', model='+', home=home, speedup=speedup_default) options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter --streamrate=5' if viewerip: options += ' --out=%s:14550' % viewerip if map: options += ' --map' mavproxy = util.start_MAVProxy_SIL('ArduCopter', options=options) mavproxy.expect('Telemetry log: (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/ArduCopter-test.tlog") print("buildlog=%s" % buildlog) copyTLog = False if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: print( "WARN: Failed to create symlink: " + logfile + " => " + buildlog + ", Will copy tlog manually to target location" ) copyTLog = True # 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() expect_list_extend([sil, mavproxy]) # 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
def setup_class(cls): #Set this to False to enable logging. DEBUG = False CONSOLE = False cls.TIMEOUT = 5 cls.DELAY = 2 cls.resource_path = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'TestGroupLib/'), 'Resources/') #start MAVLink, etc try: os.remove('eeprom.bin') except OSError: pass try: os.remove('jsb_pipe') os.remove('mavproxy_pipe') except Exception: pass util.run_cmd('mkfifo mavproxy_pipe') util.run_cmd('mkfifo jsb_pipe') if DEBUG: util.run_cmd('xterm -e tail -f jsb_pipe &') util.run_cmd('xterm -e tail -f mavproxy_pipe &') util.run_cmd('echo "INITIALIZED MAVPROXY PIPE" > mavproxy_pipe &') util.run_cmd('echo "INITIALIZED JSBSIM PIPE" > jsb_pipe &') cls.homeloc = None HOME_LOCATION = '35.7168007,-120.7644466,275,295' #McMillan Lat/Lon/Alt/Heading WIND = "0,180,0.0" # speed,direction,variance options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=100 ' #Start SITL cls.sil = util.start_SIL('ArduPlane', wipe=True) cls.mavproxy = util.start_MAVProxy_SIL('ArduPlane', options=options) cls.mavproxy.expect('Received [0-9]+ parameters') #Load SITL params cls.mavproxy.send("param load %ssitl.parm\n" % cls.resource_path) cls.mavproxy.expect('Loaded [0-9]+ parameters') #Fetch list of params cls.mavproxy.send("param fetch\n") #TODO: Optimize this. Is it necessary to start and close it? util.pexpect_close(cls.mavproxy) util.pexpect_close(cls.sil) #Start JSBSim simulation cmd = util.reltopdir("Tools/autotest/jsbsim/runsim.py") cmd += " --home=%s --wind=%s" % (HOME_LOCATION, WIND) #cls.runsim = pexpect.spawn(cmd, logfile=sys.stdout, timeout=10) cls.runsim = pexpect.spawn(cmd, logfile=file('jsb_pipe', 'w+', 0), timeout=10) cls.runsim.delaybeforesend = 0 util.pexpect_autoclose(cls.runsim) cls.runsim.expect('Simulator ready to fly.') cls.sil = util.start_SIL('ArduPlane', valgrind=True) options += ' --map' if CONSOLE: options += ' --console' cls.mavproxy = util.start_MAVProxy_SIL('ArduPlane', logfile=file( 'mavproxy_pipe', 'w+', 0), options=options) #TODO: Make these easier to find cls.mavproxy.expect('Logging to (\S+)') logfile = cls.mavproxy.match.group(1) print("LOGFILE %s" % logfile) #TODO: Make these easier to find buildlog = util.reltopdir("../buildlogs/ArduPlane-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: pass cls.mavproxy.expect('Received [0-9]+ parameters') util.expect_setup_callback(cls.mavproxy, expect_callback) expect_list_clear() expect_list_extend([cls.runsim, cls.sil, cls.mavproxy]) print("Started simulator.") #Get a mavlink connection started. try: cls.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
print("########## Test RTL ##########") print("#") if not fly_RTL(mavproxy, mav): failed_test_msg = "fly_RTL failed" print(failed_test_msg) failed = True print("# Fly copter mission") if not fly_auto_test(mavproxy, mav): failed_test_msg = "fly_auto_test failed" print(failed_test_msg) failed = True else: print("Flew copter mission OK") if not log_download(mavproxy, mav, util.reltopdir("../buildlogs/ArduCopter-log.bin")): failed_test_msg = "log_download failed" print(failed_test_msg) failed = True except pexpect.TIMEOUT, failed_test_msg: failed_test_msg = "Timeout" failed = True mav.close() util.pexpect_close(mavproxy) util.pexpect_close(sil) util.pexpect_close(sim) if os.path.exists('ArduCopter-valgrind.log'): os.chmod('ArduCopter-valgrind.log', 0644)
#!/usr/bin/env python # APM automatic test suite # Andrew Tridgell, October 2011 import pexpect, os, sys, shutil, atexit import optparse, fnmatch, time, glob, traceback, signal sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pysim')) import util os.environ['PYTHONUNBUFFERED'] = '1' os.putenv('TMPDIR', util.reltopdir('tmp')) def get_default_params(atype, binary): '''get default parameters''' # use rover simulator so SITL is not starved of input from pymavlink import mavutil HOME=mavutil.location(40.071374969556928,-105.22978898137808,1583.702759,246) if binary.find("plane") != -1 or binary.find("rover") != -1: frame = "rover" else: frame = "+" home = "%f,%f,%u,%u" % (HOME.lat, HOME.lng, HOME.alt, HOME.heading) sil = util.start_SIL(binary, wipe=True, model=frame, home=home, speedup=10) mavproxy = util.start_MAVProxy_SIL(atype) print("Dumping defaults") idx = mavproxy.expect(['Please Run Setup', 'Saved [0-9]+ parameters to (\S+)'])
def test_prerequisites(): '''check we have the right directories and tools to run tests''' print("Testing prerequisites") util.mkdir_p(util.reltopdir('../buildlogs')) return True
def fly_CopterAVC(viewerip=None, map=False): '''fly ArduCopter in SIL for AVC2013 mission ''' global homeloc if TARGET != 'sitl': util.build_SIL('ArduCopter', target=TARGET) sim_cmd = util.reltopdir('Tools/autotest/pysim/sim_multicopter.py') + ' --frame=%s --rate=400 --home=%f,%f,%u,%u' % ( FRAME, AVCHOME.lat, AVCHOME.lng, AVCHOME.alt, AVCHOME.heading) if viewerip: sim_cmd += ' --fgout=%s:5503' % viewerip sil = util.start_SIL('ArduCopter', wipe=True) mavproxy = util.start_MAVProxy_SIL('ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter') mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send("param load %s/copter_AVC2013_params.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('ArduCopter', height=HOME.alt) sim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) sim.delaybeforesend = 0 util.pexpect_autoclose(sim) options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter --streamrate=5' if viewerip: options += ' --out=%s:14550' % viewerip if map: options += ' --map' mavproxy = util.start_MAVProxy_SIL('ArduCopter', options=options) mavproxy.expect('Logging to (\S+)') 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) try: os.link(logfile, buildlog) except Exception: pass # 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() expect_list_extend([sim, sil, mavproxy]) if map: mavproxy.send('map icon 40.072467969730496 -105.2314389590174\n') mavproxy.send('map icon 40.072600990533829 -105.23146100342274\n') # 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
failed = True else: print("Flew mission2 OK") print("# Land") if not land(mavproxy, mav): print("land failed") failed = True #print("# disarm motors") #if not disarm_motors(mavproxy, mav): # print("disarm_motors failed") # failed = True except pexpect.TIMEOUT, e: failed = True mav.close() util.pexpect_close(mavproxy) util.pexpect_close(sil) util.pexpect_close(sim) if os.path.exists('ArduCopter-valgrind.log'): os.chmod('ArduCopter-valgrind.log', 0644) shutil.copy("ArduCopter-valgrind.log", util.reltopdir("../buildlogs/ArduCopter-valgrind.log")) if failed: print("FAILED: %s" % e) return False return True
def fly_ArduCopter(viewerip=None): '''fly ArduCopter 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 ''' global homeloc if TARGET != 'sitl': util.build_SIL('ArduCopter', target=TARGET) sim_cmd = util.reltopdir( 'Tools/autotest/pysim/sim_multicopter.py' ) + ' --frame=%s --rate=400 --home=%f,%f,%u,%u' % ( FRAME, HOME.lat, HOME.lng, HOME.alt, HOME.heading) sim_cmd += ' --wind=6,45,.3' if viewerip: sim_cmd += ' --fgout=%s:5503' % viewerip sil = util.start_SIL('ArduCopter', wipe=True) mavproxy = util.start_MAVProxy_SIL( 'ArduCopter', options='--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter') mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send('param set SYSID_THISMAV %u\n' % random.randint(100, 200)) mavproxy.send("param load %s/ArduCopter.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') # reboot with new parameters util.pexpect_close(mavproxy) util.pexpect_close(sil) sil = util.start_SIL('ArduCopter', height=HOME.alt) sim = pexpect.spawn(sim_cmd, logfile=sys.stdout, timeout=10) sim.delaybeforesend = 0 util.pexpect_autoclose(sim) options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --quadcopter --streamrate=5' if viewerip: options += ' --out=%s:14550' % viewerip mavproxy = util.start_MAVProxy_SIL('ArduCopter', options=options) mavproxy.expect('Logging to (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/ArduCopter-test.mavlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) os.link(logfile, buildlog) # 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() expect_list_extend([sim, sil, mavproxy]) # 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
def fly_ArduPlane(viewerip=None, map=False): '''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 ''' global homeloc options = '--sitl=127.0.0.1:5501 --out=127.0.0.1:19550 --streamrate=10' if viewerip: options += " --out=%s:14550" % viewerip if map: options += ' --map' sil = util.start_SIL('ArduPlane', wipe=True) mavproxy = util.start_MAVProxy_SIL('ArduPlane', options=options) mavproxy.expect('Received [0-9]+ parameters') # setup test parameters mavproxy.send("param load %s/ArduPlane.parm\n" % testdir) mavproxy.expect('Loaded [0-9]+ parameters') mavproxy.send("param fetch\n") # restart with new parms util.pexpect_close(mavproxy) util.pexpect_close(sil) cmd = util.reltopdir("Tools/autotest/jsbsim/runsim.py") cmd += " --home=%s --wind=%s" % (HOME_LOCATION, WIND) if viewerip: cmd += " --fgout=%s:5503" % viewerip runsim = pexpect.spawn(cmd, logfile=sys.stdout, timeout=10) runsim.delaybeforesend = 0 util.pexpect_autoclose(runsim) runsim.expect('Simulator ready to fly') sil = util.start_SIL('ArduPlane') mavproxy = util.start_MAVProxy_SIL('ArduPlane', options=options) mavproxy.expect('Logging to (\S+)') logfile = mavproxy.match.group(1) print("LOGFILE %s" % logfile) buildlog = util.reltopdir("../buildlogs/ArduPlane-test.tlog") print("buildlog=%s" % buildlog) if os.path.exists(buildlog): os.unlink(buildlog) try: os.link(logfile, buildlog) except Exception: pass mavproxy.expect('Received [0-9]+ parameters') util.expect_setup_callback(mavproxy, expect_callback) expect_list_clear() expect_list_extend([runsim, sil, mavproxy]) print("Started simulator") # 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
def addglobimage(self, name, pattern): '''add a set of images''' import glob for f in glob.glob(util.reltopdir('../buildlogs/%s' % pattern)): self.addimage(name, os.path.basename(f))
parser.add_option("--elevon", action='store_true', default=False, help='assume elevon input') parser.add_option("--revthr", action='store_true', default=False, help='reverse throttle') parser.add_option("--vtail", action='store_true', default=False, help='assume vtail input') parser.add_option("--wind", dest="wind", help="Simulate wind (speed,direction,turbulance)", default='0,0,0') parser.add_option("--rate", type='int', help="Simulation rate (Hz)", default=1000) parser.add_option("--speedup", type='float', default=1.0, help="speedup from realtime") (opts, args) = parser.parse_args() for m in [ 'home', 'script' ]: if not opts.__dict__[m]: print("Missing required option '%s'" % m) parser.print_help() sys.exit(1) os.chdir(util.reltopdir('Tools/autotest')) # kill off child when we exit atexit.register(util.pexpect_close_all) setup_template(opts.home) # start child cmd = "JSBSim --realtime --suspend --nice --simulation-rate=%u --logdirectivefile=jsb_sim/fgout.xml --script=%s" % (opts.rate, opts.script) if opts.options: cmd += ' %s' % opts.options jsb = pexpect.spawn(cmd, logfile=sys.stdout, timeout=10) jsb.delaybeforesend = 0 util.pexpect_autoclose(jsb) i = jsb.expect(["Successfully bound to socket for input on port (\d+)",
try: print("Waiting for a heartbeat with mavlink protocol %s" % mav.WIRE_PROTOCOL_VERSION) mav.wait_heartbeat() print("Setting up RC parameters") setup_rc(mavproxy) print("Waiting for GPS fix") mav.wait_gps_fix() homeloc = mav.location() print("Home location: %s" % homeloc) if not arm_rover(mavproxy, mav): print("Failed to ARM") failed = True if not drive_mission(mavproxy, mav, os.path.join(testdir, "rover1.txt")): print("Failed mission") failed = True if not log_download(mavproxy, mav, util.reltopdir("../buildlogs/APMrover2-log.bin")): print("Failed log download") failed = True # if not drive_left_circuit(mavproxy, mav): # print("Failed left circuit") # failed = True # if not drive_RTL(mavproxy, mav): # print("Failed RTL") # failed = True except pexpect.TIMEOUT, e: print("Failed with timeout") failed = True mav.close() util.pexpect_close(mavproxy) util.pexpect_close(sil)