前言
目前互联网平台中关于无人机仿真的博客或视频主要针对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联合仿真后面再更新。