PX4
环境在Ubuntu 18.04
下的搭建过程和问题总结。由于gazebo在ros安装中一般会包括,所以gazebo安装没有介绍。
这是我第一次接触ubuntu系统的安装,所以可能有些步骤有错误或者多余,敬请批评指正。
1.下载安装脚本ubuntu.sh和requeirements.txt,不太懂这个要干嘛而且很多教程中没有,所以我就试了一下反正不亏。
wget https://raw.githubusercontent.com/PX4/Firmware/master/Tools/setup/ubuntu.sh wget https://raw.githubusercontent.com/PX4/Firmware/master/Tools/setup/requirements.txt
2.运行ubuntu.sh安装,安装完成后需要重启电脑。
source ubuntu.sh
3.安装完成后的检查
运行命令检查
arm-none-eabi-gcc --version
如果出现下面就是安装Nuttx成功
这一板块我也是参考了好多教程,大家可以直接看链接中的文章,讲的非常详细:
无人机仿真搭建:ROS,Gazebo,SITL,MAVROS,PX4_waitin丶的博客-CSDN博客
1.下载代码
git clone https://github.com/ArduPilot/ardupilot cd ardupilot git submodule update --init --recursive
第三个指令最容易出错,因为github网站难以访问,容易出现连接失败,方法主要有换网站将.gitmodules文件中所有github.com替换为github.com.cnpmjs.org,或者直接下载失败的安装包。
但我在安装过程中发现在浏览器中打开那个连接失败的github网址可以提高连接的成功率,然后重复命令几次就行。
2.安装依赖
Tools/environment_install/install-prereqs-ubuntu.sh -y . ~/.profile
3.测试
执行一个python脚本就可以测试
cd ~/ardupilot/ArduCopter sim_vehicle.py --map --console
没出错,看到界面就行。如果有错就复制搜索一下。
1.
sudo apt install ros-melodic-mavros ros-melodic-mavros-extras
2.
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
这一步连接需要花费一些时间,出现连接错误可以试着更换网络或者换成http。
3.
sudo chmod a+x ./install_geographiclib_datasets.sh
4.
sudo ./install_geographiclib_datasets.sh
这里出现三个installing就好了,据说要花些时间,应该也是网络的问题。
下载源码有两种方式,一种在github上下载源码,但是速度非常慢,一种在gitee上下载源码,我就直接挂gitee了,注意不同教程下载下的文件可能有些路径不太一样。
1.
git clone https://gitee.com/robin_shaun/PX4_Firmware cd PX4_Firmware git checkout -b xtdrone/dev v1.11.0-beta1
然后需要修改一下.gitmodules文件
先备份:
sudo cp .gitmodules .gitmodules.bak
打开文件
sudo gedit .gitmodules
内容替换为:
[submodule "mavlink/include/mavlink/v2.0"] path = mavlink/include/mavlink/v2.0 url = https://gitee.com/robin_shaun/c_library_v2.git branch = master [submodule "src/drivers/uavcan/libuavcan"] path = src/drivers/uavcan/libuavcan url = https://gitee.com/robin_shaun/uavcan.git branch = px4 [submodule "Tools/jMAVSim"] path = Tools/jMAVSim url = https://gitee.com/robin_shaun/jMAVSim.git branch = master [submodule "Tools/sitl_gazebo"] path = Tools/sitl_gazebo url = https://gitee.com/robin_shaun/sitl_gazebo.git branch = master [submodule "src/lib/matrix"] path = src/lib/matrix url = https://gitee.com/robin_shaun/Matrix.git branch = master [submodule "src/lib/ecl"] path = src/lib/ecl url = https://gitee.com/robin_shaun/ecl.git branch = master [submodule "boards/atlflight/cmake_hexagon"] path = boards/atlflight/cmake_hexagon url = https://gitee.com/robin_shaun/cmake_hexagon.git branch = px4 [submodule "src/drivers/gps/devices"] path = src/drivers/gps/devices url = https://gitee.com/robin_shaun/GpsDrivers.git branch = master [submodule "src/modules/micrortps_bridge/micro-CDR"] path = src/modules/micrortps_bridge/micro-CDR url = https://gitee.com/robin_shaun/micro-CDR.git branch = px4 [submodule "platforms/nuttx/NuttX/nuttx"] path = platforms/nuttx/NuttX/nuttx url = https://gitee.com/robin_shaun/NuttX.git branch = px4_firmware_nuttx-9.1.0+ [submodule "platforms/nuttx/NuttX/apps"] path = platforms/nuttx/NuttX/apps url = https://gitee.com/robin_shaun/NuttX-apps.git branch = px4_firmware_nuttx-9.1.0+ [submodule "platforms/qurt/dspal"] path = platforms/qurt/dspal url = https://gitee.com/robin_shaun/dspal.git [submodule "Tools/flightgear_bridge"] path = Tools/flightgear_bridge url = https://gitee.com/robin_shaun/PX4-FlightGear-Bridge.git branch = master [submodule "Tools/jsbsim_bridge"] path = Tools/jsbsim_bridge url = https://gitee.com/robin_shaun/px4-jsbsim-bridge.git [submodule "src/examples/gyro_fft/CMSIS_5"] path = src/examples/gyro_fft/CMSIS_5 url = https://gitee.com/mirrors/CMSIS_5
然后运行
git submodule update --init --recursive
无论用哪种方式下载完源码,都需要安装依赖才能成功编译,我之前在这卡了很久就是没有安装依赖就编译(引用原话)
cd ~/PX4_Firmware bash ./Tools/setup/ubuntu.sh --no-nuttx --no-sim-tools
make px4_sitl_default gazebo
这里最容易出现问题,我在后面进行总结。
编译成功之后应该会打开gazebo并且没有报错
修改.bashrc文件
sudo gedit ~/.bashrc
在最末尾加入下面的代码,注意路径有可能不同,注意检查,前两个source不能颠倒
source ~/catkin_ws/devel/setup.bash source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware/Tools/sitl_gazebo
运行
source ~/.bashrc
cd ~/PX4_Firmware roslaunch px4 mavros_posix_sitl.launch
这时gazebo将会启动,注意检查有没有错误。
打开另一个终端
rostopic echo /mavros/state
connected:True,说明MAVROS与SITL通讯成功
1.github连接失败
这个是前期困扰很久的问题,想过翻墙但ubuntu不知道怎么翻,想着换网站这个方法解决了大部分问题,但是会剩下一两个依然跑到github去clone,气坏我了。师兄告诉我可以直接去下载然后安装,但我发现从终端里打开那个网址后,他就可以clone了,就重复几次
git submodule update --init --recursive
就完成了。
2.缺少waf_light文件
这个问题有些神奇,因为都是在一个开源站下的为啥别人没遇到,但我在gitee上找到了这个文件,放到路径中:home/ardupilot/modules/waf/waf-master,并且这个文件版本不能太高2.0.9不行,1.9.0行。
3.报错集锦
我遇到了个宝藏博主,写了个问题总结,解决了两个大问题,感动哭了。
搭建无人机仿真环境之PX4安装_wangdongjiab的博客-CSDN博客
下面我主要说我的错误:
ninja: build stopped: subcommand failed. Makefile:198: recipe for target 'px4_sitl_default' failed make: *** [px4_sitl_default] Error 1
这个问题,在网上搜了好多,但都是193, 200没有和我相同的,直到遇到这个大神。
解决方法:
sudo apt-get install libgstreamer-plugins-base1.0-dev
在最后的测试环节我遇到了:
RLException: [indoor1.launch] is neither a launch file in package [px4] nor is [px4] a launch file name The traceback for the exception was written to the log file
也是搜了好久,
解决方法:
source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware/Tools/sitl_gazebo
为了大家能找到这个错误,我直接复制粘贴一波。
ninja: build stopped: subcommand failed.
Makefile:198: recipe for target 'px4_sitl_default' failed
make: *** [px4_sitl_default] Error 1
RLException: [indoor1.launch] is neither a launch file in package [px4] nor is [px4] a launch file name
The traceback for the exception was written to the log file