文章

ArduPilot SITL的编译及使用

1. 下载及编译

1
2
3
4
5
6
7
8
9
git clone https://gitcode.com/ArduPilot/ardupilot.git
cd ardupilot
git submodule update --init --recursive
``

安装依赖,安装完成之后,重新进入终端,以使能一些环境变量:

```bash
./Tools/environment_install/install-prereqs-ubuntu.sh -y

安装之后,可能会提示有一些包没有安装成功,可以手动安装这些包。另外,创建venv环境可能会好一些。

编译SITL(编译为固定翼SITL):

1
2
3
# do not use waf using sudo
./waf configure --board sitl
./waf plane -j6

1.1. 编译参数

使用waf配置以及编译的参数格式分别为:

1
2
./waf configure --board <board_name>
./waf <vehicle_type> -j<cpu_cores>

ArduPilot支持的板子非常多,使用如下命令列出支持的板子:

1
./waf list_boards

而常见的vehicle命令如下:

1
2
3
4
5
6
7
./waf copter                            # All multirotor types
./waf heli                              # Helicopter types
./waf plane                             # Fixed wing airplanes including VTOL
./waf rover                             # Ground-based rovers and surface boats
./waf sub                               # ROV and other submarines
./waf antennatracker                    # Antenna trackers
./waf AP_Periph                         # AP Peripheral

2. SITL仿真

首先创建一个仿真位置文件:~/.config/ardupilot/locations.txt,用于设置仿真时的地理位置。 内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#NAME=latitude,longitude,absolute-altitude,heading
# User custom locations for ArduPilot SITL simulation
# Format: LOCATION_NAME=latitude,longitude,altitude_in_meters,heading_in_degrees

# Hefei, Anhui Province, China locations
Hefei=31.820587,117.227005,30,0
Hefei_North=31.820587,117.227005,30,0
Hefei_East=31.820587,117.227005,30,90
Hefei_South=31.820587,117.227005,30,180
Hefei_West=31.820587,117.227005,30,270

# Hefei University of Technology (approximately)
HFUT=31.841887,117.282699,35,0

# Hefei Xinqiao International Airport
HefeiAirport=31.781389,117.298333,35,90

# Hefei High-tech Zone (typical location)
HefeiHighTech=31.837722,117.169167,25,0

# Downtown Hefei
HefeiDowntown=31.864444,117.283056,28,0

2.1. TCP连接

1
2
# 创建TCP连接的`SITL`仿真的命令如下,禁用`MAVProxy`
./Tools/autotest/sim_vehicle.py --vehicle=ArduPlane --model=plane --count=2 --auto-sysid --location Hefei --auto-offset-line=0,100 --no-mavproxy

SITL所在Ubuntu的IP地址为192.168.137.176,则创建之后,生成两个SITL实例,分别监听在57605770端口。使用QGC连接时,需要创建两个TCP连接,连接参数如下:

1
2
Server Address: 192.168.137.176
Port: 5760  (或 5770)
  • TCP连接时,SITL中的飞控作为服务端,QGC作为客户端进行连接。

2.2. UDP连接

1
./Tools/autotest/sim_vehicle.py --vehicle=ArduPlane --model=plane --count=2 --auto-sysid --location Hefei --auto-offset-line=0,100 --no-mavproxy -A "--serial0=udpclient:192.168.11.139:14550"

对应的,QGC的连接参数如下:

1
2
Connection Type: UDP
Local Port: 14550
  • 此时,SITL中的飞控作为客户端,QGC作为服务端,监听端口14550的消息。
  • 经过测试,似乎此时不能发送UDP消息给SITL,只能接收SITL发送过来的消息。

3. ArduPilot 代码解读

3.1. model 参数

运行编译好的SITL时,可以通过--model参数指定仿真器模型,model参数列表定义在SITL_cmdline.cpp文件的model_constructorsSITL_cmdline.cpp

4. 第三方启动脚本

5. 资料

5.1 资源

本文由作者按照 CC BY 4.0 进行授权