Ubuntu下编译 ArduCopter

来源:互联网 发布:cnstorm知乎 编辑:程序博客网 时间:2024/06/07 05:09



解决方法:


Pixhawk官方于15年10月在GIT上更新了其固件编译方式,由make方式变成了cmake方式,但是官网上的相关说明并没有更新,这给广大开发者带来了一定困难,经各种看文档,查资料,成功实现了在cmake下的编译与下载,现将步骤说明如下:

  1. 下载并安装PX4工具链px4_toolchain_installer_v14_win.exe;
  2. 运行开始菜单工具链文件夹下的Px4 Software Download下载固件相关代码好配置;
  3. 安装JAVA环境(如果是64位系统需要在C:\px4\eclipse下修改eclipse.ini设置jre路径为x86目录);
  4. 安装cmake编译工具https://cmake.org
  5. 运行px4 console
  6. 依次运行
    [html] view plain copy print?
    1. <pre name="code" class="plain">cd Firmware  
    2. git checkout master  
    3. git reset --hard  
    4. git pull  
    5. make clean  
    6. make  
    7. make px4fmu-v2_default upload  

如果需要在eclipse下编译,需要以下步骤:

  1. 首先打开workspace,选择c/c++界面,右键打开工程,选择现有工程,选择目录C:\px4\Firmware目录,下方选择GCC编译,完成;
  2. 右侧现在make target,选择到工程名,新建px4clean、px4-v2、px4-v2_upload 四个make选项;
  3. 直接编译会存在错误,需要进行以下操作,在左边工程上右击选择Project Properties > C/C++ Build > Tool Chain Editor, 设置Current toolchain : Linux GCC, 设置Current builder : GNU Make Builder。然后选择 C/C++ Build > Environment, 改变 CWD and PWD vales 到不使用 : 比如/C/px4/Firmware。
  4. 然后双击all编译,px4fmu-v2_upload upload下载,下载是要按复位后才能开始,也可以断电再连接。

Ubuntu下编译 ardupilot

根据官方文档 http://dev.ardupilot.com/wiki/building-the-code-onlinux/

先安装git ,  而后用 git clone下载源文件

1)下载源代码

sudo apt-get -qq -y install git git clone https://github.com/diydrones/ardupilot.git

(如果不想clone整个库,到https://github.com/openpilot/OpenPilot下载zip文件有问题,因为编译过程中会调git命令取文件取不到,因为没有git库)

2) 而后安装toolchain (如:arduino-core,  gcc-avr avrdude avr-libc binutils-avr 等)

最简单就是运行下面脚本(提示不多,可能等很长时间)

ardupilot/Tools/scripts/install-prereqs-ubuntu.sh -y

不运行这个脚本,就要手动运行下面命令

sudo apt-get install gcc-avr avrdude avr-libc binutils-avr

sudo apt-get install Python-serial python-wxgtk2.8 python-matplotlib python-opencv python-pexpect python-scipy sudo apt-get gawk make git arduino-core g++ pixhawk 需要下载 arm toolchain

在ubuntu14.04不要用sudo apt-get install gcc-arm-none-eabi -y, 不但安装了错误的版本,而且缺少 c++ header

而应该运行 http://dev.px4.io/starting-installing-linux-boutique.html 提示的脚本(用wget 下载,再安装)

3)编译

使当前shell 环境变量生效

. ~/.profile

编译多轴cd ardupilot/ArduCopter make 

根据提示选择target

 Targets  -------

  px4-v1 - the PX4v1 board   px4-v2 - the Pixhawk   pxf - the Beagle Bone Black (BBB) + PXF cape combination   navio - the RaspberryPi + NavIO cape combination   linux - a generic Linux build   flymaple - the FlyMaple board

...

新版本的ArduCopter(3.x) 不支持缺省参数,而且取消了 apm1/apm2, 添加了树莓派的支持

比如编译 pixhawk 

make px4-v2

ArduPlane  APMrover2 AntennaTracker 与此类似

最后看到下面提示,就成功编译生成文件

LINK:    /home/payne/ardupilot/ardupilot/modules/PX4Firmware/Build/px4fmu-v2_APM.build/firmware.elf

BIN:     /home/payne/ardupilot/ardupilot/modules/PX4Firmware/Build/px4fmu-v2_APM.build/firmware.bin %% Generating /home/payne/ardupilot/ardupilot/modules/PX4Firmware/Build/px4fmu-v2_APM.build/firmware.px4 make[2]: Leaving directory `/home/payne/ardupilot/ardupilot/modules/PX4Firmware/Build/px4fmu-v2_APM.build' %% Copying /home/payne/ardupilot/ardupilot/modules/PX4Firmware/Images/px4fmu-v2_APM.px4 make[1]: Leaving directory `/home/payne/ardupilot/ardupilot'    text    data     bss     dec     hex filename  901640    2812   62352  966804   ec094 /home/payne/ardupilot/ardupilot/modules/PX4Firmware/Build/px4fmu-v2_APM.build/firmware.elf PX4 ArduCopter Firmware is in ArduCopter-v2.px4

最后用 make px4-v2-upload 上传

其他问题:

我想到ArduPlane去编apm2 ( Copter取消了对apm2的支持,Plane应该没有取消吧)

但提示

ArduPlane$ make apm2 ../mk/targets.mk:13: *** apm2 is deprecated on master branch; use master-AVR

那么就先运行

git checkout master-AVR

再编就可以了

make apm2

得到

%% ArduPlane.elf Firmware is in ArduPlane.elf %% ArduPlane.eep %% ArduPlane.hex

cleanflight 基于baseflight, 是支持多悬翼和固定翼飞控程序

MultiWii 的代码违反很多软件工程原则,baseflight 也是,而cleanfligh 力图改善软件质量,提高可维护性。包括

1)通过完善的测试实现更可靠的code,  2)更好的可维护性

3)更容易加入新特性

4)软件模块化更好,更易复用

cleanflight 支持Naze, CC3D 等,下面介绍 Ubuntu下如何编译

详细见:https://github.com/cleanflight/cleanflight/blob/master/docs/development/Building%20in%20Ubuntu.md

1)安装git 和toolchain

 编译 ardupilot 已经介绍过了,在 http://blog.csdn.net/span76/article/details/49782015

2)下载源代码

git clone https://github.com/cleanflight/cleanflight.git

3)编译

cd cleanflight

make TARGET=NAZE

大概1分钟,就得到了 cleanflight_NAZE.hex, 把这个 firmware上传到nave就可以用了

arm-none-eabi-size ./obj/main/cleanflight_NAZE.elf     text    data     bss     dec     hex filename  121156     208   14120  135484   2113c ./obj/main/cleanflight_NAZE.elf

arm-none-eabi-objcopy -O ihex --set-start 0x8000000 obj/main/cleanflight_NAZE.elf obj/cleanflight_NAZE.hex

同理,用

make TARGET=CC3D

得到 cleanflight_CC3D.hex

arm-none-eabi-size ./obj/main/cleanflight_CC3D.elf     text    data     bss     dec     hex filename  123180     376   13104  136660   215d4 ./obj/main/cleanflight_CC3D.elf arm-none-eabi-objcopy -O ihex --set-start 0x8000000 obj/main/cleanflight_CC3D.elf obj/cleanflight_CC3D.hex

目前支持的TARGET( 也就是支持的飞控板了) 如下

ALIENWIIF1 ALIENWIIF3 CC3D CHEBUZZF3 CJMCU COLIBRI_RACE EUSTM32F103RC MOTOLAB NAZE NAZE32PRO OLIMEXINO PORT103R RMDO SPARKY SPRACINGF3 STM32F3DISCOVERY

Ubuntu下编译Openpilot

Openpilot  是CC3D 原生固件,下面实践如何编译生成

1)首先准备 git  和arm toolchain, 参照"Ubuntu下编译 ardupilot" http://blog.csdn.net/span76/article/details/49782015

2)下载openpilot源代码

git clone https://github.com/openpilot/OpenPilot.git

3)准备qt

如果你按照官方文档(https://github.com/openpilot/OpenPilot),使用下面的命令可能等很长时间,也编译得到自己不想要的东西

make all_sdk_installmake all


我实践用的下面的步骤

sudo apt-get install p7zip-full 
make qt_sdk_install   

因为qt_sdk 500+M,所以还是很花时间


之后运行 ( fw mean firmware) 

make all_fw   


 就得到所以的fw

./build/fw_gpsplatinum/fw_gpsplatinum.elf
./build/fw_simposix/fw_simposix.elf
./build/fw_osd/fw_osd.elf
./build/fw_oplinkmini/fw_oplinkmini.elf
./build/fw_revoproto/fw_revoproto.elf
./build/fw_revolution/fw_revolution.elf
./build/fw_discoveryf4bare/fw_discoveryf4bare.elf
./build/fw_coptercontrol/fw_coptercontrol.elf


如果你不明白 make 后面可以跟那些命令

直接输出 make 回车,会有提示

首次运行gtest

看到 cleanfight 下面有 test/unit, 估计是做单元测试用的

一个make (Ubuntu下面) 都编译了,再到 cleanflight/obj/test 生成了很多可执行文件

原来 cleanflight的单元测试不是是stm32上跑了,而是在pc上跑,主要测试函数的功能


找个源元件,原来是用gtest写的,下面就在 cleanflight目录下做 gtest的试验

1)编写一个文件叫 1.c

=======  1.c ============

[html] view plain copy print?
  1. #include "gtest/gtest.h"  
  2.   
  3.   
  4. TEST (SquareRootTest, PositiveNos) {   
  5.     EXPECT_EQ (18.0, 18.0);  
  6. }  
  7.   
  8.   
  9. int main(int argc, char **argv) {  
  10.   ::testing::InitGoogleTest(&argc, argv);  
  11.   return RUN_ALL_TESTS();  
  12. }  


2) 用下面的命令编译,得到可执行文件 1
g++ -isystem  ./lib/test/gtest/inc 1.c ./obj/test/gtest-all.o -o 1 -lpthread 


3)运行得到结果

$ ./1 


[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SquareRootTest
[ RUN      ] SquareRootTest.PositiveNos
[       OK ] SquareRootTest.PositiveNos (0 ms)
[----------] 1 test from SquareRootTest (0 ms total)


[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.



0 0
原创粉丝点击