PX4 1.7.3 编译环境搭建(Ubuntu 16.04)

留给PX4_1.7.3固件编译环境搭不起来的人们


在网上大致搜了下,好像没有针对1.7.3固件的编译环境搭建的教程。
dev上的中文翻译已经很久没更新了,说实话可能会误导别人。
我把我自己搭建的流程简单复述一下。其实大致就是按照英文教程上的步骤来的,还有点额外的坑也写下来了。
在这里写下来,是为了方便遇到同样问题的人们,能够让大家节省点宝贵的时间,少走点弯路。
与其说原创,应该是翻译+一点点原创,不过这都无所谓啦。
昨天装了好久,终于弄好了。给我的一点教训是:别人能成功弄好,自己弄不好,一定要反思总结一下自己和别人的情况有什么不同;遇到困难,要以一种饿不死的大蠊精神来克服困难。


大致步骤:

  1. 安装 Ubuntu Linux LTS (16.04) 虚拟机
  2. 将用户添加到“dialout”组里,并注销用户,再进入
  3. 制作(或下载)脚本文件
  4. 运行脚本文件
  5. (坑中套坑)安装arm_none_eabi_gcc交叉编译工具
  6. 尝试编译PX4 1.7.3 固件

OK,那我们开始了。


Step 01 安装虚拟机(ubuntu 16.04)

首先不推荐使用Windows进行PX4开发,不过你要是大神的话就无所谓啦。
其次,建议安装虚拟机(我用的VMware),并且勤用、善用快照功能。快照功能真神器,一不小心弄错了,恢复快照就好。
再次,安装ubuntu一定要安装16.04版本。如果是14.04,你极有可能会因为编译报错:“缺少python库numpy toml”的问题而困扰(你就是装了也没用,还是会提示缺少)。所以要安装16.04版本,英文版教程也是这么说的。

安装虚拟机就非常简单了。给一下关键配置供参考哈:

  • 处理器:1个1核
  • 内存:4G(最新地面站挺耗资源的,小于4G可能会导致SWAP空间不足而编译不了地面站)
  • 硬盘:40G(别小于30G就行啦)

Step 02 将用户添加到“dialout”组里

基本操作了对吧?

sudo usermod -a -G dialout $USER

输入完密码,操作成功了之后记得log out一下来使这个操作生效。


Step 03 制作(或下载)脚本文件

20180208 我看到最新的教程上,已经提供了非常便利的脚本搭建编译环境的方法,我在这里转给大家咯:
以下是ubuntu_sim_common_deps.sh文件的内容,如果大家有什么额外的安装需求,自己去英文版的教程上找咯。

#!/bin/bash

## Bash script for setting up a PX4 development environment on Ubuntu LTS (16.04).
## It can be used for installing simulators (only) or for installing the preconditions for Snapdragon Flight or Raspberry Pi.
##
## Installs:
## - Common dependencies and tools for all targets (including: Ninja build system, Qt Creator, pyulog)
## - FastRTPS and FastCDR
## - jMAVSim simulator dependencies
## - PX4/Firmware source (to ~/src/Firmware/)

# Preventing sudo timeout https://serverfault.com/a/833888
trap "exit" INT TERM; trap "kill 0" EXIT; sudo -v || exit $?; sleep 1; while true; do sleep 60; sudo -nv; done 2>/dev/null &

# Ubuntu Config
echo "We must first remove modemmanager"
sudo apt-get remove modemmanager -y


# Common dependencies
echo "Installing common dependencies"
sudo apt-get update -y
sudo apt-get install git zip qtcreator cmake build-essential genromfs ninja-build -y
# Required python packages
sudo apt-get install python-argparse python-empy python-toml python-numpy python-dev python-pip -y
sudo -H pip install --upgrade pip
sudo -H pip install pandas jinja2 pyserial
# optional python tools
sudo -H pip install pyulog

# Install FastRTPS 1.5.0 and FastCDR-1.0.7
fastrtps_dir=$HOME/eProsima_FastRTPS-1.5.0-Linux
echo "Installing FastRTPS to: $fastrtps_dir"
if [ -d "$fastrtps_dir" ]
then
    echo " FastRTPS already installed."
else
    pushd .
    cd ~
    wget http://www.eprosima.com/index.php/component/ars/repository/eprosima-fast-rtps/eprosima-fast-rtps-1-5-0/eprosima_fastrtps-1-5-0-linux-tar-gz -O eprosima_fastrtps-1-5-0-linux.tar.gz
    tar -xzf eprosima_fastrtps-1-5-0-linux.tar.gz eProsima_FastRTPS-1.5.0-Linux/
    tar -xzf eprosima_fastrtps-1-5-0-linux.tar.gz requiredcomponents
    tar -xzf requiredcomponents/eProsima_FastCDR-1.0.7-Linux.tar.gz
    cpucores=$(( $(lscpu | grep Core.*per.*socket | awk -F: '{print $2}') * $(lscpu | grep Socket\(s\) | awk -F: '{print $2}') ))
    cd eProsima_FastCDR-1.0.7-Linux; ./configure --libdir=/usr/lib; make -j$cpucores; sudo make install
    cd ..
    cd eProsima_FastRTPS-1.5.0-Linux; ./configure --libdir=/usr/lib; make -j$cpucores; sudo make install
    cd ..
    rm -rf requiredcomponents eprosima_fastrtps-1-5-0-linux.tar.gz
    popd
fi

# jMAVSim simulator dependencies
echo "Installing jMAVSim simulator dependencies"
sudo apt-get install ant openjdk-8-jdk openjdk-8-jre -y

# Clone PX4/Firmware
clone_dir=~/src
echo "Cloning PX4 to: $clone_dir."
if [ -d "$clone_dir" ]
then
    echo " Firmware already cloned."
else
    mkdir -p $clone_dir
    cd $clone_dir
    git clone https://github.com/PX4/Firmware.git
fi

把这个脚本文件保存成.sh文件。


Step 04 运行脚本文件

在当前目录打开终端,输入:

# If you rename the .sh script as xxx.sh,
# you should change the name in the command respectively.
source ubuntu_sim_common_deps.sh

蹦出的请求都确认,等待安装结束。


Step 05 安装arm_none_eabi_gcc交叉编译工具

如果在没有单独安装交叉编译工具就make PX4项目,当然会出现CMake缺失组件啦。
只是1.7.3版本要求安装 最新版(2017q4)的交叉编译工具 哦,请注意。

错误方法:

  • 如果我们用以下命令安装:
sudo apt-get install gcc-arm-none-eabi

安装好之后你看它是不是给你安装一个4.9版本(2015年)的交叉编译工具?

  • 来看看这个网站上呢:

https://launchpad.net/gcc-arm-embedded/+download
上面提供2016年的,也不是我们需要的。

中文版教程这里还没更新呢!还是让安装4.9和5.4的工具。

于是我们这里要这么做:

在正式运行脚本前,先使用命令:

sudo apt-get install lib32ncurses5 lib32z1

保证自己不缺少32位的库文件。(我在运行下面脚本时,老是提示 bash: (……): No such file or directory 什么的,使用这个命令之后就可以安装成功啦)

制作一个含有以下代码的脚本:

pushd .
cd ~
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2
tar -jxf gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2
exportline="export PATH=$HOME/gcc-arm-none-eabi-7-2017-q4-major/bin:\$PATH"if grep -Fxq "$exportline" ~/.bash_profile; then echo nothing to do ; else echo $exportline >> ~/.profile; fipopd

在终端运行这个脚本文件,当然是用source命令啦。
安装完之后,为了以防万一,运行检查版本的命令:

arm-none-eabi-gcc --version

检查以下是不是:
(GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release)

是的话就安装好了。


Step 06 尝试编译PX4固件

最后就是基本操作了吧。我在这里之后就没遇到问题了。

参考资料主要是px4英文版的教程,自己也多去看看吧~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值