QT编译PX4源码

QT编译PX4源码

1. PX4源码下载

cd ~
mkdir src
cd src
git clone https://github.com/PX4/Firmware.git #官方克隆代码(速度比较慢),可以克隆到自己的码云仓库,git clone https://gitee.com/yaomagic/Firmware.git,子模块下载还是很慢
git tag -l #列出所有分支
git checkout -b tags/v1.8.0 #切换分支
#或者直接下载指定版本的源码
git clone -b v1.8.0 https://github.com/PX4/Firmware.git

2. QT安装

  1. 下载离线安装包

    https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/qt/

  2. 直接运行.run文件

3. 创建工程文件

​ 参考官方网站,创建Qt工程文件

​ https://dev.px4.io/v1.8.0/en/setup/building_px4.html

cd ~/src/Firmware
mkdir ../Firmware-build
cd ../Firmware-build
cmake ../Firmware -G "CodeBlocks - Unix Makefiles"

按照官网上面最后一行的命令,当前使用Qt编译得到的将是build px4 ,因为默认的编译指令是make posix_sitl_default,这不是大家所期待的结果。

解决方案:对于,Pixhawk硬件,将最后一行改成
cmake ../Firmware -G "CodeBlocks - Unix Makefiles" -DCONFIG=nuttx_px4fmu-v2_default

其他例如使用FMUv4的用户请根据需求进行替换。

​ 创建工程文件一般时间比较长,期间会出现一些问题,如网络问题,子模块无法克隆;编译出错等

4. 常见问题

1. 创建工程时可能遇到的问题
-- PX4 version: v1.11.0-beta2-229-g6dad4a3359
-- PX4 config file: /home/yao/PX4_src/Firmware/boards/px4/fmu-v2/default.cmake
-- PX4 config: px4_fmu-v2_default
-- PX4 platform: nuttx
-- cmake build type: MinSizeRel
-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
-- The ASM compiler identification is unknown
-- Found assembler: arm-none-eabi-gcc
CMake Error at CMakeLists.txt:202 (project):
  The CMAKE_CXX_COMPILER:

    arm-none-eabi-g++

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:202 (project):
  The CMAKE_C_COMPILER:

    arm-none-eabi-gcc

  is not a full path and was not found in the PATH.

​ 解决方法:安装交叉编译工具

sudo apt install gcc-arm-none-eabi

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-2017-q4-major-linux.tar.bz2
#将解压好的文件夹移动到/opt目录下,或者其他目录,对应的环境变量也要修改
sudo mv gcc-arm-none-eabi-7-2017-q4-major-linux /opt
#添加环境变量
vi /etc/profile
#在文件最后添加
export PATH=$PATH:/usr/lib/gcc/gcc-arm-none-eabi-7-2017-q4-major-linux/bin
#使能环境变量
source /etc/profile
#此命令只在当前终端有效,若需要在其它终端中使用,需要重启计算机。
  1. QT编译时遇到的错误-必要的工具
sudo apt-get install python3-pip  #安装pip3
pip3 install --user empy
pip3 install --user pyros-genmsg
pip3 install --user packaging
pip3 install --user jinja2
pip3 install --user toml
pip3 install --user numpy
 下载速度慢解决办法:镜像下载
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy --user

5 QT编译源码

​ 1.打开QT,点击文件-打开文件或项目…,选择src/Firmwire 下的CmakeLists.txt,点击Configure Project,等待配置文件。
QT编译PX4源码_第1张图片 2. 配置build和run,如下图。
QT编译PX4源码_第2张图片
QT编译PX4源码_第3张图片
QT编译PX4源码_第4张图片
QT编译PX4源码_第5张图片QT编译PX4源码_第6张图片
按图中配置后,点击右下角构建即可编译,点击运行可下载固件到Pixhawk飞控上
QT编译PX4源码_第7张图片

你可能感兴趣的:(无人机,飞控,PX4,linux,ubuntu)