概述
APM软件在环仿真的启动脚本是sim_vehicle.py。
其第281行,定义了一个函数“do_build_waf(opts, frame_options)”,指定了SITL仿真时目标文件的编译默认使用waf而不是make。代码如下:
def do_build_waf(opts, frame_options):
"""Build sitl using waf"""
progress("WAF build")
old_dir = os.getcwd() //当前目录Tools/
root_dir = find_root_dir()
os.chdir(root_dir) //目录ardupilot/
waf_light = os.path.join(root_dir, "modules/waf/waf-light") //文件路径ardupilot/modules/waf/waf-light
cmd_configure = [waf_light, "configure", "--board", "sitl"] //cmd命令waf_light.py configure --board sitl
if opts.debug:
cmd_configure.append("--debug") //增加debug调试
if opts.OSD:
cmd_configure.append("--enable-sfml")
pieces = [shlex.split(x) for x in opts.waf_configure_args]
for piece in pieces:
cmd_configure.extend(piece)
run_cmd_blocking("Configure waf", cmd_configure, check=True)
if opts.clean:
run_cmd_blocking("Building clean", [waf_light, "clean"])
cmd_build = [waf_light, "build", "--target", frame_options["waf_target"]] //waf编译 :waf_light.py --target=waf_target
if opts.jobs is not None:
cmd_build += ['-j', str(opts.jobs)] //-j4
pieces = [shlex.split(x) for x in opts.waf_build_args]
for piece in pieces:
cmd_build.extend(piece)
_, sts = run_cmd_blocking("Building", cmd_build)
if sts != 0: # build failed
if opts.rebuild_on_failure:
progress("Build failed; cleaning and rebuilding")
run_cmd_blocking("Building clean", [waf_light, "clean"])
_, sts = run_cmd_blocking("Building", cmd_build)
if sts != 0:
progress("Build failed")
sys.exit(1)
else:
progress("Build failed")
sys.exit(1)
os.chdir(old_dir)
定义函数“do_build_parameters(vehicle)”
def do_build_parameters(vehicle):
# build succeeded
# now build parameters
progress("Building fresh parameter descriptions")
param_parse_path = os.path.join(
find_root_dir(), "Tools/autotest/param_metadata/param_parse.py") //执行脚本ardupilot/Tools/autotest/param_metadata/param_parse.py
cmd_param_build = ["python", param_parse_path, '--vehicle', vehicle] //python param_parse.py --vehicle
_, sts = run_cmd_blocking("Building fresh params", cmd_param_build)
if sts != 0:
progress("Parameter build failed")
sys.exit(1)
函数“do_build(vehicledir, opts, frame_options)”,代码如下:
def do_build(vehicledir, opts, frame_options):
"""Build build target (e.g. sitl) in directory vehicledir"""
if opts.build_system == 'waf':
return do_build_waf(opts, frame_options)
old_dir = os.getcwd()
os.chdir(vehicledir)
if opts.clean:
run_cmd_blocking("Building clean", ["make", "clean"])
build_target = frame_options["make_target"]
if opts.debug:
build_target += "-debug"
build_cmd = ["make", build_target]
if opts.jobs is not None:
build_cmd += ['-j', str(opts.jobs)]
_, sts = run_cmd_blocking("Building %s" % build_target, build_cmd)
if sts != 0:
progress("Build failed; cleaning and rebuilding")
run_cmd_blocking("Cleaning", ["make", "clean"])
_, sts = run_cmd_blocking("Building %s" % build_target, build_cmd)
if sts != 0:
progress("Build failed")
sys.exit(1)
os.chdir(old_dir) //执行该函数,回到路径Tools/
函数“get_user_locations_path()”,代码如下:
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
$HOME is not defined, we look in ./.config/ardpupilot/locations.txt.'''
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
函数“find_location_by_name(autotest,locname)”,代码如下:
def find_location_by_name(autotest, locname):
"""Search locations.txt for locname, return GPS coords"""
locations_userpath = os.environ.get('ARDUPILOT_LOCATIONS',
get_user_locations_path())
locations_filepath = os.path.join(autotest, "locations.txt")
comment_regex = re.compile("s*#.*")
for path in [locations_userpath, locations_filepath]:
if not os.path.isfile(path):
continue
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:
return loc
print("Failed to find location (%s)" % cmd_opts.location)
sys.exit(1)
可以知道,home点的定义在Tools/autotest/location.txt文件中。启用命令是“-L”
最后
以上就是紧张雨为你收集整理的sim_vehcle.py仿真默认采用waf编译器的原因的全部内容,希望文章能够帮你解决sim_vehcle.py仿真默认采用waf编译器的原因所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复