官网英文原文地址:http://dev.px4.io/starting-building.html
PX4可以在控制台或者图形界面/IDE开发
在去到图形界面或者IDE前,验证系统设置的正确性非常重要,因此打开控制台。在 OS X, 敲击 ⌘-space ,并搜索'terminal'。在Ubuntu,单击启动栏,搜索“terminal”(或者trl+alt+T)。在windows平台,在开始菜菜单找到px4文件夹,单击'PX4 Console'
终端在Home目录启动,我们默认去到'~/src/Firmware' 然后,克隆顶层资源库。有经验的开发者可以克隆自己的复制的资源库
mkdir -p ~/src
cd ~/src
git clone https://github.com/PX4/Firmware.git
cd Firmware
git submodule update --init --recursive
cd ..
上述命令结束以后,还不能直接对源代码进行编译,直接编译可能会出现内存溢出的错误error:ld returned 1 exit status
,原因是arm-none-eabi 4.7.4版本不对,直接编译失败的结果显示如下。
collect2.exe:error:ld returned 1 exit status
make[3]: *** [src/firmware/nuttx/firmware_muttx] Error 1
make[2]: *** [src/firmware/nuttx/CMakeFiles/firmware_muttx.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [px4fmu-v2_default] Error 2
这个问题可以通过下载4.8.4版本,进行解压后复制并替换掉PX4 Toolchain安装目录下Toolchain文件夹内的相应文件即可。 在直接使用硬件前,推荐先进行仿真。喜欢在图形界面开发环境工作的用户也应该继续完成下面部分。
###基于NuttX / Pixhawk的硬件板
cd Firmware
make px4fmu-v2_default
注意到“make”是一个字符命令编译工具,“px4fmu-v2”是硬件/ardupilot版本,“default”是默认配置,所有的PX4编译目标遵循这个规则。
成功编译的最后输出是这样的:
[100%] Linking CXX executable firmware_nuttx
[100%] Built target firmware_nuttx
Scanning dependencies of target build_firmware_px4fmu-v2
[100%] Generating nuttx-px4fmu-v2-default.px4
[100%] Built target build_firmware_px4fmu-v2
通过在命令后面添加‘upload’,编译的二进制程序就会通过USB上传到飞控硬件:
make px4fmu-v2_default upload
上传成功时输出情况如下:
Erase : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.
[100%] Built target upload
The command below builds the target for Raspbian (posix_pi2_release).
cd Firmware
make posix_rpi2_release # for cross-compiler build
The "mainapp" executable file is in the directory build_posix_rpi2_release/src/firmware/posix. Copy it over to the RPi (replace YOUR_PI with the IP or hostname of your RPi, instructions how to access your RPi)
scp build_posix_rpi2_release/src/firmware/posix/mainapp pi@YOUR_PI:/home/pi/
And run it with :
./mainapp
If you're building directly on the Pi, you will want the native build target (posix_pi2_default).
cd Firmware
make posix_rpi2_default # for native build
The "mainapp" executable file is in the directory build_posix_rpi2_default/src/firmware/posix. Run it directly with :
./build_posix_rpi2_default/src/firmware/posix/mainapp
A successful build followed by executing mainapp will give you this :
[init] shell id: 1996021760
[init] task name: mainapp
______ __ __ ___
| ___ \ \ \ / / / |
| |_/ / \ V / / /| |
| __/ / \ / /_| |
| | / /^\ \ \___ |
\_| \/ \/ |_/
Ready to fly.
pxh>
The commands below build the targets for the Linux and the DSP side. Both executables communicate via muORB.
cd Firmware
make eagle_default
To load the SW on the device, connect via USB cable and make sure the device is booted. Run this in a new terminal window:
adb shell
Go back to previous terminal and upload:
make eagle_default upload
Note that this will also copy (and overwrite) the two config files mainapp.config and px4.config to the device. Those files are stored under /usr/share/data/adsp/px4.config and /home/linaro/mainapp.config respectively if you want to edit the startup scripts directly on your vehicle.
The mixer currently needs to be copied manually:
adb push ROMFS/px4fmu_common/mixers/quad_x.main.mix /usr/share/data/adsp
Run the DSP debug monitor:
${HEXAGON_SDK_ROOT}/tools/mini-dm/Linux_Debug/mini-dm
Go back to ADB shell and run mainapp:
cd /home/linaro
./mainapp mainapp.config
Note that the mainapp will stop as soon as you disconnect the USB cable (or if you ssh session is disconnected). To fly, you should make the mainapp auto-start after boot.
To run the mainapp as soon as the Snapdragon has booted, you can add the startup to rc.local
:
Either edit the file /etc/rc.local
directly on the Snapdragon:
adb shell
vim /etc/rc.local
Or copy the file to your computer, edit it locally, and copy it back:
adb pull /etc/rc.local
gedit rc.local
adb push rc.local /etc/rc.local
For the auto-start, add the following line before exit 0
:
(cd /home/linaro && ./mainapp mainapp.config > mainapp.log)
exit 0
Make sure that the rc.local
is executable:
adb shell
chmod +x /etc/rc.local
Then reboot the Snapdragon:
adb reboot
##图形IDE界面下编译 PX4 支持Qt Creator, Eclipse 和Sublime Text三种集成式开发环境。 Qt Creator是最友好的开发环境,所以被是唯一官方支持的IDE。除非资深的Eclipse 或Sublime开发者,否则一般不推荐使用Eclipse或Sublime进行二次开发。硬件底层开发可以在 Eclipse project 和 a Sublime project 找到源码。
{% raw %}