我是靠谱客的博主 紧张雨,这篇文章主要介绍sim_vehcle.py仿真默认采用waf编译器的原因,现在分享给大家,希望可以做个参考。

APM软件在环仿真的启动脚本是sim_vehicle.py。
其第281行,定义了一个函数“do_build_waf(opts, frame_options)”,指定了SITL仿真时目标文件的编译默认使用waf而不是make。代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)”

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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)”,代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()”,代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)”,代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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编译器内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部