PX4-V1.14开发笔记(1):下载px4代码

由于PX4-Autopilot托管在github,在国内下载可能遇到各种网络问题导致无法下载。为了提高下载速度,我们将PX4在github上的仓库以及其子仓库(依赖仓库)都搬移到gitee上了。

我们在gitee上创建了一个组织 px4-autopilot_v1-14做为镜像,一定能确保快速、稳定的下载。

这里我们详细说明下如何下载代码。

下载主仓库

我们在gitee上建立了PX4-Autopilot的镜像仓库。

git clone https://gitee.com/px4-autopilot_v1-14/PX4-Autopilot.git

下载完成后检出v1.14.3标签。

git checkout v1.14.3

下载子模块

通过修改.gitmodules的方式

一级子模块仓库

更换PX4-Autopilot/.gitmodules文件的内容,用如下替代:

[submodule "src/modules/mavlink/mavlink"]
    path = src/modules/mavlink/mavlink
    url = https://gitee.com/px4-autopilot_v1-14/mavlink.git
    branch = master
[submodule "src/drivers/uavcan/libuavcan"]
    path = src/drivers/uavcan/libuavcan
    url = https://gitee.com/px4-autopilot_v1-14/libuavcan.git
    branch = main
[submodule "Tools/simulation/jmavsim/jMAVSim"]
    path = Tools/simulation/jmavsim/jMAVSim
    url = https://gitee.com/px4-autopilot_v1-14/jMAVSim.git
    branch = main
[submodule "Tools/simulation/gazebo-classic/sitl_gazebo-classic"]
    path = Tools/simulation/gazebo-classic/sitl_gazebo-classic
    url = https://gitee.com/px4-autopilot_v1-14/PX4-SITL_gazebo-classic.git
    branch = main
[submodule "src/drivers/gps/devices"]
    path = src/drivers/gps/devices
    url = https://gitee.com/px4-autopilot_v1-14/PX4-GPSDrivers.git
    branch = main
[submodule "platforms/nuttx/NuttX/nuttx"]
    path = platforms/nuttx/NuttX/nuttx
    url = https://gitee.com/px4-autopilot_v1-14/NuttX.git
    branch = px4_firmware_nuttx-10.3.0+-v1.14
[submodule "platforms/nuttx/NuttX/apps"]
    path = platforms/nuttx/NuttX/apps
    url = https://gitee.com/px4-autopilot_v1-14/NuttX-apps.git
    branch = px4_firmware_nuttx-10.3.0+
[submodule "Tools/flightgear_bridge"]
    path = Tools/simulation/flightgear/flightgear_bridge
    url = https://gitee.com/px4-autopilot_v1-14/PX4-FlightGear-Bridge.git
[submodule "Tools/simulation/jsbsim/jsbsim_bridge"]
    path = Tools/simulation/jsbsim/jsbsim_bridge
    url = https://gitee.com/px4-autopilot_v1-14/px4-jsbsim-bridge.git
[submodule "src/drivers/cyphal/libcanard"]
    path = src/drivers/cyphal/libcanard
    url = https://github.com/opencyphal/libcanard.git

[submodule "src/drivers/cyphal/public_regulated_data_types"]
    path = src/drivers/cyphal/public_regulated_data_types
    url = https://gitee.com/px4-autopilot_v1-14/public_regulated_data_types.git
[submodule "src/drivers/cyphal/legacy_data_types"]
    path = src/drivers/cyphal/legacy_data_types
    url = https://gitee.com/px4-autopilot_v1-14/PX4-public_regulated_data_types.git
    branch = legacy

[submodule "src/lib/crypto/monocypher"]
    path = src/lib/crypto/monocypher
    url = https://gitee.com/px4-autopilot_v1-14/Monocypher.git
    branch = px4
[submodule "src/lib/events/libevents"]
    path = src/lib/events/libevents
    url = https://gitee.com/px4-autopilot_v1-14/libevents.git
    branch = main
[submodule "src/lib/crypto/libtomcrypt"]
    path = src/lib/crypto/libtomcrypt
    url = https://gitee.com/px4-autopilot_v1-14/libtomcrypt.git
    branch = px4
[submodule "src/lib/crypto/libtommath"]
    path = src/lib/crypto/libtommath
    url = https://gitee.com/px4-autopilot_v1-14/libtommath.git
    branch = px4
[submodule "src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client"]
    path = src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client
    url = https://gitee.com/px4-autopilot_v1-14/Micro-XRCE-DDS-Client.git
    branch = px4

 这里我们对.gitmodules文件进行下说明。

[submodule "src/modules/mavlink/mavlink"]
path = src/modules/mavlink/mavlink
url = https://gitee.com/px4-autopilot_v1-14/mavlink.git branch = master
  • path:相对当前.gitmodules的路径,也就是仓库下载后保存的路径;
  • url:仓库地址,这里我们统一修改为gitee上的镜像地址;
  • branch:分支,下载后自动检出;

同步子模块仓库地址

git submodule sync --recursive

更新(下载)子模块

git submodule update --init --recursive

二级子模块仓库

在下载完子仓库后,会继续下载子仓库的依赖仓库,这时会遇到例如flightgear的依赖仓库无法下载的问题,同样对仓库路径进行修改即可。

修改flightgear_bridge相关仓库地址

更换Tools\simulation\flightgear\flightgear_bridge\.gitmodules文件的内容,用如下替代:

[submodule "models/FlightGear-Rascal"]
    path = models/Rascal
    url = https://gitee.com/px4-autopilot_v1-14/FlightGear-Rascal.git
[submodule "models/FlightGear-TF-G1"]
    path = models/TF-G1
    url = https://gitee.com/px4-autopilot_v1-14/FlightGear-TF-G1.git
[submodule "models/FlightGear-TF-R1"]
    path = models/TF-R1
    url = https://gitee.com/px4-autopilot_v1-14/FlightGear-TF-R1.git
[submodule "models/FlightGear-TF-G2"]
    path = models/TF-G2
    url = https://gitee.com/px4-autopilot_v1-14/FlightGear-TF-G2.git

重新运行

git submodule sync --recursive
git submodule update --init --recursive

如果一些子仓库没有下载,可以手动下载然后拷贝:

# 下载
git clone https://gitee.com/px4-autopilot_v1-14/FlightGear-TF-G1.git    
git clone https://gitee.com/px4-autopilot_v1-14/FlightGear-Rascal.git    
# 拷贝
cp -r .\FlightGear-TF-G1\* E:\A-respository\D-px4\PX4-Autopilot\Tools\simulation\flightgear\flightgear_bridge\models\TF-G1
cp -r .\FlightGear-Rascal\* E:\A-respository\D-px4\PX4-Autopilot\Tools\simulation\flightgear\flightgear_bridge\models\Rascal
修改libevents相关仓库地址

紧接着再修改src\lib\events\libevents\.gitmodules文件的内容,用如下替代:

[submodule "libs/cpp/parse/nlohmann_json"]
    path = libs/cpp/parse/nlohmann_json
    url = https://gitee.com/px4-autopilot_v1-14/nlohmann_json.git

如果出现以下问题: 

fatal: could not get a repository handle for submodule 'libs/cpp/parse/nlohmann_json'

可以先下载: 

git clone https://gitee.com/px4-autopilot_v1-14/nlohmann_json.git

然后拷贝至指定目录:

cp -r nlohmann_json/* E:\A-respository\D-px4\PX4-Autopilot\src\lib\events\libevents\libs\cpp\parse\nlohmann_json 

修改mavlink相关仓库地址

紧接着再修改src\modules\mavlink\mavlink\.gitmodules文件的内容,用如下替代:

[submodule "pymavlink"]
    path = pymavlink
    url = https://gitee.com/px4-autopilot_v1-14/pymavlink.git
修改eProsima相关仓库地址

修改PX4-Autopilot/src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client/cmake/SuperBuild.cmake文件的内容,用如下代替

#https://github.com/eProsima/Micro-CDR.git
#替换为:
https://gitee.com/px4-autopilot_v1-14/Micro-CDR.git

# https://github.com/google/googletest.git
# 替换为
https://gitee.com/px4-autopilot_v1-14/googletest.git

通过仓库地址替换方式(简单)

我们已经将所有子仓库都放到了gitee,那么可以在命令行中使用git的insteadOf命令将github仓库路径替换为gitee镜像地址,这样就不用去修改文件了。

进入PX4-Autopilot路径后,将其子仓库的github地址替换为gitee地址即可,例如:

git config --global url."https://github.com/mavlink/mavlink.git".insteadOf https://gitee.com/px4-autopilot_v1-14/m

 关于NextPilot飞控

NextPilot飞控系统是一款基于px4和rt-thread的国产开源自动驾驶仪,由NextPilot开发团队(nextpilot@qq.com)负责维护。它能够便捷的应用于教育、研究和工业等领域,让工程师专注于自己的擅长领域(比如嵌入式、控制算法、应用业务)进行高效的开发。

 

<think>我们参考用户的问题:用户想下载PX4源码,并询问正确的方法。 根据引用[2]中的内容,我们得知在下载PX4源码时需要注意权限问题,不要使用root权限下载,否则会导致后续编译出现权限问题。 因此,正确的步骤应该是: 1. 使用普通用户(非root)进行操作。 2. 按照PX4官方文档的推荐方式下载源码。 具体步骤: 步骤1:安装必要的工具 步骤2:创建并进入一个工作目录(例如:~/px4) 步骤3:使用git克隆PX4 Firmware仓库(注意:不要使用sudo) 详细步骤: 1. 安装git(如果未安装): 在Ubuntu/Debian系统上: ```bash sudo apt update sudo apt install git -y ``` 2. 创建工作目录并克隆仓库: ```bash mkdir -p ~/px4 cd ~/px4 git clone https://github.com/PX4/PX4-Autopilot.git --recursive ``` 3. 进入仓库目录并初始化子模块(如果克隆时已经使用了--recursive,则此步骤可省略,但为了保险可以再运行): ```bash cd PX4-Autopilot git submodule update --init --recursive ``` 4. 注意:整个过程中不要使用sudo命令,确保所有文件都属于当前用户。 引用[2]中特别强调:永远不要使用sudo来修复权限问题,否则会带来更多的权限问题,需要重装系统来解决。 因此,我们应避免使用root权限下载和操作源码。 另外,根据PX4官方文档(https://docs.px4.io/main/en/dev_setup/building_px4.html ),还需要安装一些依赖,但用户的问题只是下载源码,所以先完成下载步骤。 如果用户后续需要编译,再按照官方文档安装依赖和进行编译。 总结:使用普通用户身份,通过git克隆官方仓库,并递归初始化子模块。 注意:如果网络问题导致子模块下载失败,可以尝试多次运行`git submodule update --init --recursive`。 相关问题: 1. 如何安装PX4编译所需的依赖? 2. 如何编译PX4固件? 3. 如何解决PX4源码下载过程中的子模块下载失败问题? 4. 如何更新PX4源码到最新版本? 5. 如何切换到特定的PX4版本(如发布版本)? 注意:在回答中,我们引用了引用[2]的内容,因此需要添加引用标记[^2]。</think>### 正确下载PX4源码的步骤 #### 1. **准备工作环境** - 确保使用普通用户操作,**切勿使用root权限**(避免权限问题导致后续编译失败)[^2] - 安装必要工具: ```bash sudo apt update sudo apt install git python3-pip -y ``` #### 2. **创建工作目录** ```bash mkdir -p ~/px4_workspace # 创建专用目录 cd ~/px4_workspace ``` #### 3. **克隆源码仓库** ```bash git clone https://github.com/PX4/PX4-Autopilot.git --recursive ``` - `--recursive` 参数确保所有子模块同步下载 - 若网络问题导致失败,可尝试: ```bash git clone https://gitee.com/mirrors/PX4-Autopilot.git --recursive # 国内镜像 ``` #### 4. **初始化子模块** ```bash cd PX4-Autopilot git submodule update --init --recursive ``` #### 5. **验证下载完整性** ```bash make list_config_targets # 查看支持的构建目标 ``` 正常输出应显示类似: ``` Available configuration targets: aerofc-v1_default aeroscout-v1_default ... ``` #### 6. **设置环境权限** ```bash sudo usermod -a -G dialout $USER # 添加串口访问权限 sudo apt remove modemmanager -y # 移除冲突服务 sudo reboot # 重启生效 ``` #### ⚠️ 关键注意事项 1. **权限管理**: - 所有操作在普通用户下完成 - 若误用`sudo`下载,需彻底删除后重下: ```bash sudo rm -rf ~/px4_workspace ``` [权限问题会导致编译失败[^2]] 2. **网络问题处理**: - 子模块下载失败时,手动更新: ```bash git submodule foreach git pull origin main ``` 3. **版本选择**: ```bash git tag -l # 查看可用版本 git checkout v1.14.0 # 切换到稳定版 ``` #### 验证成功 ```bash ls Tools/flightgear_bridge # 检查子模块 ``` 应看到`CMakeLists.txt`等文件,无空目录 > **技术说明**:PX4使用`git submodule`管理依赖,包含NuttX RTOS、uORB通信等核心组件[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值