PX4配置過程與踩坑

雲夢士發表於2022-05-31

0.前言

由於需要在GitHub下載程式碼,而國內訪問受限,可能會出現一些問題,這裡建議使用github國內映象,參看:GitHub國內映象網站,當然下面會給出具體解決方案。

1.步驟

1.1下載原始碼:git clone https://github.com/PX4/PX4-Autopilot.git

注意:
若該步驟出錯,使用映象,也就是執行:git clone https://hub.fastgit.xyz/PX4/PX4-Autopilot.git
或者使用gitee映象:git clone https://gitee.com/robin_shaun/PX4_Firmware(注意使用這個方法時的原始碼檔名是PX4_Firmware)

1.2 切換到原始碼資料夾:cd PX4-Autopilot

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

注意:
若該步驟出錯,歸根到底還是因為github訪問不穩定。解決方案如下:
(方案的總體原則就是改變原始碼裡面各個.gitmodules檔案裡的下載地址,需要注意的是原始碼位置,我這裡是將原始碼放在主資料夾下,也就是 ~/PX4_Autopilot)

(1)原始碼主資料夾下

  1. cd ~/PX4_Autopilot
  2. gedit .gitmodules
    (注意:這裡主要是為了修改檔案,我用的是gedit編輯器,也可以用vim, nano,vs code之類的,後面相同)
    將 .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
  1. git submodule update --init

(2) libuavcan資料夾

  1. cd ~/PX4_Autopilot/src/drivers/uavcan/libuavcan
  2. gedit .gitmodules
    將 .gitmodules 中的內容更換為:
[submodule "dsdl"]
	path = dsdl
	url = https://gitee.com/robin_shaun/dsdl
	branch = legacy-v0
[submodule "libuavcan/dsdl_compiler/pyuavcan"]
	path = libuavcan/dsdl_compiler/pyuavcan
	url = https://gitee.com/robin_shaun/pyuavcan
[submodule "libuavcan_drivers/kinetis"]
	path = libuavcan_drivers/kinetis
	url = https://gitee.com/robin_shaun/libuavcan_kinetis.git
  1. git submodule update --init

(3) jMAVSim資料夾

  1. cd ~/PX4_Autopilot/Tools/jMAVSim
  2. gedit .gitmodules
    將 .gitmodules 中的內容更換為:
[submodule "jMAVlib"]
	path = jMAVlib
	url = https://gitee.com/robin_shaun/jMAVlib
	branch = master
  1. git submodule update --init

(4) sitl_gazebo資料夾

  1. cd ~/PX4_Autopilot/Tools/sitl_gazebo
  2. gedit .gitmodules
    將 .gitmodules 中的內容更換為:
[submodule "external/OpticalFlow"]
	path = external/OpticalFlow
	url = https://gitee.com/robin_shaun/OpticalFlow
  1. git submodule update --init

(5) dspal資料夾

  1. cd ~/PX4_Autopilot/platforms/qurt/dspal
  2. gedit .gitmodules
    將 .gitmodules 中的內容更換為:
[submodule "cmake_hexagon"]
	path = cmake_hexagon
	url = https://gitee.com/robin_shaun/cmake_hexagon
  1. git submodule update --init

(6) pyuavcan資料夾

  1. cd ~/PX4_Autopilot/src/drivers/uavcan/libuavcan/libuavcan/dsdl_compiler/pyuavcan
  2. gedit .gitmodules
    將 .gitmodules 中的內容更換為:
[submodule "dsdl"]
	path = dsdl
	url = https://gitee.com/robin_shaun/dsdl
  1. git submodule update --init

(7) OpticalFlow資料夾

  1. cd ~/PX4_Autopilot/Tools/sitl_gazebo/external/OpticalFlow
  2. gedit .gitmodules
    將 .gitmodules 中的內容更換為:
[submodule "external/klt_feature_tracker"]
	path = external/klt_feature_tracker
	url = https://gitee.com/robin_shaun/klt_feature_tracker
  1. git submodule update --init

(8)終於修改完了,可以再次執行下這句命令

git submodule update --init

1.4 編譯

cd ~/PX4_Firmware
make px4_sitl_default gazebo

注意:
這一步可能會報錯:ninja: build stopped: subcommand failed.
image
不要慌!

  1. 先看看子模組是否更新成功。執行命令:git submodule update --init --recursive
    linux哲學,沒有訊息就是好訊息,如果沒有出現任何內容,說明子模組更新成功(看不懂什麼是子模組也沒問題,意思就是到此為止,沒問題)。
  2. 接下來清理下make環境就ok了:make clean
  3. 最後再執行一次編譯命令:make px4_sitl_default
    以下是我成功的介面
    image

2. 開啟gazebo make px4_sitl_default gazebo

注意:
如果gazebo出不來,可以這麼做:

  1. 清理一下:make distclean
  2. 重新安裝:sudo apt-get install ros-melodic-gazebo-dev
  3. 再次執行:make px4_sitl_default gazebo
    image

2. 祝你配置順利!如有問題,歡迎討論!

相關文章