采用最新Ardupilot_gazebo插件和gazebo-sim 7于ubuntu20.04的docker容器内部署
一、Ardupilot_gazebo插件安装
1.安装额外依赖项(for Gazebo garden):
sudo apt update
sudo apt install libgz-sim7-dev rapidjson-dev
2.创建工作区文件夹并克隆插件库:
mkdir -p gz_ws/src && cd gz_ws/src
git clone https://github.com/ArduPilot/ardupilot_gazebo
3.构建插件:根据安装的gazebo版本设置GZ_VERSION环境变量
export GZ_VERSION=garden
cd ardupilot_gazebo
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j4
二、配置Gazebo环境
Gazebo 使用许多环境变量在运行时定位插件和模型。这些可以在用于运行 Gazebo 的终端中设置,或者在.bashrc或.zshrc文件中设置:
在终端:
export GZ_SIM_SYSTEM_PLUGIN_PATH=$HOME/gz_ws/src/ardupilot_gazebo/build:$GZ_SIM_SYSTEM_PLUGIN_PATH
export GZ_SIM_RESOURCE_PATH=$HOME/gz_ws/src/ardupilot_gazebo/models:$HOME/gz_ws/src/ardupilot_gazebo/worlds:$GZ_SIM_RESOURCE_PATH
三、测试运行Gazebo与Ardupilot结合使用
1.运行gazebo:gz sim -v4 -r iris_runway.sdf
2.运行SITL:sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console
3.解锁并起飞:
STABILIZE> mode guided
GUIDED> arm throttle
GUIDED> takeoff 5
(参考:官方文档)
四、多架无人机文件配置
1.模型文件修改
在安装ardupilot_gazebo的文件夹/gz_ws/src/ardupilot_gazebo/models中有文件夹iris_with_ardupilot将其复制三个(所需无人机个数),分别改名为iris_with_ardupilot_9002,iris_with_ardupilot_9012,iris_with_ardupilot_9022(文件夹名后的数字仅为方便对应端口号,原则任意填写文件夹名)
同样的有文件夹iris_with_standoffs将其复制三个,分别改名为iris_with_standoffs_9002,iris_with_standoffs_9012,iris_with_standoffs_9022
2.模型文件信息修改
以文件夹iris_with_ardupilot_9002为例,修改其内文件model.sdf,将model name修改为iris_with_ardupilot_9002,标签内的地址修改为model://iris_with_standoffs_9002(两文件夹存在引用)
在plugins注释后的代码段中找到plugin name为ArduPilotPlugin的标签,将 <fdm_port_in>下添加 <fdm_port_out>并在原有端口上加1
model.sdf代码段中有很多设置传感器的部分,其中每一部分的引用都要改为model name,使用ctrl+h进行搜索iris_with_ardupilot并替换为iris_with_ardupilot_9002(已被注释部分可不用修改)
修改model.config文件,代码段尾部的标签内的路径修改为iris_with_standoffs_9002,到此关于iris_with_ardupilot_9002文件夹下的文件修改完毕,其余文件夹中的文件类似处理即可。
以文件夹iris_with_standoffs_9002为例,修改其内文件model.sdf,将model name改为iris_with_standoffs_9002
model.sdf代码段中有很多旋翼设置,其中每一部分的引用都要改为model name,使用ctrl+h进行搜索iris_with_standoffs并替换为iris_with_standoffs_9002(已被注释部分可不用修改),到此关于iris_with_standoffs_9002文件夹下的文件修改完毕,其余文件夹中的文件类似处理即可。
3.加载世界文件修改
在安装Ardupilot_gazebo文件夹下,/gz_ws/src/ardupilot_gazebo/worlds复制其中文件iris_runway.sdf留存备份,在其代码段底部添加三架无人机模型路径信息(原本有一架,将其修改即可需将pose degress调整使其错开)并保存。
4.启动无人机并连接Gazebo
新建四个终端并分别输入:
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console -I0
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console -I1
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console -I2
gz sim -v4 -r iris_runway.sdf
前三行分别是启动三个无人机并按id进行端口排序,默认9002,9012,9022,最后一行是启动具有多无人机的世界场景。