无人机仿真 APM+Gazebo+SITL+QGC仿真教学及常见问题记录与解决方法


前言

目前互联网平台中关于无人机仿真的博客或视频主要针对PX4固件,对于APM固件的仿真内容较少,本文用于记录个人在学习与仿真过程中遇到的问题及解决方法。请确保你已安装ROS。

一、APM环境搭建

1、环境配置

APM官方链接:APM_Link

sudo apt-get update
git clone git@github.com:ArduPilot/ardupilot.git
cd ardupilot
git submodule update --init --recursive
Tools/environment_install/install-prereqs-ubuntu.sh -y
. ~/.profile

在克隆过程中很容易因为网络问题导致出错,建议直接去GitHub下载压缩包解压至Ubuntu

git submodule update --init --recursive 这一步容易因为网络中断,多运行几次即可

2、修改环境变量

sudo gedit ~/.bashrc
export PATH=$PATH:$HOME/ardupilot/Tools/autotest
export PATH=/usr/lib/ccache:$PATH
. ~/.bashrc

二、APM联合SITL简易仿真与问题解决

代码如下(示例):

cd ~/ardupilot/ArduCopter
sim_vehicle.py --map --console

效果图:
在这里插入图片描述

常见BUG

无法显示console和map

报错提示:
Failed to load module: No module named ‘console’. Use ‘set moddebug 3’ in the MAVProxy console to enable traceback Failed to load module: No module named ‘map’. Use ‘set moddebug 3’ in the MAVProxy console to enable traceback

1、针对Anaconda的环境

解决方法1:python几个包未安装好,需要删除后重装

pip3 uninstall MAVProxy pymavlink future lxml
sudo -H pip2 install --upgrade MAVProxy pymavlink future lxml

2、针对虚拟机原环境

解决方法1:mavproxy未安装好,参考官方链接安装link

sudo apt-get install python3-dev python3-opencv python3-wxgtk4.0 python3-pip python3-matplotlib python3-lxml python-pygame
pip3 install PyYAML mavproxy --user
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc

三、Gazebo仿真搭建

环境搭建

git clone https://github.com/SwiftGust/ardupilot_gazebo
cd ardupilot_gazebo
mkdir build
cd build
cmake ..
make -j4
sudo make install

在克隆时容易出错,同样建议直接通过GitHub下载压缩包解压。注意,要将文件夹名字从ardupilot_gazebo-master重命名为ardupilot_gazebo

常见BUG

1、CMake Error at CMakeLists.txt:11 (find_package):

By not providing “Findgazebo.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “gazebo”, but
CMake did not find one.
在这里插入图片描述
解决方法:

sudo apt-get install ros-melodic-gazebo-dev

针对Ubuntu18.04系统,其他系统请将melodic修改为你对应的系统版本

2、 error: no matching function for call to ‘google::protobuf::internal::ArenaStringPtr::GetNoArena(const string*) const’

在这里插入图片描述
解决方法:需要更新proto版本,依旧推荐直接下载压缩包然后解压至Ubuntu

sudo apt-get remove --purge protobuf-compiler 
sudo apt-get install libprotobuf-dev protobuf-compiler
wget https://github.com/google/protobuf/archive/v3.0.0.zip
unzip v3.0.0.zip
cd protobuf-3.0.0
gedit autogen.sh

注释掉autogen.sh文件内的

echo "Google Mock not present.  Fetching gmock-1.7.0 from the web..."
curl $curlopts -O https://googlemock.googlecode.com/files/gmock-1.7.0.zip

进行编译

./autogen.sh 
./configure
make
sudo make install

然后回到ardupilot_gazebo的build文件夹

sudo apt-get install ros-melodic-gazebo-dev
cmake ..
make -j4

成功搭建
在这里插入图片描述

修改环境变量

sudo gedit ~/.bashrc

文章末尾加入以下内容:

source /usr/share/gazebo/setup.sh
export GAZEBO_MODEL_PATH=~/ardupilot_gazebo/models:${GAZEBO_MODEL_PATH}
export GAZEBO_MODEL_PATH=~/ardupilot_gazebo/models_gazebo:${GAZEBO_MODEL_PATH}
export GAZEBO_RESOURCE_PATH=~/ardupilot_gazebo/worlds:${GAZEBO_RESOURCE_PATH}
export GAZEBO_PLUGIN_PATH=~/ardupilot_gazebo/build:${GAZEBO_PLUGIN_PATH}

四、Gazebo联合SITL仿真测试

效果展示

本次测试针对固定翼飞机,请根据你的需要将Arduplane更改为你需要的机种。

第一个终端窗口:

sim_vehicle.py -v ArduPlane -f gazebo-zephyr --map --console -I0

第二个终端窗口:

gazebo --verbose zephyr_ardupilot_demo.world

在这里插入图片描述

常见BUG

1、不显示map地图

解决方法:按照上面的第二步方法解决

2、console显示link 1 down 超时

在这里插入图片描述
解决方法:这是由于只执行了SITL的仿真,没有执行gazebo启动代码

sim_vehicle.py -v ArduPlane -f gazebo-zephyr --map --console -I0

在第二个终端窗口执行gazebo启动代码即可。

gazebo --verbose zephyr_ardupilot_demo.world

3、gazebo启动报错:[Err] [ModelDatabase.cc:235] No tag in the model database database.config found here[http://gazebosim.org/models/] [Err] [ModelDatabase.cc:294] Unable to download model manifests

在这里插入图片描述

解决方法:
1、这是因为http://gazebosim.org/models/地址已经变换http://models.gazebosim.org,修改文件下载路径

sudo gedit /usr/share/gazebo/setup.sh
sudo gedit /usr/share/gazebo-9/setup.sh

将export GAZEBO_MODEL_DATABASE_URI=http://gazebosim.org/models修改为:

export GAZEBO_MODEL_DATABASE_URI=http://models.gazebosim.org/

2、缺少manifest.xml文件

cd ~/ardupilot_gazebo/models
wget http://models.gazebosim.org/manifest.xml

4、[Err] [REST.cc:205] Error in REST request

在这里插入图片描述

sudo gedit ~/.ignition/fuel/config.yaml

把url: https://api.ignitionfuel.org修改为:

url: https://api.ignitionrobotics.org  

总结

相对来说,直接使用Ubuntu自带的3.6.9python环境会更加容易搭建仿真环境,anaconda的环境始终会出一些问题,QGC联合仿真后面再更新。

  • 46
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
PX4 Gazebo无人机仿真是一种利用Gazebo仿真软件来模拟现实世界中无人机的行为和环境的方法。通过PX4的源代码,我们可以获得PX4无人机Gazebo模型,通过运行launch文件,我们可以在Gazebo环境中模拟出一个无人机。这种仿真环境可以帮助开发者测试和调试无人机的控制算法和系统。它还可以用于学习ROS系统的基本操作和与无人机进行通讯,如使用MAVROS进行通讯。 在使用PX4 Gazebo无人机仿真的过程中,首先需要打开Gazebo环境,此时会显示一个地面上有一个无人机的场景。然后,我们可以通过使用rostopic echo /mavros/state命令来测试无人机的通讯状态。这个仿真环境可以帮助我们进行无人机的控制和跟踪移动物体等实验。 总结来说,PX4 Gazebo无人机仿真是一种通过Gazebo仿真软件来模拟无人机行为和环境的方法,可以用于测试和调试无人机的控制算法和系统,以及学习ROS系统的基本操作和与无人机进行通讯。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [PX4无人机-Gazebo仿真实现移动物体的跟踪](https://blog.csdn.net/qq_44939973/article/details/120965458)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值