PX4安装和编译遇到一些坑

最近由于实验需要,又得安装px4和gazebo,特此记录一些遇到的bug和解决方法,希望能帮助其他uu。

1下载

一般的安装步骤如下(不建议完全按下面命令执行):

点击查看代码
git clone https://github.com/PX4/PX4-Autopilot.git
mv PX4-Autopilot PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1
#到这一步git submodule一般就因为网络原因总是出错了
git submodule update --init --recursive
make px4_sitl_default gazebo
由于需要在GitHub下载代码,而国内访问受限,可能会出现一些问题,这里建议使用github国内镜像,当然下面会给出具体解决方案。

更新工程子模块git submodule update --init --recursive

若该步骤出错,归根到底还是因为github访问不稳定。
解决方案如下:
方案的总体原则就是改变源码里面各个.gitmodules文件里的下载地址,需要注意的是源码位置,我这里是将源码放在主文件夹下,也就是~/PX4_Firmware,后面的代码是我借鉴其他博客的,所以PX4_Firmware还是PX4_Autopilot根据你的px4改没改名决定

(1)源码主文件夹下

cd ~/PX4_Autopilot
gedit .gitmodules
(注意:这里主要是为了修改文件,我用的是gedit编辑器,也可以用vim, nano,vs code之类的,后面相同)
将 .gitmodules 中的内容更换为:

点击查看代码
#注意这里的格式不对,你只需改一下url的内容就行,大概就是让你通过gitee下载而不是github下载,解决网络不稳定问题
[submodule "mavlink/include/mavlink/v2.0"]path = mavlink/include/mavlink/v2.0url = https://gitee.com/robin_shaun/c_library_v2.gitbranch = master
[submodule "src/drivers/uavcan/libuavcan"]path = src/drivers/uavcan/libuavcanurl = https://gitee.com/robin_shaun/uavcan.gitbranch = px4
[submodule "Tools/jMAVSim"]path = Tools/jMAVSimurl = https://gitee.com/robin_shaun/jMAVSim.gitbranch = master
[submodule "Tools/sitl_gazebo"]path = Tools/sitl_gazebourl = https://gitee.com/robin_shaun/sitl_gazebo.gitbranch = master
[submodule "src/lib/matrix"]path = src/lib/matrixurl = https://gitee.com/robin_shaun/Matrix.gitbranch = master
[submodule "src/lib/ecl"]path = src/lib/eclurl = https://gitee.com/robin_shaun/ecl.gitbranch = master
[submodule "boards/atlflight/cmake_hexagon"]path = boards/atlflight/cmake_hexagonurl = https://gitee.com/robin_shaun/cmake_hexagon.gitbranch = px4
[submodule "src/drivers/gps/devices"]path = src/drivers/gps/devicesurl = https://gitee.com/robin_shaun/GpsDrivers.gitbranch = master
[submodule "src/modules/micrortps_bridge/micro-CDR"]path = src/modules/micrortps_bridge/micro-CDRurl = https://gitee.com/robin_shaun/micro-CDR.gitbranch = px4
[submodule "platforms/nuttx/NuttX/nuttx"]path = platforms/nuttx/NuttX/nuttxurl = https://gitee.com/robin_shaun/NuttX.gitbranch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/nuttx/NuttX/apps"]path = platforms/nuttx/NuttX/appsurl = https://gitee.com/robin_shaun/NuttX-apps.gitbranch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/qurt/dspal"]path = platforms/qurt/dspalurl = https://gitee.com/robin_shaun/dspal.git
[submodule "Tools/flightgear_bridge"]path = Tools/flightgear_bridgeurl = https://gitee.com/robin_shaun/PX4-FlightGear-Bridge.gitbranch = master 
[submodule "Tools/jsbsim_bridge"]path = Tools/jsbsim_bridgeurl = https://gitee.com/robin_shaun/px4-jsbsim-bridge.git
[submodule "src/examples/gyro_fft/CMSIS_5"]path = src/examples/gyro_fft/CMSIS_5url = https://gitee.com/mirrors/CMSIS_5
git submodule update --init

(2) libuavcan文件夹

cd ~/PX4_Autopilot/src/drivers/uavcan/libuavcan
gedit .gitmodules
将 .gitmodules 中的内容更换为:

点击查看代码
#同上,只需改url,下面都一样
[submodule "dsdl"]path = dsdlurl = https://gitee.com/robin_shaun/dsdlbranch = legacy-v0
[submodule "libuavcan/dsdl_compiler/pyuavcan"]path = libuavcan/dsdl_compiler/pyuavcanurl = https://gitee.com/robin_shaun/pyuavcan
[submodule "libuavcan_drivers/kinetis"]path = libuavcan_drivers/kinetisurl = https://gitee.com/robin_shaun/libuavcan_kinetis.git
git submodule update --init

(3) jMAVSim文件夹

cd ~/PX4_Autopilot/Tools/jMAVSim
gedit .gitmodules
将 .gitmodules 中的内容更换为:

点击查看代码
[submodule "jMAVlib"]path = jMAVliburl = https://gitee.com/robin_shaun/jMAVlibbranch = master
git submodule update --init

(4) sitl_gazebo文件夹

cd ~/PX4_Autopilot/Tools/sitl_gazebo
gedit .gitmodules
将 .gitmodules 中的内容更换为:

点击查看代码
[submodule "external/OpticalFlow"]path = external/OpticalFlowurl = https://gitee.com/robin_shaun/OpticalFlow
git submodule update --init

(5) dspal文件夹

cd ~/PX4_Autopilot/platforms/qurt/dspal
gedit .gitmodules
将 .gitmodules 中的内容更换为:

点击查看代码
[submodule "cmake_hexagon"]path = cmake_hexagonurl = https://gitee.com/robin_shaun/cmake_hexagon
git submodule update --init

(6) pyuavcan文件夹

cd ~/PX4_Autopilot/src/drivers/uavcan/libuavcan/libuavcan/dsdl_compiler/pyuavcan
gedit .gitmodules
将 .gitmodules 中的内容更换为:

点击查看代码
[submodule "dsdl"]path = dsdlurl = https://gitee.com/robin_shaun/dsdl
git submodule update --init

(7) OpticalFlow文件夹

cd ~/PX4_Autopilot/Tools/sitl_gazebo/external/OpticalFlow
gedit .gitmodules
将 .gitmodules 中的内容更换为:

点击查看代码
[submodule "external/klt_feature_tracker"]path = external/klt_feature_trackerurl = https://gitee.com/robin_shaun/klt_feature_tracker
git submodule update --init

(8)终于修改完了,可以再次运行下这句命令

cd ~/PX4_Autopilot
git submodule update --init --recursive

编译

/usr/bin/ld: 找不到 -lpthreads

这个我一开始按照网上下载apt-file,update,最后apt-file search pthread根本没用,还有apt-get install libxxx.dev也没用,我的解决办法如下

点击查看代码
#找到thread.so的动态库位置
vinson@vinson-XPS-8940:~/PX4_Firmware$ ldconfig -p|grep pthread
	libpthread.so.0 (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib/x86_64-linux-gnu/libpthread.so.0
	libpthread.so.0 (libc6, OS ABI: Linux 3.2.0) => /lib/i386-linux-gnu/libpthread.so.0
	libpthread.so.0 (libc6, OS ABI: Linux 3.2.0) => /lib32/libpthread.so.0

sudo cp /lib/x86_64-linux-gnu/libpthread.so.0 /usr/lib
这样操作之后还是不太行,但出现了新问题

image
在如下的文件进行修改,在文件在Tools/sitl_gazebo/下

image
然后make px4_sitl_default gazebo成功(如果怕之前编译过影响后面结果可以先make clean)
总之过程艰难曲折,希望大家都能顺利装好!

参考博客:
https://www.ngui.cc/article/show-456981.html
https://blog.csdn.net/weixin_42319496/article/details/119371292
https://blog.csdn.net/qq_42412225/article/details/123582777

posted @ 2023-02-23 20:28  December钟  阅读(486)  评论(0编辑  收藏  举报