Pixhawk原生固件PX4之一个脚本搞定Linux系统的环境配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/oqqENvY12/article/details/79266838

PX4官网发布了一个使用脚本配置Linux系统固件编译环境的教程,只用5步就可以完成整个PX4固件编译所需的步骤:

  1. 在终端输入以下指令将将用户添加到附属组群:

    sudo usermod -a -G dialout $USER
  2. 注销并重新登录
  3. 保存如下脚本ubuntu_sim_nuttx.sh
  4. 使脚本生效,执行指令

    source ubuntu_sim_nuttx.sh

    等脚本执行完
  5. 重启电脑

接下来就会发现在~/src目录下已经下载好了最新的PX4固件,直接就可以进行编译了。


接下来重点看看这个脚本里到底做了些什么事情

脚本1:ubuntu_sim_nuttx.sh

#!/bin/bash

## Bash script for setting up a PX4 development environment for Pixhawk/NuttX targets on Ubuntu LTS (16.04).
## It can be used for installing simulators and the NuttX toolchain.
## 
## 这是用于在Ubuntu16.04s上为Pixhawk/Nuttx设置PX4开发环境的的Bash脚本
## 它可以用于安装模拟器以及Nuttx工具链
##
## Installs:
## - Common dependencies libraries, tools, and Gazebo8 simulator as defined in `ubuntu_sim.sh`
## - NuttX toolchain (i.e. gcc compiler)
## 安装说明:
## - 一般依赖库,工具,以及Gazebo8模拟器(在脚本ubuntu_sim.sh)
## - Nuttx工具链

echo "Downloading dependent script 'ubuntu_sim.sh'"
# Source the ubuntu_sim.sh script directly from github

# 从github上下载ubuntu_sim.sh脚本并source使其立即生效
ubuntu_sim=$(wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'ubuntu_sim.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
. <(echo "${ubuntu_sim}")

# NuttX
# 下载NuttX工具链
sudo apt-get install python-serial openocd \
    flex bison libncurses5-dev autoconf texinfo \
    libftdi-dev libtool zlib1g-dev -y

# Clean up old GCC
# 清除旧的GCC编译器
sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi gcc-arm-embedded -y
sudo add-apt-repository --remove ppa:team-gcc-arm-embedded/ppa -y

# Install GCC 5.4
# 安装GCC 5.4
gcc_dir=$HOME/gcc-arm-none-eabi-5_4-2016q2
echo "Installing GCC to: $gcc_dir"
if [ -d "$gcc_dir" ]
then
    echo " GCC already installed."
else
    pushd .
    cd ~    
    wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q2/gccarmnoneeabi542016q220160622linuxtar.bz2
    tar -jxf gccarmnoneeabi542016q220160622linuxtar.bz2
    exportline="export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q2/bin:\$PATH"
    if grep -Fxq "$exportline" ~/.profile; then echo " GCC path already set." ; else echo $exportline >> ~/.profile; fi
    . ~/.profile
    popd

    # Install 32 bit support libraries (ignore if fails)
    # 安装32位支持库
    sudo dpkg --add-architecture i386
    sudo apt-get update
    sudo apt-get install libc6:i386 libgcc1:i386 libstdc++5:i386 libstdc++6:i386 -y
    sudo apt-get install gcc-5.4-base:i386 -y
fi

# Go to the firmware directory
# 进入固件目录,在其他上面的脚本中clone了PX4固件
cd $clone_dir/Firmware

# Reboot the computer (required before building)
# 提示重启电脑
echo RESTART YOUR COMPUTER to complete installation of PX4 development toolchain

脚本2:ubuntu_sim.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 libraries and tools as defined in `ubuntu_sim_common_deps.sh`
## - Gazebo8 simulator

echo "Downloading dependent script 'ubuntu_sim_common_deps.sh'"
# Source the ubuntu_sim_common_deps.sh script directly from github

# 从github上下载ubuntu_sim_common_deps.sh脚本并source使其立即生效
common_deps=$(wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_common_deps.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'ubuntu_sim_common_deps.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise, source the downloaded script.
. <(echo "${common_deps}")

# Gazebo simulator dependencies
# 安装Gazebo8模拟器
echo "Installing Gazebo8"
sudo apt-get install protobuf-compiler libeigen3-dev libopencv-dev -y
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
## Setup keys
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
## Update the debian database:
sudo apt-get update -y
## Install Gazebo8
sudo apt-get install gazebo8 -y
## For developers (who work on top of Gazebo) one extra package
sudo apt-get install libgazebo8-dev -y

# Go to the firmware directory
cd $clone_dir/Firmware

脚本3: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/)
## - FastRTPS(快速实时发布订阅)
## - FastCDR序列化机制
## - PX4源码

# 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
# 卸载Ubuntu模式管理器(DBus系统总线启动服务)
echo "We must first remove modemmanager"
sudo apt-get remove modemmanager -y


# Common dependencies
# 一般依赖
echo "Installing common dependencies"
sudo apt-get update -y
# 这里安装了一堆软件 git、zip、Qt(这个没有用)、cmake等等
sudo apt-get install git zip qtcreator cmake build-essential genromfs ninja-build -y
# Required python packages
# 必要的Python包
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
# 可选的python工具,这里的pyulog笔者认为作用不大
sudo -H pip install pyulog

# Install FastRTPS 1.5.0 and FastCDR-1.0.7
# 安装FastRTPS、FastCRD(V1.6版固件之后才有的吧,笔者没有用过)
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
# jMAMSim模拟器依赖
echo "Installing jMAVSim simulator dependencies"
sudo apt-get install ant openjdk-8-jdk openjdk-8-jre -y

# Clone PX4/Firmware
# 下载PX4固件
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

官网越来越注重开发者体验了,很棒!

猜你喜欢

转载自blog.csdn.net/oqqENvY12/article/details/79266838
今日推荐