px4源码编译指南

px4源码编译指南

强烈推荐大家去看官网的英文文档,国内的博客杂七杂八,官网的中文也很久没有更新,这几天自己踩了很多坑,写个教程希望能帮助到大家(本文选用平台是pixhawk1)

1. 安装ubuntu16.04

18.04版本似乎是没有适配的工具链,编译的时候莫名其妙会报错,所以直接安装16的版本
百度云:(链接: https://pan.baidu.com/s/1UdM1FKp58kmmOw0YkasxKQ 提取码: wgqq )

2. 换源

ubuntu默认是欧洲的源,速度慢的惊人,推荐换成阿里的镜像

1)先备份一下

cp /etc/apt/sources.list /etc/apt/sources.list_bak

2)编辑sources.list

sudo gedit /etc/apt/sources.list

3)将所有内容替换成以下代码

#deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

4)最后记得更新

sudo apt-get update

参考:https://www.cnblogs.com/mufire/p/6433757.html

3. 编译环境搭建

1)

 sudo usermod -a -G dialout $USER

2)注销账户后再登录一次
3)下载工具链配置脚本并安装

 wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_nuttx.sh
 source ubuntu_sim_nuttx.sh

4)重启一次系统

4. 安装仿真器

 wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_common_deps.sh
 source ubuntu_sim_common_deps.sh

5. 编译源码(基于pixhawk1)

1)下载源文件

git clone https://github.com/PX4/Firmware.git

2)编译仿真器(在虚拟机上会失效,只能实际装一个系统,不过不影响编译源码,只是不能模拟了)

make px4_sitl jmavsim

3)编译

make make px4_fmu-v2_default

如果出现类似下面的句子,说明编译成功

[954/954] Creating /home/youruser/src/Firmware/build/px4_fmu-v2_default/px4_fmu-v2_default.px4

4)编译好后上传

make make px4_fmu-v2_default upload

出现下面这种应该就成功了,和官网上的样式不太一样

Erase : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting. Elapsed Time 44.948

6. 配置IDE

官方推荐的IDE是QT,刚才的脚本已经下载了qtcreator
QT配置可以参考:https://blog.csdn.net/pix_csdn/article/details/81913610

ps:其他型号开发板的构建参数

  • Pixhawk 4: make px4_fmu-v5_default
  • Pixracer: make px4_fmu-v4_default
  • Pixhawk 3 Pro: make px4_fmu-v4pro_default
  • Pixhawk Mini: make px4_fmu-v3_default
  • Pixhawk 2: make px4_fmu-v3_default
  • mRo Pixhawk: make px4_fmu-v3_default (supports 2MB Flash)
  • HKPilot32: make px4_fmu-v2_default
  • Pixfalcon: make px4_fmu-v2_default
  • Dropix: make px4_fmu-v2_default
  • MindPX/MindRacer: make airmind_mindpx-v2_default
  • mRo X-2.1: make auav_x21_default
  • Crazyflie 2.0: make bitcraze_crazyflie_default
  • Intel® Aero Ready to Fly Drone: make intel_aerofc-v1_default
  • Pixhawk 1: make px4_fmu-v2_default
  • Pixhawk 1 with 2 MB flash: make px4_fmu-v3_default

你可能感兴趣的:(PX4)