1 介绍
本人px4小白一枚,对编程了解不是很多,本人研一,从事飞行力学与控制方向偏理论,但是导师搞px4开发方向,假期没事搭个px4开发环境,学学代码。以前从来没接触过linux系统,查了很多博文最后用vmware虚拟机装了ubuntu16.04系统。
2 必备知识
1)首先需要对linux系统有一定了解,如果你只是从各个博主上copy自己都不知道干什么,推荐大家看看linux基础知识的相关书籍,学会终端shell语句。
2)如果你是一个新的ubuntu系统,决定你git和下载东西的速度主要有两个,一个是网速,一个是软件的源,源推荐阿里云和清华,网速这个看自己的情况,git慢最好用梯子。
3 配置开发环境
3.1权限设置
sudo usermod -a -G dialout $USER
3.2安装工具链和依赖包
各个博主对此都有解释,但我总是在各个地方出错,最后还是按照官网的方法成功了。
gedit ubuntu_sim_nuttx.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 exiftool -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 pyyaml
# 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
然后在终端中运行
source ubuntu_sim_common_deps.sh
这样所有的工具就都安装完成了。
4 编译源码
4.1源码下载
mkdir -p ~/src
cd ~/src
git clone https://github.com/PX4/Firmware.git
注:这里mkdir -p ~/src是新建一个src文件夹,上面安装工具链那段代码最后的命令是跳进src/Firmware,如果提前没建立这个文件夹,最后可能会报错,但是不影响结果,源码下载和依赖包工具链的下载不分先后。
4.2 基于NuttX / Pixhawk的硬件板编译
pixhawk如下操作即可
cd Firmware
make px4fmu-v2_default
这里可以编译各个版本:
以下列表显示了常用板的构建命令:
Pixhawk 4: make px4fmu-v5_default
Pixracer:make px4fmu-v4_default
Pixhawk 3 Pro:make px4fmu-v4pro_default
Pixhawk Mini:make px4fmu-v3_default
Pixhawk 2:make px4fmu-v3_default
mRo Pixhawk:(make px4fmu-v3_default支持2MB闪存)
HKPilot32:make px4fmu-v2_default
Pixfalcon:make px4fmu-v2_default
Dropix的:make px4fmu-v2_default
MindPX / MindRacer:make mindpx-v2_default
mRo X-2.1:make auav-x21_default
Crazyflie 2.0:make crazyflie_default
英特尔®Aero准备飞无人机:make aerofc-v1_default
精灵鹰1:make px4fmu-v2_default
附:
编译成功会出现这样一个build文件夹,nuttx_px4fmu-v5_default,打开后:
这样就是编译成功了。