本文假设已经把linux下该安装的环境都安装好了,如果是全新的ubuntu系统则需要配置很多依赖包,可以参考大神博客,接下来按部就班进行PX4固件1.9.0版本的编译。
首先git最新的1.9.0固件:
mkdir -p ~/src
cd ~/src
git clone https://github.com/PX4/Firmware.git
然后进行初始化:
cd Firmware
git submodule update --init --recursive
最后进行编译:
make px4fmu-v2_default
前两步,只要网络好基本都没有问题,问题最多的是第三步编译,出现的第一个问题:
/CMakeFiles/modules__dataman.dir/dataman.cpp.obj.d -o src/modules/dataman/CMakeFiles/modules__dataman.dir/dataman.cpp.obj -c ../../src/modules/dataman/dataman.cpp
In file included from ../../src/platforms/px4_module.h:44:0,
from ../../src/modules/dataman/dataman.cpp:46:
../../src/platforms/px4_atomic.h: In instantiation of 'class px4::atomic':
../../src/platforms/px4_module.h:421:42: required from here
../../src/platforms/px4_atomic.h:72:2: error: non-constant condition for static assertion
static_assert(__atomic_always_lock_free(sizeof(T),(char*) 0), "atomic is not lock-free for the given type T");
^
compilation terminated due to -Wfatal-errors.
ninja: build stopped: subcommand failed.
Makefile:190: recipe for target 'intel_aerofc-v1_default' failed
make: *** [intel_aerofc-v1_default] Error 1
出现这个问题的原因,根据github上的解释是gcc-arm-none-eabi版本太老了,通过查看,果然是4.9版本(以前1.8.0版本没有出现这种情况,估计是1.9.0版本要求新版本):
arm-none-eabi-gcc --version
没办法,只能安装新版本的gcc-arm-none-eabi,首先下载新版本,然后对新版本解压和安装:
#卸载旧版的gcc-arm-none-eabi
sudo apt-get remove gcc-arm-none-eabi
#安装下载好的gcc-arm-none-eabi(在官网上下载的tar包)
#解压
tar -jxf gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2
#将解压好的文件夹移动到/opt目录下,其实不是必须放到/opt下的
sudo mv gcc-arm-none-eabi-7-2018-q2-update /opt
#打开vi ~/.bashrc 在最后一行加上路径
export PATH=/opt/gcc-arm-none-eabi-7-2018q2/bin:\$PATH
source ~/.bashrc
#在/usr/bin下面建立gcc和g++的符号链接symlink
sudo ln -s /opt/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc /usr/bin/arm-none-eabi-gcc
sudo ln -s /opt/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-g++ /usr/bin/arm-none-eabi-g++
还可以用命令行下载安装gcc-arm-none-eabi,可以参考这个博主。用命令行就直接默认安装目录为/usr/bin,所以就不用建立符号链接了。整体来说,PX4的新固件(1.9.0)比以前编译更简单了,就遇到这一个问题,以前的版本真是问题百出!!