Ubuntu下PX4开发环境的搭建(适用于18.04及以上)
前言
全文参考了PX4官方文档,利用官方文档给出的脚本在ubuntu下对PX4环境进行了配置,并针对出现的问题作以说明
下面是整个配置过程,仅供参考
一、使用官方脚本进行配置
官方文档给出的步骤是首先下载PX4的源码,然后导航到源码文件夹下运行ubuntu.sh脚本文件,即可开始PX4的环境配置:
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
如果整个过程非常非常顺利,在脚本执行完成之后重启计算机,环境就配置好了。
但是通常可能不会这么顺利。
因为我一开始没有翻墙,所以没有按照官网给出的顺序来,而是先下载了ubuntu.sh和requirements.txt两个文件,并运行ubuntu.sh:
wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/master/Tools/setup/ubuntu.sh
wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/master/Tools/setup/requirements.txt
source ubuntu.sh
打开脚本可以看到运行它之后会安装PX4的常规依赖项、python3依赖、Nuttx工具链以及仿真工具及其依赖,下面针对安装过程中出现的一些问题进行说明。
二、问题说明
1.安装python3依赖项时下载速度过慢
在这一步中,下载某些包的时候下载速度极慢甚至下载失败,推荐使用清华源,可以直接修改脚本然后运行之:
将脚本中这几行:
# Python3 dependencies
echo
echo "Installing PX4 Python3 dependencies"
sudo python3 -m pip install -r ${DIR}/requirements.txt
替换成:
# Python3 dependencies
echo
echo "Installing PX4 Python3 dependencies"
sudo python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r ${DIR}/requirements.txt
然后继续运行,网上一些教程也推荐用阿里云的源,只需要替换上面的链接就好。
这一步下,如果之前requirements.txt文件没能成功下载或者没有下载,可以直接手动添加python 依赖(参考自https://blog.csdn.net/weixin_44616080/article/details/96980883?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242):
sudo apt-get install python-argparse \
python-empy python-toml python-numpy python-yaml \
python-dev python-pip -y
sudo -H pip install --upgrade pip
sudo -H pip install pandas jinja2 pyserial cerberus
2.交叉编译器下载失败
这一步里,我尝试多次,都是在下载到一半多的时候提示下载失败,核心已转储,可以直接到这个网站下面手动下载然后配置:
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
解压缩:
tar -jxf gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2
配置编译环境,将编译器的路径放到.bashrc或者.profile文件中:
export PATH=$HOME/gcc-arm-none-eabi-7-2017-q4-major/bin:\$PATH
查看编译器版本确认是否配置成功:
arm-none-eabi-gcc --version
配置成功的话会输出如下的信息:
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
上面是以2017-q4版本为例
3. PX4源码下载
这一步无论如何建议翻墙下载,国内软件源试了都不行
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
等待下载完成后,打开终端,进到px4文件夹下,对仿真环境进行测试,以检验环境配置是否正确:
make px4_sitl_default jmavsim
正确的话,界面是这样:
也可以通过编译固件来验证:
make px4_fmu-v5_default
如果编译成功,说明环境配置的没有问题。