2016-04-27 22:34:15 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
"""
|
|
|
|
Framework to start a simulated vehicle and connect it to MAVProxy.
|
|
|
|
|
|
|
|
Peter Barker, April 2016
|
|
|
|
based on sim_vehicle.sh by Andrew Tridgell, October 2011
|
2021-02-21 04:48:07 -04:00
|
|
|
|
|
|
|
AP_FLAKE8_CLEAN
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
"""
|
2016-11-08 06:37:02 -04:00
|
|
|
from __future__ import print_function
|
2016-04-27 22:34:15 -03:00
|
|
|
|
|
|
|
import atexit
|
2021-02-21 04:48:07 -04:00
|
|
|
import datetime
|
2016-12-16 13:52:19 -04:00
|
|
|
import errno
|
2016-07-04 15:28:06 -03:00
|
|
|
import optparse
|
2016-04-27 22:34:15 -03:00
|
|
|
import os
|
2016-05-13 17:55:06 -03:00
|
|
|
import os.path
|
2016-11-14 22:52:34 -04:00
|
|
|
import re
|
2016-07-04 15:28:06 -03:00
|
|
|
import signal
|
2016-04-27 22:34:15 -03:00
|
|
|
import subprocess
|
2016-07-04 15:28:06 -03:00
|
|
|
import sys
|
2016-04-27 22:34:15 -03:00
|
|
|
import tempfile
|
2017-02-19 20:33:55 -04:00
|
|
|
import textwrap
|
2016-04-27 22:34:15 -03:00
|
|
|
import time
|
2016-08-29 21:49:16 -03:00
|
|
|
import shlex
|
2020-03-09 17:09:28 -03:00
|
|
|
import binascii
|
2021-06-27 18:55:32 -03:00
|
|
|
import math
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2022-01-26 13:20:18 -04:00
|
|
|
from pysim import util
|
2017-09-17 23:50:38 -03:00
|
|
|
from pysim import vehicleinfo
|
|
|
|
|
2020-09-04 19:24:20 -03:00
|
|
|
|
2016-06-23 12:27:28 -03:00
|
|
|
# List of open terminal windows for macosx
|
|
|
|
windowID = []
|
|
|
|
|
2020-01-29 11:31:09 -04:00
|
|
|
autotest_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
root_dir = os.path.realpath(os.path.join(autotest_dir, '../..'))
|
2016-06-23 12:27:28 -03:00
|
|
|
|
2021-09-03 12:03:29 -03:00
|
|
|
try:
|
|
|
|
from pymavlink import mavextra
|
|
|
|
except ImportError:
|
|
|
|
sys.path.append(os.path.join(root_dir, "modules/mavlink"))
|
|
|
|
from pymavlink import mavextra
|
|
|
|
|
2020-03-09 17:09:28 -03:00
|
|
|
os.environ["SIM_VEHICLE_SESSION"] = binascii.hexlify(os.urandom(8)).decode()
|
|
|
|
|
2021-02-21 04:48:07 -04:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
class CompatError(Exception):
|
2017-09-17 23:50:38 -03:00
|
|
|
"""A custom exception class to hold state if we encounter the parse
|
|
|
|
error we are looking for"""
|
2016-07-04 15:28:06 -03:00
|
|
|
def __init__(self, error, opts, rargs):
|
|
|
|
Exception.__init__(self, error)
|
2016-04-27 22:34:15 -03:00
|
|
|
self.opts = opts
|
|
|
|
self.rargs = rargs
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
class CompatOptionParser(optparse.OptionParser):
|
2017-09-17 23:50:38 -03:00
|
|
|
"""An option parser which emulates the behaviour of the old
|
|
|
|
sim_vehicle.sh; if passed -C, the first argument not understood starts
|
|
|
|
a list of arguments that are passed straight to mavproxy
|
|
|
|
"""
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2017-02-19 20:33:55 -04:00
|
|
|
class CustomFormatter(optparse.IndentedHelpFormatter):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-09-17 23:50:38 -03:00
|
|
|
optparse.IndentedHelpFormatter.__init__(self, *args, **kwargs)
|
2017-02-19 20:33:55 -04:00
|
|
|
|
|
|
|
# taken and modified from from optparse.py's format_option
|
|
|
|
def format_option_preserve_nl(self, option):
|
|
|
|
# The help for each option consists of two parts:
|
|
|
|
# * the opt strings and metavars
|
|
|
|
# eg. ("-x", or "-fFILENAME, --file=FILENAME")
|
|
|
|
# * the user-supplied help string
|
|
|
|
# eg. ("turn on expert mode", "read data from FILENAME")
|
|
|
|
#
|
|
|
|
# If possible, we write both of these on the same line:
|
|
|
|
# -x turn on expert mode
|
|
|
|
#
|
|
|
|
# But if the opt string list is too long, we put the help
|
|
|
|
# string on a second line, indented to the same column it would
|
|
|
|
# start in if it fit on the first line.
|
|
|
|
# -fFILENAME, --file=FILENAME
|
|
|
|
# read data from FILENAME
|
|
|
|
result = []
|
|
|
|
opts = self.option_strings[option]
|
|
|
|
opt_width = self.help_position - self.current_indent - 2
|
|
|
|
if len(opts) > opt_width:
|
|
|
|
opts = "%*s%s\n" % (self.current_indent, "", opts)
|
|
|
|
else: # start help on same line as opts
|
|
|
|
opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
|
|
|
|
result.append(opts)
|
|
|
|
if option.help:
|
|
|
|
help_text = self.expand_default(option)
|
2017-09-17 23:50:38 -03:00
|
|
|
tw = textwrap.TextWrapper(replace_whitespace=False,
|
|
|
|
initial_indent="",
|
|
|
|
subsequent_indent=" ",
|
|
|
|
width=self.help_width)
|
2017-02-19 20:33:55 -04:00
|
|
|
|
|
|
|
for line in help_text.split("\n"):
|
|
|
|
help_lines = tw.wrap(line)
|
2018-07-31 06:50:02 -03:00
|
|
|
for wline in help_lines:
|
2017-09-17 23:50:38 -03:00
|
|
|
result.extend(["%*s%s\n" % (self.help_position,
|
|
|
|
"",
|
2018-07-31 06:50:02 -03:00
|
|
|
wline)])
|
2017-02-19 20:33:55 -04:00
|
|
|
elif opts[-1] != "\n":
|
|
|
|
result.append("\n")
|
|
|
|
return "".join(result)
|
|
|
|
|
|
|
|
def format_option(self, option):
|
|
|
|
if str(option).find('frame') != -1:
|
|
|
|
return self.format_option_preserve_nl(option)
|
|
|
|
return optparse.IndentedHelpFormatter.format_option(self, option)
|
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-02-19 20:33:55 -04:00
|
|
|
formatter = CompatOptionParser.CustomFormatter()
|
2017-09-17 23:50:38 -03:00
|
|
|
optparse.OptionParser.__init__(self,
|
|
|
|
*args,
|
|
|
|
formatter=formatter,
|
|
|
|
**kwargs)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
|
|
|
def error(self, error):
|
2018-07-31 06:50:02 -03:00
|
|
|
"""Override default error handler called by
|
2017-09-17 23:50:38 -03:00
|
|
|
optparse.OptionParser.parse_args when a parse error occurs;
|
|
|
|
raise a detailed exception which can be caught
|
2018-07-31 06:50:02 -03:00
|
|
|
"""
|
2016-04-27 22:34:15 -03:00
|
|
|
if error.find("no such option") != -1:
|
|
|
|
raise CompatError(error, self.values, self.rargs)
|
|
|
|
|
|
|
|
optparse.OptionParser.error(self, error)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
def parse_args(self, args=None, values=None):
|
2017-09-17 23:50:38 -03:00
|
|
|
'''Wrap parse_args so we can catch the exception raised upon
|
|
|
|
discovering the known parameter parsing error
|
|
|
|
'''
|
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
try:
|
|
|
|
opts, args = optparse.OptionParser.parse_args(self)
|
|
|
|
except CompatError as e:
|
|
|
|
if not e.opts.sim_vehicle_sh_compatible:
|
|
|
|
print(e)
|
2016-04-28 23:16:53 -03:00
|
|
|
print("Perhaps you want --sim_vehicle_sh_compatible (-C)?")
|
2016-04-27 22:34:15 -03:00
|
|
|
sys.exit(1)
|
|
|
|
if e.opts.mavproxy_args:
|
|
|
|
print("--mavproxy-args not permitted in compat mode")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
args = []
|
|
|
|
opts = e.opts
|
2016-07-04 15:28:06 -03:00
|
|
|
mavproxy_args = [str(e)[16:]] # this trims "no such option" off
|
2016-04-27 22:34:15 -03:00
|
|
|
mavproxy_args.extend(e.rargs)
|
|
|
|
opts.ensure_value("mavproxy_args", " ".join(mavproxy_args))
|
|
|
|
|
|
|
|
return opts, args
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
|
|
|
def cygwin_pidof(proc_name):
|
|
|
|
""" Thanks to kata198 for this:
|
2016-04-28 23:16:53 -03:00
|
|
|
https://github.com/kata198/cygwin-ps-misc/blob/master/pidof
|
2016-07-04 15:28:06 -03:00
|
|
|
"""
|
2017-09-17 23:50:38 -03:00
|
|
|
pipe = subprocess.Popen("ps -ea | grep " + proc_name,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE)
|
2020-04-14 22:51:31 -03:00
|
|
|
output_lines = pipe.stdout.read().decode('utf-8').replace("\r", "").split("\n")
|
2016-04-28 23:16:53 -03:00
|
|
|
ret = pipe.wait()
|
|
|
|
pids = []
|
|
|
|
if ret != 0:
|
|
|
|
# No results
|
2016-07-04 15:28:06 -03:00
|
|
|
return []
|
|
|
|
for line in output_lines:
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
line_split = [item for item in line.split(' ') if item]
|
|
|
|
cmd = line_split[-1].split('/')[-1]
|
|
|
|
if cmd == proc_name:
|
|
|
|
try:
|
|
|
|
pid = int(line_split[0].strip())
|
2021-02-21 04:48:07 -04:00
|
|
|
except Exception:
|
2016-07-04 15:28:06 -03:00
|
|
|
pid = int(line_split[1].strip())
|
2016-08-22 00:59:22 -03:00
|
|
|
if pid not in pids:
|
|
|
|
pids.append(pid)
|
2016-04-28 23:16:53 -03:00
|
|
|
return pids
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-04-28 23:16:53 -03:00
|
|
|
def under_cygwin():
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Return if Cygwin binary exist"""
|
2016-04-28 23:16:53 -03:00
|
|
|
return os.path.exists("/usr/bin/cygstart")
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-07-06 11:26:34 -03:00
|
|
|
def under_macos():
|
|
|
|
return sys.platform == 'darwin'
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2023-01-03 20:38:04 -04:00
|
|
|
def under_vagrant():
|
|
|
|
return os.path.isfile("/ardupilot.vagrant")
|
|
|
|
|
|
|
|
|
|
|
|
def under_wsl2():
|
2023-01-04 19:36:27 -04:00
|
|
|
import platform
|
|
|
|
return 'microsoft-standard-WSL2' in platform.release()
|
2023-01-03 20:38:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
def wsl2_host_ip():
|
|
|
|
if not under_wsl2():
|
|
|
|
return None
|
|
|
|
|
2023-02-06 23:19:50 -04:00
|
|
|
pipe = subprocess.Popen("ip route show default | awk '{print $3}'",
|
2023-01-03 20:38:04 -04:00
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
output_lines = pipe.stdout.read().decode('utf-8').strip(' \r\n')
|
|
|
|
ret = pipe.wait()
|
|
|
|
|
|
|
|
if ret != 0:
|
|
|
|
# Command exited with an error. The output it generated probably isn't what we're expecting
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not output_lines:
|
|
|
|
# No output detected, maybe there's no nameserver or WSL2 has some abnormal firewalls/network settings?
|
|
|
|
return None
|
|
|
|
|
|
|
|
return str(output_lines)
|
|
|
|
|
|
|
|
|
2016-04-28 23:16:53 -03:00
|
|
|
def kill_tasks_cygwin(victims):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Shell out to ps -ea to find processes to kill"""
|
2016-04-28 23:16:53 -03:00
|
|
|
for victim in list(victims):
|
|
|
|
pids = cygwin_pidof(victim)
|
2017-09-17 23:50:38 -03:00
|
|
|
# progress("pids for (%s): %s" %
|
|
|
|
# (victim,",".join([ str(p) for p in pids])))
|
2016-04-28 23:16:53 -03:00
|
|
|
for apid in pids:
|
|
|
|
os.kill(apid, signal.SIGKILL)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-07-06 11:26:34 -03:00
|
|
|
def kill_tasks_macos():
|
|
|
|
for window in windowID:
|
2017-09-17 23:50:38 -03:00
|
|
|
cmd = ("osascript -e \'tell application \"Terminal\" to close "
|
|
|
|
"(window(get index of window id %s))\'" % window)
|
2016-07-06 11:26:34 -03:00
|
|
|
os.system(cmd)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-06-23 00:31:38 -03:00
|
|
|
def kill_tasks_psutil(victims):
|
2017-09-17 23:50:38 -03:00
|
|
|
"""Use the psutil module to kill tasks by name. Sadly, this module is
|
|
|
|
not available on Windows, but when it is we should be able to *just*
|
|
|
|
use this routine"""
|
2016-06-23 00:31:38 -03:00
|
|
|
import psutil
|
|
|
|
for proc in psutil.process_iter():
|
2020-03-09 17:09:28 -03:00
|
|
|
pdict = proc.as_dict(attrs=['environ', 'status'])
|
2019-05-13 10:06:27 -03:00
|
|
|
if pdict['status'] == psutil.STATUS_ZOMBIE:
|
2016-06-23 00:31:38 -03:00
|
|
|
continue
|
2020-03-09 17:09:28 -03:00
|
|
|
if pdict['environ'] is not None:
|
|
|
|
if pdict['environ'].get('SIM_VEHICLE_SESSION') == os.environ['SIM_VEHICLE_SESSION']:
|
|
|
|
proc.kill()
|
2016-06-23 00:31:38 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-06-23 00:31:38 -03:00
|
|
|
def kill_tasks_pkill(victims):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Shell out to pkill(1) to kill processed by name"""
|
|
|
|
for victim in victims: # pkill takes a single pattern, so iterate
|
2018-07-03 17:04:44 -03:00
|
|
|
cmd = ["pkill", victim[:15]] # pkill matches only first 15 characters
|
2016-06-23 00:31:38 -03:00
|
|
|
run_cmd_blocking("pkill", cmd, quiet=True)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-06-23 00:31:38 -03:00
|
|
|
class BobException(Exception):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Handle Bob's Exceptions"""
|
2016-06-23 00:31:38 -03:00
|
|
|
pass
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
def kill_tasks():
|
2017-09-17 23:50:38 -03:00
|
|
|
"""Clean up stray processes by name. This is a shotgun approach"""
|
2016-06-23 00:33:52 -03:00
|
|
|
progress("Killing tasks")
|
2021-08-13 09:13:02 -03:00
|
|
|
|
|
|
|
if cmd_opts.coverage:
|
|
|
|
import psutil
|
|
|
|
for proc in psutil.process_iter(['pid', 'name', 'environ']):
|
|
|
|
if proc.name() not in ["arducopter", "ardurover", "arduplane", "ardusub", "antennatracker"]:
|
|
|
|
# only kill vehicle that way
|
|
|
|
continue
|
|
|
|
if os.environ['SIM_VEHICLE_SESSION'] not in proc.environ().get('SIM_VEHICLE_SESSION'):
|
|
|
|
# only kill vehicle launched with sim_vehicle.py that way
|
|
|
|
continue
|
|
|
|
proc.terminate()
|
|
|
|
progress("Waiting SITL to exit cleanly and write coverage .gcda")
|
|
|
|
try:
|
|
|
|
proc.wait(timeout=30)
|
|
|
|
progress("Done")
|
|
|
|
except psutil.TimeoutExpired:
|
|
|
|
progress("SITL doesn't want to exit cleaning, killing ...")
|
|
|
|
proc.kill()
|
|
|
|
|
2016-06-23 00:31:38 -03:00
|
|
|
try:
|
2016-07-31 07:22:06 -03:00
|
|
|
victim_names = {
|
2016-06-23 00:33:52 -03:00
|
|
|
'JSBSim',
|
|
|
|
'lt-JSBSim',
|
|
|
|
'ArduPlane.elf',
|
|
|
|
'ArduCopter.elf',
|
2016-10-29 04:42:22 -03:00
|
|
|
'ArduSub.elf',
|
2020-03-26 20:14:17 -03:00
|
|
|
'Rover.elf',
|
2016-06-23 00:33:52 -03:00
|
|
|
'AntennaTracker.elf',
|
|
|
|
'JSBSIm.exe',
|
|
|
|
'MAVProxy.exe',
|
|
|
|
'runsim.py',
|
|
|
|
'AntennaTracker.elf',
|
2022-01-28 20:51:45 -04:00
|
|
|
'scrimmage',
|
2020-04-14 22:51:31 -03:00
|
|
|
'ardurover',
|
|
|
|
'arduplane',
|
|
|
|
'arducopter'
|
2016-07-31 07:22:06 -03:00
|
|
|
}
|
2017-05-24 04:18:24 -03:00
|
|
|
for vehicle in vinfo.options:
|
|
|
|
for frame in vinfo.options[vehicle]["frames"]:
|
|
|
|
frame_info = vinfo.options[vehicle]["frames"][frame]
|
2017-02-19 20:33:55 -04:00
|
|
|
if "waf_target" not in frame_info:
|
|
|
|
continue
|
|
|
|
exe_name = os.path.basename(frame_info["waf_target"])
|
|
|
|
victim_names.add(exe_name)
|
2016-06-23 00:33:52 -03:00
|
|
|
|
|
|
|
if under_cygwin():
|
|
|
|
return kill_tasks_cygwin(victim_names)
|
2018-01-20 16:54:03 -04:00
|
|
|
if under_macos() and os.environ.get('DISPLAY'):
|
2018-07-03 20:35:06 -03:00
|
|
|
# use special macos kill routine if Display is on
|
2016-07-06 11:26:34 -03:00
|
|
|
return kill_tasks_macos()
|
2016-06-23 00:33:52 -03:00
|
|
|
|
|
|
|
try:
|
|
|
|
kill_tasks_psutil(victim_names)
|
2016-07-04 15:28:06 -03:00
|
|
|
except ImportError:
|
2016-06-23 00:33:52 -03:00
|
|
|
kill_tasks_pkill(victim_names)
|
|
|
|
except Exception as e:
|
|
|
|
progress("kill_tasks failed: {}".format(str(e)))
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
def progress(text):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Display sim_vehicle progress text"""
|
2016-04-27 22:34:15 -03:00
|
|
|
print("SIM_VEHICLE: " + text)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-12-19 10:29:37 -04:00
|
|
|
def wait_unlimited():
|
|
|
|
"""Wait until signal received"""
|
2017-11-05 07:58:33 -04:00
|
|
|
while True:
|
|
|
|
time.sleep(600)
|
2016-12-19 10:29:37 -04:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
|
2017-05-24 04:18:24 -03:00
|
|
|
vinfo = vehicleinfo.VehicleInfo()
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
|
2021-01-15 02:07:04 -04:00
|
|
|
def do_build(opts, frame_options):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Build sitl using waf"""
|
2016-04-28 23:16:53 -03:00
|
|
|
progress("WAF build")
|
|
|
|
|
|
|
|
old_dir = os.getcwd()
|
|
|
|
os.chdir(root_dir)
|
|
|
|
|
2016-05-12 00:32:36 -03:00
|
|
|
waf_light = os.path.join(root_dir, "modules/waf/waf-light")
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2022-08-21 18:20:39 -03:00
|
|
|
configure_target = frame_options.get('configure_target', 'sitl')
|
|
|
|
|
|
|
|
cmd_configure = [waf_light, "configure", "--board", configure_target]
|
2016-05-06 00:11:53 -03:00
|
|
|
if opts.debug:
|
|
|
|
cmd_configure.append("--debug")
|
2018-07-01 07:10:29 -03:00
|
|
|
|
2021-08-13 09:13:02 -03:00
|
|
|
if opts.coverage:
|
|
|
|
cmd_configure.append("--coverage")
|
|
|
|
|
2021-06-14 13:04:30 -03:00
|
|
|
if opts.enable_onvif and 'antennatracker' in frame_options["waf_target"]:
|
|
|
|
cmd_configure.append("--enable-onvif")
|
|
|
|
|
2018-07-01 07:10:29 -03:00
|
|
|
if opts.OSD:
|
2018-07-01 20:35:41 -03:00
|
|
|
cmd_configure.append("--enable-sfml")
|
2019-05-16 01:02:58 -03:00
|
|
|
cmd_configure.append("--sitl-osd")
|
|
|
|
|
2020-09-06 20:18:25 -03:00
|
|
|
if opts.OSDMSP:
|
|
|
|
cmd_configure.append("--osd")
|
2021-02-21 04:48:07 -04:00
|
|
|
|
2019-05-16 01:02:58 -03:00
|
|
|
if opts.rgbled:
|
|
|
|
cmd_configure.append("--enable-sfml")
|
|
|
|
cmd_configure.append("--sitl-rgbled")
|
2018-07-01 07:10:29 -03:00
|
|
|
|
2019-03-19 23:36:41 -03:00
|
|
|
if opts.tonealarm:
|
|
|
|
cmd_configure.append("--enable-sfml-audio")
|
|
|
|
|
2020-04-27 22:30:39 -03:00
|
|
|
if opts.math_check_indexes:
|
|
|
|
cmd_configure.append("--enable-math-check-indexes")
|
|
|
|
|
2020-04-11 19:25:31 -03:00
|
|
|
if opts.disable_ekf2:
|
|
|
|
cmd_configure.append("--disable-ekf2")
|
|
|
|
|
|
|
|
if opts.disable_ekf3:
|
|
|
|
cmd_configure.append("--disable-ekf3")
|
2021-02-21 04:48:07 -04:00
|
|
|
|
2021-06-22 02:57:48 -03:00
|
|
|
if opts.postype_single:
|
|
|
|
cmd_configure.append("--postype-single")
|
|
|
|
|
2021-05-04 08:12:24 -03:00
|
|
|
if opts.ekf_double:
|
|
|
|
cmd_configure.append("--ekf-double")
|
|
|
|
|
|
|
|
if opts.ekf_single:
|
|
|
|
cmd_configure.append("--ekf-single")
|
|
|
|
|
2023-01-08 18:56:33 -04:00
|
|
|
if opts.force_32bit:
|
|
|
|
cmd_configure.append("--force-32bit")
|
2021-09-07 16:32:24 -03:00
|
|
|
|
2022-07-10 20:16:55 -03:00
|
|
|
if opts.ubsan:
|
|
|
|
cmd_configure.append("--ubsan")
|
|
|
|
|
|
|
|
if opts.ubsan_abort:
|
|
|
|
cmd_configure.append("--ubsan-abort")
|
|
|
|
|
2023-03-03 19:53:50 -04:00
|
|
|
if opts.num_aux_imus:
|
|
|
|
cmd_configure.append("--num-aux-imus=%s" % opts.num_aux_imus)
|
|
|
|
|
2022-06-26 21:40:06 -03:00
|
|
|
for nv in opts.define:
|
|
|
|
cmd_configure.append("--define=%s" % nv)
|
|
|
|
|
2023-03-10 20:45:28 -04:00
|
|
|
if opts.enable_dds:
|
|
|
|
cmd_configure.append("--enable-dds")
|
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
pieces = [shlex.split(x) for x in opts.waf_configure_args]
|
2016-08-29 21:49:16 -03:00
|
|
|
for piece in pieces:
|
|
|
|
cmd_configure.extend(piece)
|
2016-05-06 00:11:53 -03:00
|
|
|
|
2016-08-29 21:49:16 -03:00
|
|
|
run_cmd_blocking("Configure waf", cmd_configure, check=True)
|
2016-04-28 23:16:53 -03:00
|
|
|
|
|
|
|
if opts.clean:
|
|
|
|
run_cmd_blocking("Building clean", [waf_light, "clean"])
|
|
|
|
|
2022-08-21 18:20:39 -03:00
|
|
|
print(frame_options)
|
2016-05-11 13:15:30 -03:00
|
|
|
cmd_build = [waf_light, "build", "--target", frame_options["waf_target"]]
|
|
|
|
if opts.jobs is not None:
|
|
|
|
cmd_build += ['-j', str(opts.jobs)]
|
2017-09-17 23:50:38 -03:00
|
|
|
pieces = [shlex.split(x) for x in opts.waf_build_args]
|
2016-08-29 21:49:16 -03:00
|
|
|
for piece in pieces:
|
|
|
|
cmd_build.extend(piece)
|
2016-05-11 13:15:30 -03:00
|
|
|
|
2016-05-11 23:44:56 -03:00
|
|
|
_, sts = run_cmd_blocking("Building", cmd_build)
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
if sts != 0: # build failed
|
2016-05-07 20:34:42 -03:00
|
|
|
if opts.rebuild_on_failure:
|
|
|
|
progress("Build failed; cleaning and rebuilding")
|
|
|
|
run_cmd_blocking("Building clean", [waf_light, "clean"])
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2016-05-11 23:44:56 -03:00
|
|
|
_, sts = run_cmd_blocking("Building", cmd_build)
|
2016-05-07 20:34:42 -03:00
|
|
|
if sts != 0:
|
|
|
|
progress("Build failed")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2016-04-28 23:16:53 -03:00
|
|
|
progress("Build failed")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
os.chdir(old_dir)
|
|
|
|
|
|
|
|
|
2017-12-16 00:22:45 -04:00
|
|
|
def do_build_parameters(vehicle):
|
|
|
|
# build succeeded
|
|
|
|
# now build parameters
|
|
|
|
progress("Building fresh parameter descriptions")
|
|
|
|
param_parse_path = os.path.join(
|
2020-01-29 11:31:09 -04:00
|
|
|
autotest_dir, "param_metadata/param_parse.py")
|
2017-12-16 00:22:45 -04:00
|
|
|
cmd_param_build = ["python", param_parse_path, '--vehicle', vehicle]
|
|
|
|
|
|
|
|
_, sts = run_cmd_blocking("Building fresh params", cmd_param_build)
|
|
|
|
if sts != 0:
|
|
|
|
progress("Parameter build failed")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2016-11-14 14:48:59 -04:00
|
|
|
def get_user_locations_path():
|
|
|
|
'''The user locations.txt file is located by default in
|
|
|
|
$XDG_CONFIG_DIR/ardupilot/locations.txt. If $XDG_CONFIG_DIR is
|
|
|
|
not defined, we look in $HOME/.config/ardupilot/locations.txt. If
|
2022-02-04 21:50:40 -04:00
|
|
|
$HOME is not defined, we look in ./.config/ardupilot/locations.txt.'''
|
2016-11-14 14:48:59 -04:00
|
|
|
|
|
|
|
config_dir = os.environ.get(
|
|
|
|
'XDG_CONFIG_DIR',
|
|
|
|
os.path.join(os.environ.get('HOME', '.'), '.config'))
|
|
|
|
|
|
|
|
user_locations_path = os.path.join(
|
|
|
|
config_dir, 'ardupilot', 'locations.txt')
|
|
|
|
|
|
|
|
return user_locations_path
|
|
|
|
|
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
def find_offsets(instances, file_path):
|
|
|
|
offsets = {}
|
2020-01-29 11:31:09 -04:00
|
|
|
swarminit_filepath = os.path.join(autotest_dir, "swarminit.txt")
|
2021-02-21 04:48:07 -04:00
|
|
|
comment_regex = re.compile(r"\s*#.*")
|
2020-01-29 11:55:17 -04:00
|
|
|
for path in [file_path, swarminit_filepath]:
|
|
|
|
if os.path.isfile(path):
|
|
|
|
with open(path, 'r') as fd:
|
|
|
|
for line in fd:
|
|
|
|
line = re.sub(comment_regex, "", line)
|
|
|
|
line = line.rstrip("\n")
|
|
|
|
if len(line) == 0:
|
|
|
|
continue
|
|
|
|
(instance, offset) = line.split("=")
|
|
|
|
instance = (int)(instance)
|
|
|
|
if (instance not in offsets) and (instance in instances):
|
2021-02-21 04:48:07 -04:00
|
|
|
offsets[instance] = [(float)(x) for x in offset.split(",")]
|
2018-12-25 16:46:13 -04:00
|
|
|
continue
|
2020-01-29 11:55:17 -04:00
|
|
|
if len(offsets) == len(instances):
|
|
|
|
return offsets
|
|
|
|
if len(offsets) == len(instances):
|
|
|
|
return offsets
|
|
|
|
for instance in instances:
|
|
|
|
if instance not in offsets:
|
|
|
|
offsets[instance] = [90.0, 20.0 * instance, 0.0, None]
|
|
|
|
return offsets
|
2018-12-25 16:46:13 -04:00
|
|
|
|
2019-01-18 18:33:03 -04:00
|
|
|
|
2021-06-27 18:55:32 -03:00
|
|
|
def find_geocoder_location(locname):
|
|
|
|
'''find a location using geocoder and SRTM'''
|
|
|
|
try:
|
|
|
|
import geocoder
|
|
|
|
except ImportError:
|
|
|
|
print("geocoder not installed")
|
|
|
|
return None
|
|
|
|
j = geocoder.osm(locname)
|
|
|
|
if j is None or not hasattr(j, 'lat') or j.lat is None:
|
|
|
|
print("geocoder failed to find '%s'" % locname)
|
|
|
|
return None
|
|
|
|
lat = j.lat
|
|
|
|
lon = j.lng
|
|
|
|
from MAVProxy.modules.mavproxy_map import srtm
|
|
|
|
downloader = srtm.SRTMDownloader()
|
|
|
|
downloader.loadFileList()
|
|
|
|
start = time.time()
|
|
|
|
alt = None
|
|
|
|
while time.time() - start < 5:
|
|
|
|
tile = downloader.getTile(int(math.floor(lat)), int(math.floor(lon)))
|
|
|
|
if tile:
|
|
|
|
alt = tile.getAltitudeFromLatLon(lat, lon)
|
|
|
|
break
|
|
|
|
if alt is None:
|
|
|
|
print("timed out getting altitude for '%s'" % locname)
|
|
|
|
return None
|
|
|
|
return [lat, lon, alt, 0.0]
|
|
|
|
|
|
|
|
|
2020-01-29 11:31:09 -04:00
|
|
|
def find_location_by_name(locname):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Search locations.txt for locname, return GPS coords"""
|
2016-11-14 14:48:59 -04:00
|
|
|
locations_userpath = os.environ.get('ARDUPILOT_LOCATIONS',
|
|
|
|
get_user_locations_path())
|
2020-01-29 11:31:09 -04:00
|
|
|
locations_filepath = os.path.join(autotest_dir, "locations.txt")
|
2021-02-21 04:48:07 -04:00
|
|
|
comment_regex = re.compile(r"\s*#.*")
|
2016-11-14 14:48:59 -04:00
|
|
|
for path in [locations_userpath, locations_filepath]:
|
|
|
|
if not os.path.isfile(path):
|
2016-11-14 22:52:34 -04:00
|
|
|
continue
|
2016-11-14 14:48:59 -04:00
|
|
|
with open(path, 'r') as fd:
|
|
|
|
for line in fd:
|
|
|
|
line = re.sub(comment_regex, "", line)
|
|
|
|
line = line.rstrip("\n")
|
|
|
|
if len(line) == 0:
|
|
|
|
continue
|
|
|
|
(name, loc) = line.split("=")
|
|
|
|
if name == locname:
|
2021-02-21 04:48:07 -04:00
|
|
|
return [(float)(x) for x in loc.split(",")]
|
2016-11-14 14:48:59 -04:00
|
|
|
|
2021-06-27 18:55:32 -03:00
|
|
|
# fallback to geocoder if available
|
|
|
|
loc = find_geocoder_location(locname)
|
|
|
|
if loc is None:
|
|
|
|
sys.exit(1)
|
|
|
|
return loc
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
def find_spawns(loc, offsets):
|
|
|
|
lat, lon, alt, heading = loc
|
|
|
|
spawns = {}
|
|
|
|
for k in offsets:
|
|
|
|
(x, y, z, head) = offsets[k]
|
|
|
|
if head is None:
|
|
|
|
head = heading
|
|
|
|
g = mavextra.gps_offset(lat, lon, x, y)
|
|
|
|
spawns[k] = ",".join([str(g[0]), str(g[1]), str(alt+z), str(head)])
|
|
|
|
return spawns
|
|
|
|
|
|
|
|
|
2016-04-28 23:16:53 -03:00
|
|
|
def progress_cmd(what, cmd):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Print cmd in a way a user could cut-and-paste to get the same effect"""
|
2016-04-28 23:16:53 -03:00
|
|
|
progress(what)
|
2016-07-04 15:28:06 -03:00
|
|
|
shell_text = "%s" % (" ".join(['"%s"' % x for x in cmd]))
|
2016-04-28 23:16:53 -03:00
|
|
|
progress(shell_text)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-08-29 21:49:16 -03:00
|
|
|
def run_cmd_blocking(what, cmd, quiet=False, check=False, **kw):
|
2016-06-23 00:31:38 -03:00
|
|
|
if not quiet:
|
|
|
|
progress_cmd(what, cmd)
|
2018-08-17 11:06:10 -03:00
|
|
|
|
|
|
|
try:
|
|
|
|
p = subprocess.Popen(cmd, **kw)
|
|
|
|
ret = os.waitpid(p.pid, 0)
|
|
|
|
except Exception as e:
|
|
|
|
print("[%s] An exception has occurred with command: '%s'" % (what, (' ').join(cmd)))
|
|
|
|
print(e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-08-29 21:49:16 -03:00
|
|
|
_, sts = ret
|
|
|
|
if check and sts != 0:
|
2017-09-17 23:50:38 -03:00
|
|
|
progress("(%s) exited with code %d" % (what, sts,))
|
2016-08-29 21:49:16 -03:00
|
|
|
sys.exit(1)
|
|
|
|
return ret
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
def run_in_terminal_window(name, cmd, **kw):
|
2016-07-04 15:28:06 -03:00
|
|
|
|
|
|
|
"""Execute the run_in_terminal_window.sh command for cmd"""
|
2016-06-23 12:27:28 -03:00
|
|
|
global windowID
|
2020-01-29 11:31:09 -04:00
|
|
|
runme = [os.path.join(autotest_dir, "run_in_terminal_window.sh"), name]
|
2016-04-27 22:34:15 -03:00
|
|
|
runme.extend(cmd)
|
2016-04-28 23:16:53 -03:00
|
|
|
progress_cmd("Run " + name, runme)
|
2016-06-23 12:27:28 -03:00
|
|
|
|
2018-01-20 16:54:03 -04:00
|
|
|
if under_macos() and os.environ.get('DISPLAY'):
|
2016-07-07 19:20:20 -03:00
|
|
|
# on MacOS record the window IDs so we can close them later
|
2020-01-29 11:55:17 -04:00
|
|
|
out = subprocess.Popen(runme, stdout=subprocess.PIPE, **kw).communicate()[0]
|
2018-03-18 21:21:59 -03:00
|
|
|
out = out.decode('utf-8')
|
2016-06-23 12:27:28 -03:00
|
|
|
p = re.compile('tab 1 of window id (.*)')
|
2018-05-15 21:31:26 -03:00
|
|
|
|
2017-11-28 14:49:08 -04:00
|
|
|
tstart = time.time()
|
|
|
|
while time.time() - tstart < 5:
|
|
|
|
tabs = p.findall(out)
|
2018-05-15 21:31:26 -03:00
|
|
|
|
2017-11-28 14:49:08 -04:00
|
|
|
if len(tabs) > 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
time.sleep(0.1)
|
2018-07-03 20:35:06 -03:00
|
|
|
# sleep for extra 2 seconds for application to start
|
2018-01-20 16:54:03 -04:00
|
|
|
time.sleep(2)
|
2017-11-28 14:49:08 -04:00
|
|
|
if len(tabs) > 0:
|
|
|
|
windowID.append(tabs[0])
|
|
|
|
else:
|
2018-07-03 20:35:06 -03:00
|
|
|
progress("Cannot find %s process terminal" % name)
|
2016-07-07 19:20:20 -03:00
|
|
|
else:
|
2020-01-29 11:55:17 -04:00
|
|
|
subprocess.Popen(runme, **kw)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
tracker_uarta = None # blemish
|
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2020-01-29 11:31:09 -04:00
|
|
|
def start_antenna_tracker(opts):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Compile and run the AntennaTracker, add tracker to mavproxy"""
|
2018-03-20 21:46:12 -03:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
global tracker_uarta
|
|
|
|
progress("Preparing antenna tracker")
|
2020-01-29 11:31:09 -04:00
|
|
|
tracker_home = find_location_by_name(opts.tracker_location)
|
|
|
|
vehicledir = os.path.join(autotest_dir, "../../" + "AntennaTracker")
|
2018-07-31 06:50:02 -03:00
|
|
|
options = vinfo.options["AntennaTracker"]
|
|
|
|
tracker_default_frame = options["default_frame"]
|
|
|
|
tracker_frame_options = options["frames"][tracker_default_frame]
|
2021-01-18 15:49:10 -04:00
|
|
|
do_build(opts, tracker_frame_options)
|
2016-04-27 22:34:15 -03:00
|
|
|
tracker_instance = 1
|
2017-02-14 08:30:56 -04:00
|
|
|
oldpwd = os.getcwd()
|
2016-04-27 22:34:15 -03:00
|
|
|
os.chdir(vehicledir)
|
2016-07-04 15:28:06 -03:00
|
|
|
tracker_uarta = "tcp:127.0.0.1:" + str(5760 + 10 * tracker_instance)
|
2022-07-12 02:09:28 -03:00
|
|
|
binary_basedir = "build/sitl"
|
|
|
|
exe = os.path.join(root_dir,
|
|
|
|
binary_basedir,
|
|
|
|
"bin/antennatracker")
|
2020-01-29 11:31:09 -04:00
|
|
|
run_in_terminal_window("AntennaTracker",
|
2017-09-17 23:50:38 -03:00
|
|
|
["nice",
|
|
|
|
exe,
|
|
|
|
"-I" + str(tracker_instance),
|
|
|
|
"--model=tracker",
|
2020-08-16 22:13:32 -03:00
|
|
|
"--home=" + ",".join([str(x) for x in tracker_home])])
|
2017-02-14 08:30:56 -04:00
|
|
|
os.chdir(oldpwd)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2022-08-21 18:20:39 -03:00
|
|
|
def start_CAN_GPS(opts):
|
|
|
|
"""Compile and run the sitl_periph_gps"""
|
|
|
|
|
|
|
|
global can_uarta
|
|
|
|
progress("Preparing sitl_periph_gps")
|
|
|
|
options = vinfo.options["sitl_periph_gps"]['frames']['gps']
|
|
|
|
do_build(opts, options)
|
|
|
|
exe = os.path.join(root_dir, 'build/sitl_periph_gps', 'bin/AP_Periph')
|
2023-04-07 04:55:17 -03:00
|
|
|
cmd = ["nice"]
|
|
|
|
cmd_name = "sitl_periph_gps"
|
|
|
|
if opts.valgrind:
|
|
|
|
cmd_name += " (valgrind)"
|
|
|
|
cmd.append("valgrind")
|
|
|
|
# adding this option allows valgrind to cope with the overload
|
|
|
|
# of operator new
|
|
|
|
cmd.append("--soname-synonyms=somalloc=nouserintercepts")
|
|
|
|
cmd.append("--track-origins=yes")
|
|
|
|
if opts.gdb or opts.gdb_stopped:
|
|
|
|
cmd_name += " (gdb)"
|
|
|
|
cmd.append("gdb")
|
|
|
|
gdb_commands_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
|
|
|
atexit.register(os.unlink, gdb_commands_file.name)
|
|
|
|
gdb_commands_file.write("set pagination off\n")
|
|
|
|
if not opts.gdb_stopped:
|
|
|
|
gdb_commands_file.write("r\n")
|
|
|
|
gdb_commands_file.close()
|
|
|
|
cmd.extend(["-x", gdb_commands_file.name])
|
|
|
|
cmd.append("--args")
|
|
|
|
cmd.append(exe)
|
|
|
|
run_in_terminal_window(cmd_name, cmd)
|
2022-08-21 18:20:39 -03:00
|
|
|
|
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
def start_vehicle(binary, opts, stuff, spawns=None):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Run the ArduPilot binary"""
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
cmd_name = opts.vehicle
|
|
|
|
cmd = []
|
|
|
|
if opts.valgrind:
|
|
|
|
cmd_name += " (valgrind)"
|
2018-12-05 20:16:37 -04:00
|
|
|
cmd.append("valgrind")
|
2018-12-04 16:32:05 -04:00
|
|
|
# adding this option allows valgrind to cope with the overload
|
|
|
|
# of operator new
|
2018-12-05 20:16:37 -04:00
|
|
|
cmd.append("--soname-synonyms=somalloc=nouserintercepts")
|
2019-09-20 22:37:51 -03:00
|
|
|
cmd.append("--track-origins=yes")
|
2016-12-16 19:13:01 -04:00
|
|
|
if opts.callgrind:
|
|
|
|
cmd_name += " (callgrind)"
|
2018-12-05 20:16:37 -04:00
|
|
|
cmd.append("valgrind")
|
|
|
|
cmd.append("--tool=callgrind")
|
2016-11-22 07:15:20 -04:00
|
|
|
if opts.gdb or opts.gdb_stopped:
|
2016-04-27 22:34:15 -03:00
|
|
|
cmd_name += " (gdb)"
|
|
|
|
cmd.append("gdb")
|
2018-07-03 17:04:44 -03:00
|
|
|
gdb_commands_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
2016-04-27 22:34:15 -03:00
|
|
|
atexit.register(os.unlink, gdb_commands_file.name)
|
|
|
|
|
2016-04-28 23:16:53 -03:00
|
|
|
for breakpoint in opts.breakpoint:
|
|
|
|
gdb_commands_file.write("b %s\n" % (breakpoint,))
|
2020-09-15 01:13:18 -03:00
|
|
|
if opts.disable_breakpoints:
|
|
|
|
gdb_commands_file.write("disable\n")
|
2022-04-07 18:57:45 -03:00
|
|
|
gdb_commands_file.write("set pagination off\n")
|
2016-11-22 07:15:20 -04:00
|
|
|
if not opts.gdb_stopped:
|
|
|
|
gdb_commands_file.write("r\n")
|
2016-04-27 22:34:15 -03:00
|
|
|
gdb_commands_file.close()
|
|
|
|
cmd.extend(["-x", gdb_commands_file.name])
|
|
|
|
cmd.append("--args")
|
2019-09-24 14:44:02 -03:00
|
|
|
elif opts.lldb or opts.lldb_stopped:
|
|
|
|
cmd_name += " (lldb)"
|
|
|
|
cmd.append("lldb")
|
|
|
|
lldb_commands_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
|
|
|
atexit.register(os.unlink, lldb_commands_file.name)
|
|
|
|
|
|
|
|
for breakpoint in opts.breakpoint:
|
|
|
|
lldb_commands_file.write("b %s\n" % (breakpoint,))
|
|
|
|
if not opts.lldb_stopped:
|
|
|
|
lldb_commands_file.write("process launch\n")
|
|
|
|
lldb_commands_file.close()
|
|
|
|
cmd.extend(["-s", lldb_commands_file.name])
|
|
|
|
cmd.append("--")
|
2016-05-12 08:09:45 -03:00
|
|
|
if opts.strace:
|
|
|
|
cmd_name += " (strace)"
|
|
|
|
cmd.append("strace")
|
2016-07-04 15:28:06 -03:00
|
|
|
strace_options = ['-o', binary + '.strace', '-s', '8000', '-ttt']
|
2016-05-12 08:09:45 -03:00
|
|
|
cmd.extend(strace_options)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
cmd.append(binary)
|
2016-04-27 22:34:15 -03:00
|
|
|
cmd.append("-S")
|
|
|
|
if opts.wipe_eeprom:
|
|
|
|
cmd.append("-w")
|
|
|
|
cmd.extend(["--model", stuff["model"]])
|
|
|
|
cmd.extend(["--speedup", str(opts.speedup)])
|
2018-09-04 14:06:54 -03:00
|
|
|
if opts.sysid is not None:
|
|
|
|
cmd.extend(["--sysid", str(opts.sysid)])
|
2021-04-24 21:34:27 -03:00
|
|
|
if opts.slave is not None:
|
|
|
|
cmd.extend(["--slave", str(opts.slave)])
|
2016-04-27 22:34:15 -03:00
|
|
|
if opts.sitl_instance_args:
|
2017-09-17 23:50:38 -03:00
|
|
|
# this could be a lot better:
|
|
|
|
cmd.extend(opts.sitl_instance_args.split(" "))
|
2016-04-27 22:34:15 -03:00
|
|
|
if opts.mavlink_gimbal:
|
|
|
|
cmd.append("--gimbal")
|
2018-04-23 16:23:35 -03:00
|
|
|
path = None
|
2016-07-04 15:28:06 -03:00
|
|
|
if "default_params_filename" in stuff:
|
2016-11-07 07:13:53 -04:00
|
|
|
paths = stuff["default_params_filename"]
|
2017-09-17 23:50:38 -03:00
|
|
|
if not isinstance(paths, list):
|
2016-11-07 07:13:53 -04:00
|
|
|
paths = [paths]
|
2022-02-01 20:27:03 -04:00
|
|
|
paths = [util.relcurdir(os.path.join(autotest_dir, x)) for x in paths]
|
2018-06-19 04:24:10 -03:00
|
|
|
for x in paths:
|
|
|
|
if not os.path.isfile(x):
|
|
|
|
print("The parameter file (%s) does not exist" % (x,))
|
|
|
|
sys.exit(1)
|
2016-11-07 07:13:53 -04:00
|
|
|
path = ",".join(paths)
|
2022-08-25 00:45:28 -03:00
|
|
|
if cmd_opts.count > 1:
|
|
|
|
# we are in a subdirectory when using -n
|
|
|
|
path = os.path.join("..", path)
|
2016-04-27 22:34:15 -03:00
|
|
|
progress("Using defaults from (%s)" % (path,))
|
2021-06-10 23:30:39 -03:00
|
|
|
if opts.flash_storage:
|
|
|
|
cmd.append("--set-storage-flash-enabled 1")
|
|
|
|
cmd.append("--set-storage-posix-enabled 0")
|
2021-10-08 00:11:20 -03:00
|
|
|
elif opts.fram_storage:
|
|
|
|
cmd.append("--set-storage-fram-enabled 1")
|
|
|
|
cmd.append("--set-storage-posix-enabled 0")
|
2018-04-23 16:23:35 -03:00
|
|
|
if opts.add_param_file:
|
2021-02-02 10:27:27 -04:00
|
|
|
for file in opts.add_param_file:
|
|
|
|
if not os.path.isfile(file):
|
|
|
|
print("The parameter file (%s) does not exist" %
|
|
|
|
(file,))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if path is not None:
|
|
|
|
path += "," + str(file)
|
|
|
|
else:
|
|
|
|
path = str(file)
|
|
|
|
|
|
|
|
progress("Adding parameters from (%s)" % (str(file),))
|
2020-09-06 20:18:25 -03:00
|
|
|
if opts.OSDMSP:
|
|
|
|
path += "," + os.path.join(root_dir, "libraries/AP_MSP/Tools/osdtest.parm")
|
|
|
|
path += "," + os.path.join(autotest_dir, "default_params/msposd.parm")
|
|
|
|
subprocess.Popen([os.path.join(root_dir, "libraries/AP_MSP/Tools/msposd.py")])
|
|
|
|
|
2022-11-08 17:01:54 -04:00
|
|
|
if path is not None and len(path) > 0:
|
2016-04-27 22:34:15 -03:00
|
|
|
cmd.extend(["--defaults", path])
|
|
|
|
|
2020-09-04 19:24:20 -03:00
|
|
|
if cmd_opts.start_time is not None:
|
|
|
|
# Parse start_time into a double precision number specifying seconds since 1900.
|
|
|
|
try:
|
|
|
|
start_time_UTC = time.mktime(datetime.datetime.strptime(cmd_opts.start_time, '%Y-%m-%d-%H:%M').timetuple())
|
2021-02-21 04:48:07 -04:00
|
|
|
except Exception:
|
2020-09-04 19:24:20 -03:00
|
|
|
print("Incorrect start time format - require YYYY-MM-DD-HH:MM (given %s)" % cmd_opts.start_time)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
cmd.append("--start-time=%d" % start_time_UTC)
|
|
|
|
|
2023-01-21 21:19:14 -04:00
|
|
|
cmd.append("--sim-address=%s" % cmd_opts.sim_address)
|
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
old_dir = os.getcwd()
|
|
|
|
for i, i_dir in zip(instances, instance_dir):
|
|
|
|
c = ["-I" + str(i)]
|
|
|
|
if spawns is not None:
|
|
|
|
c.extend(["--home", spawns[i]])
|
2021-11-02 20:48:42 -03:00
|
|
|
if opts.mcast:
|
|
|
|
c.extend(["--uartA", "mcast:"])
|
|
|
|
elif opts.udp:
|
|
|
|
c.extend(["--uartA", "udpclient:127.0.0.1:" + str(5760+i*10)])
|
2021-10-30 18:18:32 -03:00
|
|
|
if opts.auto_sysid:
|
|
|
|
if opts.sysid is not None:
|
|
|
|
raise ValueError("Can't use auto-sysid and sysid together")
|
|
|
|
sysid = i + 1
|
|
|
|
# Take 0-based logging into account
|
2021-11-02 20:44:46 -03:00
|
|
|
if sysid < 1 or sysid > 255:
|
|
|
|
raise ValueError("Invalid system id %d" % sysid)
|
2021-10-30 18:18:32 -03:00
|
|
|
c.extend(["--sysid", str(sysid)])
|
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
os.chdir(i_dir)
|
|
|
|
run_in_terminal_window(cmd_name, cmd + c)
|
|
|
|
os.chdir(old_dir)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
def start_mavproxy(opts, stuff):
|
2016-07-04 15:28:06 -03:00
|
|
|
"""Run mavproxy"""
|
2017-09-17 23:50:38 -03:00
|
|
|
# FIXME: would be nice to e.g. "mavproxy.mavproxy(....).run"
|
|
|
|
# rather than shelling out
|
2016-04-27 22:34:15 -03:00
|
|
|
|
|
|
|
extra_cmd = ""
|
|
|
|
cmd = []
|
2016-04-28 23:16:53 -03:00
|
|
|
if under_cygwin():
|
|
|
|
cmd.append("/usr/bin/cygstart")
|
2016-04-27 22:34:15 -03:00
|
|
|
cmd.append("-w")
|
2018-11-22 01:09:00 -04:00
|
|
|
cmd.append("mavproxy.exe")
|
2016-04-27 22:34:15 -03:00
|
|
|
else:
|
|
|
|
cmd.append("mavproxy.py")
|
|
|
|
|
2020-10-28 15:09:16 -03:00
|
|
|
if opts.mcast:
|
|
|
|
cmd.extend(["--master", "mcast:"])
|
|
|
|
|
2023-01-03 20:38:04 -04:00
|
|
|
# returns a valid IP of the host windows computer if we're WSL2.
|
|
|
|
# This is run before the loop so it only runs once
|
|
|
|
wsl2_host_ip_str = wsl2_host_ip()
|
|
|
|
|
2020-10-28 15:09:16 -03:00
|
|
|
for i in instances:
|
|
|
|
if not opts.no_extra_ports:
|
|
|
|
ports = [p + 10 * i for p in [14550, 14551]]
|
|
|
|
for port in ports:
|
2023-01-03 20:38:04 -04:00
|
|
|
if under_vagrant():
|
2020-10-28 15:09:16 -03:00
|
|
|
# We're running inside of a vagrant guest; forward our
|
|
|
|
# mavlink out to the containing host OS
|
|
|
|
cmd.extend(["--out", "10.0.2.2:" + str(port)])
|
2023-01-03 20:38:04 -04:00
|
|
|
elif wsl2_host_ip_str:
|
|
|
|
# We're running WSL2; forward our
|
|
|
|
# mavlink out to the containing host Windows OS
|
|
|
|
cmd.extend(["--out", str(wsl2_host_ip_str) + ":" + str(port)])
|
2020-10-28 15:09:16 -03:00
|
|
|
else:
|
|
|
|
cmd.extend(["--out", "127.0.0.1:" + str(port)])
|
|
|
|
|
|
|
|
if not opts.mcast:
|
|
|
|
if opts.udp:
|
|
|
|
cmd.extend(["--master", ":" + str(5760 + 10 * i)])
|
|
|
|
else:
|
|
|
|
cmd.extend(["--master", "tcp:127.0.0.1:" + str(5760 + 10 * i)])
|
|
|
|
if stuff["sitl-port"] and not opts.no_rcin:
|
|
|
|
cmd.extend(["--sitl", "127.0.0.1:" + str(5501 + 10 * i)])
|
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
if opts.tracker:
|
|
|
|
cmd.extend(["--load-module", "tracker"])
|
|
|
|
global tracker_uarta
|
|
|
|
# tracker_uarta is set when we start the tracker...
|
2017-09-17 23:50:38 -03:00
|
|
|
extra_cmd += ("module load map;"
|
|
|
|
"tracker set port %s; "
|
|
|
|
"tracker start; "
|
|
|
|
"tracker arm;" % (tracker_uarta,))
|
2016-04-27 22:34:15 -03:00
|
|
|
|
|
|
|
if opts.mavlink_gimbal:
|
|
|
|
cmd.extend(["--load-module", "gimbal"])
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
if "extra_mavlink_cmds" in stuff:
|
2016-04-27 22:34:15 -03:00
|
|
|
extra_cmd += " " + stuff["extra_mavlink_cmds"]
|
|
|
|
|
2018-07-03 20:35:06 -03:00
|
|
|
# Parsing the arguments to pass to mavproxy, split args on space
|
|
|
|
# and "=" signs and ignore those signs within quotation marks
|
2016-04-27 22:34:15 -03:00
|
|
|
if opts.mavproxy_args:
|
2018-05-15 21:31:26 -03:00
|
|
|
# It would be great if this could be done with regex
|
|
|
|
mavargs = opts.mavproxy_args.split(" ")
|
|
|
|
# Find the arguments with '=' in them and split them up
|
|
|
|
for i, x in enumerate(mavargs):
|
|
|
|
if '=' in x:
|
|
|
|
mavargs[i] = x.split('=')[0]
|
|
|
|
mavargs.insert(i+1, x.split('=')[1])
|
2018-07-03 20:35:06 -03:00
|
|
|
# Use this flag to tell if parsing character inbetween a pair
|
|
|
|
# of quotation marks
|
2018-05-15 21:31:26 -03:00
|
|
|
inString = False
|
|
|
|
beginStringIndex = []
|
|
|
|
endStringIndex = []
|
2018-07-03 20:35:06 -03:00
|
|
|
# Iterate through the arguments, looking for the arguments
|
|
|
|
# that begin with a quotation mark and the ones that end with
|
|
|
|
# a quotation mark
|
2018-05-15 21:31:26 -03:00
|
|
|
for i, x in enumerate(mavargs):
|
|
|
|
if not inString and x[0] == "\"":
|
|
|
|
beginStringIndex.append(i)
|
|
|
|
mavargs[i] = x[1:]
|
|
|
|
inString = True
|
|
|
|
elif inString and x[-1] == "\"":
|
|
|
|
endStringIndex.append(i)
|
|
|
|
inString = False
|
|
|
|
mavargs[i] = x[:-1]
|
|
|
|
# Replace the list items with one string to be passed into mavproxy
|
|
|
|
for begin, end in zip(beginStringIndex, endStringIndex):
|
|
|
|
replacement = " ".join(mavargs[begin:end+1])
|
|
|
|
mavargs[begin] = replacement
|
|
|
|
mavargs = mavargs[0:begin+1] + mavargs[end+1:]
|
|
|
|
cmd.extend(mavargs)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-05-12 14:15:46 -03:00
|
|
|
# compatibility pass-through parameters (for those that don't want
|
2016-04-28 23:16:53 -03:00
|
|
|
# to use -C :-)
|
|
|
|
for out in opts.out:
|
|
|
|
cmd.extend(['--out', out])
|
|
|
|
if opts.map:
|
|
|
|
cmd.append('--map')
|
|
|
|
if opts.console:
|
|
|
|
cmd.append('--console')
|
2016-09-09 04:36:37 -03:00
|
|
|
if opts.aircraft is not None:
|
|
|
|
cmd.extend(['--aircraft', opts.aircraft])
|
2019-10-02 01:20:35 -03:00
|
|
|
if opts.moddebug:
|
|
|
|
cmd.append('--moddebug=%u' % opts.moddebug)
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2017-12-16 00:22:45 -04:00
|
|
|
if opts.fresh_params:
|
|
|
|
# these were built earlier:
|
|
|
|
path = os.path.join(os.getcwd(), "apm.pdef.xml")
|
|
|
|
cmd.extend(['--load-module', 'param:{"xml-filepath":"%s"}' % path])
|
|
|
|
|
2016-04-27 22:34:15 -03:00
|
|
|
if len(extra_cmd):
|
|
|
|
cmd.extend(['--cmd', extra_cmd])
|
|
|
|
|
2020-03-03 04:38:24 -04:00
|
|
|
# add Tools/mavproxy_modules to PYTHONPATH in autotest so we can
|
|
|
|
# find random MAVProxy helper modules like sitl_calibration
|
2016-05-13 17:55:06 -03:00
|
|
|
local_mp_modules_dir = os.path.abspath(
|
2016-07-04 15:28:06 -03:00
|
|
|
os.path.join(__file__, '..', '..', 'mavproxy_modules'))
|
2016-05-13 17:55:06 -03:00
|
|
|
env = dict(os.environ)
|
2020-03-03 04:38:24 -04:00
|
|
|
old = env.get('PYTHONPATH', None)
|
|
|
|
env['PYTHONPATH'] = local_mp_modules_dir
|
|
|
|
if old is not None:
|
2020-03-03 22:34:51 -04:00
|
|
|
env['PYTHONPATH'] += os.path.pathsep + old
|
2016-05-13 17:55:06 -03:00
|
|
|
|
2020-10-28 15:09:16 -03:00
|
|
|
run_cmd_blocking("Run MavProxy", cmd, env=env)
|
|
|
|
progress("MAVProxy exited")
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
|
2017-05-24 04:18:24 -03:00
|
|
|
vehicle_options_string = '|'.join(vinfo.options.keys())
|
2017-02-19 20:33:55 -04:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
|
2017-02-19 20:33:55 -04:00
|
|
|
def generate_frame_help():
|
|
|
|
ret = ""
|
2017-05-24 04:18:24 -03:00
|
|
|
for vehicle in vinfo.options:
|
2019-07-29 22:00:05 -03:00
|
|
|
frame_options = sorted(vinfo.options[vehicle]["frames"].keys())
|
2017-09-17 23:50:38 -03:00
|
|
|
frame_options_string = '|'.join(frame_options)
|
2017-02-19 20:33:55 -04:00
|
|
|
ret += "%s: %s\n" % (vehicle, frame_options_string)
|
|
|
|
return ret
|
2017-02-14 21:19:58 -04:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
|
2023-03-26 21:23:36 -03:00
|
|
|
# map from some vehicle aliases back to directory names. APMrover2
|
|
|
|
# was the old name / directory name for Rover.
|
|
|
|
vehicle_map = {
|
|
|
|
"APMrover2": "Rover",
|
|
|
|
"Copter": "ArduCopter",
|
|
|
|
"Plane": "ArduPlane",
|
|
|
|
"Sub": "ArduSub",
|
|
|
|
"Blimp" : "Blimp",
|
|
|
|
"Rover": "Rover",
|
|
|
|
}
|
|
|
|
# add lower-case equivalents too
|
|
|
|
for k in list(vehicle_map.keys()):
|
|
|
|
vehicle_map[k.lower()] = vehicle_map[k]
|
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
# define and run parser
|
2017-09-17 23:50:38 -03:00
|
|
|
parser = CompatOptionParser(
|
|
|
|
"sim_vehicle.py",
|
|
|
|
epilog=""
|
2019-03-03 19:43:10 -04:00
|
|
|
"eeprom.bin in the starting directory contains the parameters for your "
|
2017-09-17 23:50:38 -03:00
|
|
|
"simulated vehicle. Always start from the same directory. It is "
|
2019-03-03 19:43:10 -04:00
|
|
|
"recommended that you start in the main vehicle directory for the vehicle "
|
2017-09-17 23:50:38 -03:00
|
|
|
"you are simulating, for example, start in the ArduPlane directory to "
|
|
|
|
"simulate ArduPlane")
|
|
|
|
|
2020-04-07 20:50:21 -03:00
|
|
|
vehicle_choices = list(vinfo.options.keys())
|
2023-03-26 21:23:36 -03:00
|
|
|
|
|
|
|
# add vehicle aliases to argument parser options:
|
|
|
|
for c in vehicle_map.keys():
|
|
|
|
vehicle_choices.append(c)
|
2020-04-07 20:50:21 -03:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
parser.add_option("-v", "--vehicle",
|
|
|
|
type='choice',
|
|
|
|
default=None,
|
|
|
|
help="vehicle type (%s)" % vehicle_options_string,
|
2020-04-07 20:50:21 -03:00
|
|
|
choices=vehicle_choices)
|
2017-02-19 20:33:55 -04:00
|
|
|
parser.add_option("-f", "--frame", type='string', default=None, help="""set vehicle frame type
|
|
|
|
|
|
|
|
%s""" % (generate_frame_help()))
|
2020-12-12 00:55:50 -04:00
|
|
|
|
|
|
|
parser.add_option("--vehicle-binary",
|
|
|
|
default=None,
|
|
|
|
help="vehicle binary path")
|
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
parser.add_option("-C", "--sim_vehicle_sh_compatible",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="be compatible with the way sim_vehicle.sh works; "
|
|
|
|
"make this the first option")
|
2016-09-09 20:51:56 -03:00
|
|
|
|
|
|
|
group_build = optparse.OptionGroup(parser, "Build options")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_build.add_option("-N", "--no-rebuild",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="don't rebuild before starting ardupilot")
|
|
|
|
group_build.add_option("-D", "--debug",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="build with debugging")
|
|
|
|
group_build.add_option("-c", "--clean",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="do a make clean before building")
|
|
|
|
group_build.add_option("-j", "--jobs",
|
|
|
|
default=None,
|
|
|
|
type='int',
|
|
|
|
help="number of processors to use during build "
|
|
|
|
"(default for waf : number of processor, for make : 1)")
|
|
|
|
group_build.add_option("-b", "--build-target",
|
|
|
|
default=None,
|
|
|
|
type='string',
|
|
|
|
help="override SITL build target")
|
2020-04-27 22:30:39 -03:00
|
|
|
group_build.add_option("--enable-math-check-indexes",
|
|
|
|
default=False,
|
|
|
|
action="store_true",
|
|
|
|
dest="math_check_indexes",
|
|
|
|
help="enable checking of math indexes")
|
2023-01-08 18:56:33 -04:00
|
|
|
group_build.add_option("", "--force-32bit",
|
2021-09-07 16:32:24 -03:00
|
|
|
default=False,
|
|
|
|
action='store_true',
|
2023-01-08 18:56:33 -04:00
|
|
|
dest="force_32bit",
|
2021-09-07 16:32:24 -03:00
|
|
|
help="compile sitl using 32-bit")
|
2022-06-26 21:40:06 -03:00
|
|
|
group_build.add_option("", "--configure-define",
|
|
|
|
default=[],
|
|
|
|
action='append',
|
|
|
|
dest="define",
|
|
|
|
help="create a preprocessor define")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_build.add_option("", "--rebuild-on-failure",
|
|
|
|
dest="rebuild_on_failure",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="if build fails, do not clean and rebuild")
|
|
|
|
group_build.add_option("", "--waf-configure-arg",
|
|
|
|
action="append",
|
|
|
|
dest="waf_configure_args",
|
|
|
|
type="string",
|
|
|
|
default=[],
|
|
|
|
help="extra arguments to pass to waf in configure step")
|
|
|
|
group_build.add_option("", "--waf-build-arg",
|
|
|
|
action="append",
|
|
|
|
dest="waf_build_args",
|
|
|
|
type="string",
|
|
|
|
default=[],
|
|
|
|
help="extra arguments to pass to waf in its build step")
|
2021-08-13 09:13:02 -03:00
|
|
|
group_build.add_option("", "--coverage",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="use coverage build")
|
2022-07-10 20:16:55 -03:00
|
|
|
group_build.add_option("", "--ubsan",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
dest="ubsan",
|
|
|
|
help="compile sitl with undefined behaviour sanitiser")
|
|
|
|
group_build.add_option("", "--ubsan-abort",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
dest="ubsan_abort",
|
|
|
|
help="compile sitl with undefined behaviour sanitiser and abort on error")
|
2023-03-03 19:53:50 -04:00
|
|
|
group_build.add_option("--num-aux-imus",
|
|
|
|
dest="num_aux_imus",
|
|
|
|
default=0,
|
|
|
|
type='int',
|
|
|
|
help='number of auxiliary IMUs to simulate')
|
2016-09-09 20:51:56 -03:00
|
|
|
parser.add_option_group(group_build)
|
|
|
|
|
|
|
|
group_sim = optparse.OptionGroup(parser, "Simulation options")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("-I", "--instance",
|
|
|
|
default=0,
|
|
|
|
type='int',
|
|
|
|
help="instance of simulator")
|
2020-01-29 11:55:17 -04:00
|
|
|
group_sim.add_option("-n", "--count",
|
|
|
|
type='int',
|
|
|
|
default=1,
|
|
|
|
help="vehicle count; if this is specified, -I is used as a base-value")
|
|
|
|
group_sim.add_option("-i", "--instances",
|
|
|
|
default=None,
|
|
|
|
type='string',
|
|
|
|
help="a space delimited list of instances to spawn; if specified, overrides -I and -n.")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("-V", "--valgrind",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="enable valgrind for memory access checking (slow!)")
|
|
|
|
group_sim.add_option("", "--callgrind",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="enable valgrind for performance analysis (slow!!)")
|
|
|
|
group_sim.add_option("-T", "--tracker",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="start an antenna tracker instance")
|
2021-06-14 13:04:30 -03:00
|
|
|
group_sim.add_option("", "--enable-onvif",
|
|
|
|
action="store_true",
|
|
|
|
help="enable onvif camera control sim using AntennaTracker")
|
2022-08-21 18:20:39 -03:00
|
|
|
group_sim.add_option("", "--can-gps",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="start a DroneCAN GPS instance (use Tools/scripts/CAN/can_sitl_nodev.sh first)")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("-A", "--sitl-instance-args",
|
|
|
|
type='string',
|
|
|
|
default=None,
|
|
|
|
help="pass arguments to SITL instance")
|
|
|
|
group_sim.add_option("-G", "--gdb",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="use gdb for debugging ardupilot")
|
|
|
|
group_sim.add_option("-g", "--gdb-stopped",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="use gdb for debugging ardupilot (no auto-start)")
|
2019-09-24 14:44:02 -03:00
|
|
|
group_sim.add_option("--lldb",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="use lldb for debugging ardupilot")
|
|
|
|
group_sim.add_option("--lldb-stopped",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="use ldb for debugging ardupilot (no auto-start)")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("-d", "--delay-start",
|
|
|
|
default=0,
|
|
|
|
type='float',
|
|
|
|
help="delay start of mavproxy by this number of seconds")
|
|
|
|
group_sim.add_option("-B", "--breakpoint",
|
|
|
|
type='string',
|
|
|
|
action="append",
|
|
|
|
default=[],
|
|
|
|
help="add a breakpoint at given location in debugger")
|
2020-09-15 01:13:18 -03:00
|
|
|
group_sim.add_option("--disable-breakpoints",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="disable all breakpoints before starting")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("-M", "--mavlink-gimbal",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="enable MAVLink gimbal")
|
|
|
|
group_sim.add_option("-L", "--location", type='string',
|
2019-08-15 03:50:13 -03:00
|
|
|
default=None,
|
2017-09-17 23:50:38 -03:00
|
|
|
help="use start location from "
|
|
|
|
"Tools/autotest/locations.txt")
|
|
|
|
group_sim.add_option("-l", "--custom-location",
|
|
|
|
type='string',
|
|
|
|
default=None,
|
2019-02-01 23:49:43 -04:00
|
|
|
help="set custom start location (lat,lon,alt,heading)")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("-S", "--speedup",
|
|
|
|
default=1,
|
|
|
|
type='int',
|
|
|
|
help="set simulation speedup (1 for wall clock time)")
|
|
|
|
group_sim.add_option("-t", "--tracker-location",
|
|
|
|
default='CMAC_PILOTSBOX',
|
|
|
|
type='string',
|
|
|
|
help="set antenna tracker start location")
|
|
|
|
group_sim.add_option("-w", "--wipe-eeprom",
|
|
|
|
action='store_true',
|
|
|
|
default=False, help="wipe EEPROM and reload parameters")
|
|
|
|
group_sim.add_option("-m", "--mavproxy-args",
|
|
|
|
default=None,
|
|
|
|
type='string',
|
|
|
|
help="additional arguments to pass to mavproxy.py")
|
2020-05-13 11:51:02 -03:00
|
|
|
group_sim.add_option("", "--scrimmage-args",
|
|
|
|
default=None,
|
|
|
|
type='string',
|
|
|
|
help="arguments used to populate SCRIMMAGE mission (comma-separated). "
|
|
|
|
"Currently visual_model, motion_model, and terrain are supported. "
|
|
|
|
"Usage: [instance=]argument=value...")
|
2017-09-17 23:50:38 -03:00
|
|
|
group_sim.add_option("", "--strace",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="strace the ArduPilot binary")
|
|
|
|
group_sim.add_option("", "--model",
|
|
|
|
type='string',
|
|
|
|
default=None,
|
|
|
|
help="Override simulation model to use")
|
|
|
|
group_sim.add_option("", "--use-dir",
|
|
|
|
type='string',
|
|
|
|
default=None,
|
|
|
|
help="Store SITL state and output in named directory")
|
|
|
|
group_sim.add_option("", "--no-mavproxy",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Don't launch MAVProxy")
|
2017-12-16 00:22:45 -04:00
|
|
|
group_sim.add_option("", "--fresh-params",
|
|
|
|
action='store_true',
|
|
|
|
dest='fresh_params',
|
|
|
|
default=False,
|
|
|
|
help="Generate and use local parameter help XML")
|
2019-01-16 16:49:14 -04:00
|
|
|
group_sim.add_option("", "--mcast",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Use multicasting at default 239.255.145.50:14550")
|
2021-07-09 01:06:10 -03:00
|
|
|
group_sim.add_option("", "--udp",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Use UDP on 127.0.0.1:5760")
|
2018-07-01 07:10:29 -03:00
|
|
|
group_sim.add_option("", "--osd",
|
|
|
|
action='store_true',
|
|
|
|
dest='OSD',
|
|
|
|
default=False,
|
|
|
|
help="Enable SITL OSD")
|
2020-09-06 20:18:25 -03:00
|
|
|
group_sim.add_option("", "--osdmsp",
|
|
|
|
action='store_true',
|
|
|
|
dest='OSDMSP',
|
|
|
|
default=False,
|
|
|
|
help="Enable SITL OSD using MSP")
|
2019-03-19 23:36:41 -03:00
|
|
|
group_sim.add_option("", "--tonealarm",
|
|
|
|
action='store_true',
|
|
|
|
dest='tonealarm',
|
|
|
|
default=False,
|
|
|
|
help="Enable SITL ToneAlarm")
|
2019-05-16 01:02:58 -03:00
|
|
|
group_sim.add_option("", "--rgbled",
|
|
|
|
action='store_true',
|
|
|
|
dest='rgbled',
|
|
|
|
default=False,
|
|
|
|
help="Enable SITL RGBLed")
|
2018-04-23 16:23:35 -03:00
|
|
|
group_sim.add_option("", "--add-param-file",
|
|
|
|
type='string',
|
2021-02-02 10:27:27 -04:00
|
|
|
action="append",
|
2018-04-23 16:23:35 -03:00
|
|
|
default=None,
|
|
|
|
help="Add a parameters file to use")
|
2018-05-02 04:22:44 -03:00
|
|
|
group_sim.add_option("", "--no-extra-ports",
|
|
|
|
action='store_true',
|
|
|
|
dest='no_extra_ports',
|
|
|
|
default=False,
|
|
|
|
help="Disable setup of UDP 14550 and 14551 output")
|
2019-01-18 18:33:03 -04:00
|
|
|
group_sim.add_option("-Z", "--swarm",
|
2018-12-25 16:46:13 -04:00
|
|
|
type='string',
|
|
|
|
default=None,
|
|
|
|
help="Specify path of swarminit.txt for shifting spawn location")
|
2021-11-02 21:18:01 -03:00
|
|
|
group_sim.add_option("", "--auto-offset-line",
|
|
|
|
type="string",
|
|
|
|
default=None,
|
|
|
|
help="Argument of form BEARING,DISTANCE. When running multiple instances, form a line along bearing with an interval of DISTANCE", # NOQA
|
|
|
|
)
|
2019-01-21 00:21:10 -04:00
|
|
|
group_sim.add_option("--flash-storage",
|
|
|
|
action='store_true',
|
2021-10-08 00:11:20 -03:00
|
|
|
help="use flash storage emulation")
|
|
|
|
group_sim.add_option("--fram-storage",
|
|
|
|
action='store_true',
|
|
|
|
help="use fram storage emulation")
|
2020-04-11 19:25:31 -03:00
|
|
|
group_sim.add_option("--disable-ekf2",
|
|
|
|
action='store_true',
|
|
|
|
help="disable EKF2 in build")
|
|
|
|
group_sim.add_option("--disable-ekf3",
|
|
|
|
action='store_true',
|
|
|
|
help="disable EKF3 in build")
|
2020-09-04 19:24:20 -03:00
|
|
|
group_sim.add_option("", "--start-time",
|
|
|
|
default=None,
|
|
|
|
type='string',
|
|
|
|
help="specify simulation start time in format YYYY-MM-DD-HH:MM in your local time zone")
|
2018-09-04 14:06:54 -03:00
|
|
|
group_sim.add_option("", "--sysid",
|
|
|
|
type='int',
|
|
|
|
default=None,
|
|
|
|
help="Set SYSID_THISMAV")
|
2021-06-22 02:57:48 -03:00
|
|
|
group_sim.add_option("--postype-single",
|
|
|
|
action='store_true',
|
|
|
|
help="force single precision postype_t")
|
2021-05-04 08:12:24 -03:00
|
|
|
group_sim.add_option("--ekf-double",
|
|
|
|
action='store_true',
|
|
|
|
help="use double precision in EKF")
|
|
|
|
group_sim.add_option("--ekf-single",
|
|
|
|
action='store_true',
|
|
|
|
help="use single precision in EKF")
|
2021-04-24 21:34:27 -03:00
|
|
|
group_sim.add_option("", "--slave",
|
|
|
|
type='int',
|
|
|
|
default=0,
|
|
|
|
help="Set the number of JSON slave")
|
2020-11-09 11:49:04 -04:00
|
|
|
group_sim.add_option("", "--auto-sysid",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Set SYSID_THISMAV based upon instance number")
|
2023-01-21 21:19:14 -04:00
|
|
|
group_sim.add_option("", "--sim-address",
|
|
|
|
type=str,
|
|
|
|
default="127.0.0.1",
|
|
|
|
help="IP address of the simulator. Defaults to localhost")
|
2023-03-10 20:45:28 -04:00
|
|
|
group_sim.add_option("--enable-dds", action='store_true',
|
|
|
|
help="Enable the dds client to connect with ROS2/DDS")
|
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
parser.add_option_group(group_sim)
|
|
|
|
|
|
|
|
|
|
|
|
# special-cased parameters for mavproxy, because some people's fingers
|
|
|
|
# have long memories, and they don't want to use -C :-)
|
2017-09-17 23:50:38 -03:00
|
|
|
group = optparse.OptionGroup(parser,
|
|
|
|
"Compatibility MAVProxy options "
|
|
|
|
"(consider using --mavproxy-args instead)")
|
|
|
|
group.add_option("", "--out",
|
|
|
|
default=[],
|
|
|
|
type='string',
|
|
|
|
action="append",
|
|
|
|
help="create an additional mavlink output")
|
|
|
|
group.add_option("", "--map",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="load map module on startup")
|
|
|
|
group.add_option("", "--console",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="load console module on startup")
|
|
|
|
group.add_option("", "--aircraft",
|
|
|
|
default=None,
|
|
|
|
help="store state and logs in named directory")
|
2019-10-02 01:20:35 -03:00
|
|
|
group.add_option("", "--moddebug",
|
|
|
|
default=0,
|
|
|
|
type=int,
|
|
|
|
help="mavproxy module debug")
|
2019-12-03 21:13:36 -04:00
|
|
|
group.add_option("", "--no-rcin",
|
|
|
|
action='store_true',
|
|
|
|
help="disable mavproxy rcin")
|
2016-09-09 20:51:56 -03:00
|
|
|
parser.add_option_group(group)
|
|
|
|
|
2020-07-09 16:11:50 -03:00
|
|
|
group_completion = optparse.OptionGroup(parser, "Completion helpers")
|
|
|
|
group_completion.add_option("", "--list-vehicle",
|
|
|
|
action='store_true',
|
|
|
|
help="List the vehicles")
|
|
|
|
group_completion.add_option("", "--list-frame",
|
|
|
|
type='string',
|
|
|
|
default=None,
|
|
|
|
help="List the vehicle frames")
|
|
|
|
parser.add_option_group(group_completion)
|
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
cmd_opts, cmd_args = parser.parse_args()
|
|
|
|
|
2020-07-09 16:11:50 -03:00
|
|
|
if cmd_opts.list_vehicle:
|
|
|
|
print(' '.join(vinfo.options.keys()))
|
|
|
|
sys.exit(1)
|
|
|
|
if cmd_opts.list_frame:
|
|
|
|
frame_options = sorted(vinfo.options[cmd_opts.list_frame]["frames"].keys())
|
|
|
|
frame_options_string = ' '.join(frame_options)
|
|
|
|
print(frame_options_string)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
# clean up processes at exit:
|
|
|
|
atexit.register(kill_tasks)
|
|
|
|
|
|
|
|
progress("Start")
|
|
|
|
|
|
|
|
if cmd_opts.sim_vehicle_sh_compatible and cmd_opts.jobs is None:
|
|
|
|
cmd_opts.jobs = 1
|
|
|
|
|
|
|
|
# validate parameters
|
2019-09-24 14:44:02 -03:00
|
|
|
if cmd_opts.valgrind and (cmd_opts.gdb or cmd_opts.gdb_stopped or cmd_opts.lldb or cmd_opts.lldb_stopped):
|
|
|
|
print("May not use valgrind with gdb or lldb")
|
2016-09-09 20:51:56 -03:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-08-29 08:16:23 -03:00
|
|
|
if cmd_opts.valgrind and cmd_opts.callgrind:
|
2016-12-16 19:13:01 -04:00
|
|
|
print("May not use valgrind with callgrind")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-09-24 14:44:02 -03:00
|
|
|
if cmd_opts.strace and (cmd_opts.gdb or cmd_opts.gdb_stopped or cmd_opts.lldb or cmd_opts.lldb_stopped):
|
|
|
|
print("May not use strace with gdb or lldb")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if (cmd_opts.gdb or cmd_opts.gdb_stopped) and (cmd_opts.lldb or cmd_opts.lldb_stopped):
|
|
|
|
print("May not use lldb with gdb")
|
2016-09-09 20:51:56 -03:00
|
|
|
sys.exit(1)
|
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
if cmd_opts.instance < 0:
|
|
|
|
print("May not specify a negative instance ID")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if cmd_opts.count < 1:
|
|
|
|
print("May not specify a count less than 1")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
if cmd_opts.strace and cmd_opts.valgrind:
|
|
|
|
print("valgrind and strace almost certainly not a good idea")
|
|
|
|
|
2016-12-16 19:13:01 -04:00
|
|
|
if cmd_opts.strace and cmd_opts.callgrind:
|
|
|
|
print("callgrind and strace almost certainly not a good idea")
|
|
|
|
|
2021-10-30 18:18:32 -03:00
|
|
|
if cmd_opts.sysid and cmd_opts.auto_sysid:
|
|
|
|
print("Cannot use auto-sysid together with sysid")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
# magically determine vehicle type (if required):
|
|
|
|
if cmd_opts.vehicle is None:
|
|
|
|
cwd = os.getcwd()
|
|
|
|
cmd_opts.vehicle = os.path.basename(cwd)
|
|
|
|
|
2017-05-24 04:18:24 -03:00
|
|
|
if cmd_opts.vehicle not in vinfo.options:
|
2016-09-09 20:51:56 -03:00
|
|
|
# try in parent directories, useful for having config in subdirectories
|
|
|
|
cwd = os.getcwd()
|
|
|
|
while cwd:
|
|
|
|
bname = os.path.basename(cwd)
|
|
|
|
if not bname:
|
|
|
|
break
|
2017-05-24 04:18:24 -03:00
|
|
|
if bname in vinfo.options:
|
2016-09-09 20:51:56 -03:00
|
|
|
cmd_opts.vehicle = bname
|
|
|
|
break
|
|
|
|
cwd = os.path.dirname(cwd)
|
|
|
|
|
2020-04-07 20:50:21 -03:00
|
|
|
if cmd_opts.vehicle in vehicle_map:
|
|
|
|
cmd_opts.vehicle = vehicle_map[cmd_opts.vehicle]
|
2023-03-26 21:23:36 -03:00
|
|
|
elif cmd_opts.vehicle.lower() in vehicle_map:
|
|
|
|
cmd_opts.vehicle = vehicle_map[cmd_opts.vehicle.lower()]
|
2020-04-07 20:50:21 -03:00
|
|
|
|
2016-09-09 20:51:56 -03:00
|
|
|
# try to validate vehicle
|
2017-05-24 04:18:24 -03:00
|
|
|
if cmd_opts.vehicle not in vinfo.options:
|
2017-02-14 21:19:58 -04:00
|
|
|
progress('''
|
|
|
|
** Is (%s) really your vehicle type?
|
|
|
|
Perhaps you could try -v %s
|
|
|
|
You could also try changing directory to e.g. the ArduCopter subdirectory
|
|
|
|
''' % (cmd_opts.vehicle, vehicle_options_string))
|
|
|
|
sys.exit(1)
|
2016-09-09 20:51:56 -03:00
|
|
|
|
|
|
|
# determine frame options (e.g. build type might be "sitl")
|
|
|
|
if cmd_opts.frame is None:
|
2017-05-24 04:18:24 -03:00
|
|
|
cmd_opts.frame = vinfo.options[cmd_opts.vehicle]["default_frame"]
|
2016-09-09 20:51:56 -03:00
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
frame_infos = vinfo.options_for_frame(cmd_opts.frame,
|
|
|
|
cmd_opts.vehicle,
|
|
|
|
cmd_opts)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2020-01-29 11:31:09 -04:00
|
|
|
vehicle_dir = os.path.realpath(os.path.join(root_dir, cmd_opts.vehicle))
|
2016-07-04 15:28:06 -03:00
|
|
|
if not os.path.exists(vehicle_dir):
|
|
|
|
print("vehicle directory (%s) does not exist" % (vehicle_dir,))
|
2016-04-27 22:34:15 -03:00
|
|
|
sys.exit(1)
|
|
|
|
|
2020-01-29 11:55:17 -04:00
|
|
|
if cmd_opts.instances is not None:
|
|
|
|
instances = set()
|
|
|
|
for i in cmd_opts.instances.split(' '):
|
|
|
|
i = (int)(i)
|
|
|
|
if i < 0:
|
|
|
|
print("May not specify a negative instance ID")
|
|
|
|
sys.exit(1)
|
|
|
|
instances.add(i)
|
|
|
|
instances = sorted(instances) # to list
|
|
|
|
else:
|
|
|
|
instances = range(cmd_opts.instance, cmd_opts.instance + cmd_opts.count)
|
|
|
|
|
2021-06-09 08:31:36 -03:00
|
|
|
if cmd_opts.instance == 0:
|
|
|
|
kill_tasks()
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
if cmd_opts.tracker:
|
2020-01-29 11:31:09 -04:00
|
|
|
start_antenna_tracker(cmd_opts)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2022-08-21 18:20:39 -03:00
|
|
|
if cmd_opts.can_gps:
|
|
|
|
start_CAN_GPS(cmd_opts)
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
if cmd_opts.custom_location:
|
2021-02-21 04:48:07 -04:00
|
|
|
location = [(float)(x) for x in cmd_opts.custom_location.split(",")]
|
2016-07-04 15:28:06 -03:00
|
|
|
progress("Starting up at %s" % (location,))
|
2019-08-15 03:50:13 -03:00
|
|
|
elif cmd_opts.location is not None:
|
2020-01-29 11:31:09 -04:00
|
|
|
location = find_location_by_name(cmd_opts.location)
|
2016-07-04 15:28:06 -03:00
|
|
|
progress("Starting up at %s (%s)" % (location, cmd_opts.location))
|
2019-08-15 03:50:13 -03:00
|
|
|
else:
|
|
|
|
progress("Starting up at SITL location")
|
|
|
|
location = None
|
2020-01-29 11:55:17 -04:00
|
|
|
if cmd_opts.swarm is not None:
|
|
|
|
offsets = find_offsets(instances, cmd_opts.swarm)
|
2021-11-02 21:18:01 -03:00
|
|
|
elif cmd_opts.auto_offset_line is not None:
|
|
|
|
if location is None:
|
|
|
|
raise ValueError("location needed for auto-offset-line")
|
|
|
|
(bearing, metres) = cmd_opts.auto_offset_line.split(",")
|
|
|
|
bearing = float(bearing)
|
|
|
|
metres = float(metres)
|
|
|
|
dist = 0
|
|
|
|
offsets = {}
|
|
|
|
for x in instances:
|
|
|
|
offsets[x] = [dist*math.sin(math.radians(bearing)), dist*math.cos(math.radians(bearing)), 0, 0]
|
|
|
|
dist += metres
|
2020-01-29 11:55:17 -04:00
|
|
|
else:
|
2021-02-21 04:48:07 -04:00
|
|
|
offsets = {x: [0.0, 0.0, 0.0, None] for x in instances}
|
2020-01-29 11:55:17 -04:00
|
|
|
if location is not None:
|
|
|
|
spawns = find_spawns(location, offsets)
|
|
|
|
else:
|
|
|
|
spawns = None
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-12-16 13:52:19 -04:00
|
|
|
if cmd_opts.use_dir is not None:
|
2020-01-29 11:55:17 -04:00
|
|
|
base_dir = os.path.realpath(cmd_opts.use_dir)
|
2016-12-16 13:52:19 -04:00
|
|
|
try:
|
2020-01-29 11:55:17 -04:00
|
|
|
os.makedirs(base_dir)
|
2016-12-16 13:52:19 -04:00
|
|
|
except OSError as exception:
|
|
|
|
if exception.errno != errno.EEXIST:
|
|
|
|
raise
|
2020-01-29 11:55:17 -04:00
|
|
|
os.chdir(base_dir)
|
|
|
|
else:
|
|
|
|
base_dir = os.getcwd()
|
|
|
|
instance_dir = []
|
|
|
|
if len(instances) == 1:
|
|
|
|
instance_dir.append(base_dir)
|
|
|
|
else:
|
|
|
|
for i in instances:
|
|
|
|
i_dir = os.path.join(base_dir, str(i))
|
|
|
|
try:
|
|
|
|
os.makedirs(i_dir)
|
|
|
|
except OSError as exception:
|
|
|
|
if exception.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
instance_dir.append(i_dir)
|
2016-12-16 13:52:19 -04:00
|
|
|
|
2021-06-09 08:31:36 -03:00
|
|
|
if True:
|
2016-07-04 15:28:06 -03:00
|
|
|
if not cmd_opts.no_rebuild: # i.e. we should rebuild
|
2021-01-18 08:18:58 -04:00
|
|
|
do_build(cmd_opts, frame_infos)
|
2016-04-28 23:16:53 -03:00
|
|
|
|
2017-12-16 00:22:45 -04:00
|
|
|
if cmd_opts.fresh_params:
|
|
|
|
do_build_parameters(cmd_opts.vehicle)
|
|
|
|
|
2020-12-12 00:55:50 -04:00
|
|
|
if cmd_opts.vehicle_binary is not None:
|
|
|
|
vehicle_binary = cmd_opts.vehicle_binary
|
2022-07-12 02:09:28 -03:00
|
|
|
else:
|
2018-05-04 01:07:41 -03:00
|
|
|
binary_basedir = "build/sitl"
|
2020-01-29 11:31:09 -04:00
|
|
|
vehicle_binary = os.path.join(root_dir,
|
2017-09-17 23:50:38 -03:00
|
|
|
binary_basedir,
|
|
|
|
frame_infos["waf_target"])
|
2016-04-28 23:16:53 -03:00
|
|
|
|
|
|
|
if not os.path.exists(vehicle_binary):
|
|
|
|
print("Vehicle binary (%s) does not exist" % (vehicle_binary,))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-09-17 23:50:38 -03:00
|
|
|
start_vehicle(vehicle_binary,
|
|
|
|
cmd_opts,
|
|
|
|
frame_infos,
|
2020-01-29 11:55:17 -04:00
|
|
|
spawns=spawns)
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2020-01-29 11:55:55 -04:00
|
|
|
|
|
|
|
if cmd_opts.delay_start:
|
|
|
|
progress("Sleeping for %f seconds" % (cmd_opts.delay_start,))
|
|
|
|
time.sleep(float(cmd_opts.delay_start))
|
|
|
|
|
|
|
|
tmp = None
|
|
|
|
if cmd_opts.frame in ['scrimmage-plane', 'scrimmage-copter']:
|
|
|
|
# import only here so as to avoid jinja dependency in whole script
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
from tempfile import mkstemp
|
|
|
|
entities = []
|
|
|
|
config = {}
|
|
|
|
config['plane'] = cmd_opts.vehicle == 'ArduPlane'
|
|
|
|
if location is not None:
|
|
|
|
config['lat'] = location[0]
|
|
|
|
config['lon'] = location[1]
|
|
|
|
config['alt'] = location[2]
|
2020-05-13 11:51:02 -03:00
|
|
|
entities = {}
|
|
|
|
for i in instances:
|
|
|
|
(x, y, z, heading) = offsets[i]
|
|
|
|
entities[i] = {
|
|
|
|
'x': x, 'y': y, 'z': z, 'heading': heading,
|
|
|
|
'to_ardupilot_port': 9003 + i * 10,
|
|
|
|
'from_ardupilot_port': 9002 + i * 10,
|
|
|
|
'to_ardupilot_ip': '127.0.0.1'
|
|
|
|
}
|
|
|
|
if cmd_opts.scrimmage_args is not None:
|
|
|
|
scrimmage_args = cmd_opts.scrimmage_args.split(',')
|
|
|
|
global_opts = ['terrain']
|
|
|
|
instance_opts = ['motion_model', 'visual_model']
|
|
|
|
for arg in scrimmage_args:
|
|
|
|
arg = arg.split('=', 2)
|
|
|
|
if len(arg) == 2:
|
|
|
|
k, v = arg
|
|
|
|
if k in global_opts:
|
|
|
|
config[k] = v
|
|
|
|
elif k in instance_opts:
|
|
|
|
for i in entities:
|
|
|
|
# explicit instance args take precedence; don't overwrite
|
|
|
|
if k not in entities[i]:
|
|
|
|
entities[i][k] = v
|
|
|
|
elif len(arg) == 3:
|
|
|
|
i, k, v = arg
|
|
|
|
try:
|
|
|
|
i = int(i)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
if i in entities and k in instance_opts:
|
|
|
|
entities[i][k] = v
|
|
|
|
config['entities'] = list(entities.values())
|
2020-01-29 11:55:55 -04:00
|
|
|
env = Environment(loader=FileSystemLoader(os.path.join(autotest_dir, 'template')))
|
|
|
|
mission = env.get_template('scrimmage.xml').render(**config)
|
|
|
|
tmp = mkstemp()
|
|
|
|
atexit.register(os.remove, tmp[1])
|
|
|
|
|
|
|
|
with os.fdopen(tmp[0], 'w') as fd:
|
|
|
|
fd.write(mission)
|
|
|
|
run_in_terminal_window('SCRIMMAGE', ['scrimmage', tmp[1]])
|
|
|
|
|
|
|
|
|
2016-07-04 15:28:06 -03:00
|
|
|
if cmd_opts.delay_start:
|
|
|
|
progress("Sleeping for %f seconds" % (cmd_opts.delay_start,))
|
|
|
|
time.sleep(float(cmd_opts.delay_start))
|
2016-04-27 22:34:15 -03:00
|
|
|
|
2016-12-19 10:29:37 -04:00
|
|
|
try:
|
|
|
|
if cmd_opts.no_mavproxy:
|
2017-09-17 23:50:38 -03:00
|
|
|
time.sleep(3) # output our message after run_in_terminal_window.sh's
|
2016-12-19 10:29:37 -04:00
|
|
|
progress("Waiting for SITL to exit")
|
|
|
|
wait_unlimited()
|
|
|
|
else:
|
|
|
|
start_mavproxy(cmd_opts, frame_infos)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
progress("Keyboard Interrupt received ...")
|
2016-04-27 22:34:15 -03:00
|
|
|
|
|
|
|
sys.exit(0)
|