Ubuntu下构建PX4软件

本搭建过程基于http://dev.px4.io/starting-building.html,希望大家互相交流学习。

原文:Building PX4 Software(构建PX4软件)

PX4 can be built on the console or in a graphical development environment / IDE.(PX4可以在终端被构建或者在图形开发环境/集成开发环境

Compiling on the Console(在终端编译)

Before moving on to a graphical editor or IDE, it is important to validate the system setup. Do so by bringing up the terminal. On OS X, hit ⌘-space and search for 'terminal'. On Ubuntu, click the launch bar and search for 'terminal'. On Windows, find the PX4 folder in the start menu and click on 'PX4 Console'.(在使用图形编辑器或集成开发环境前,验证系统设置是很重要的。该工作需要使用终端完成。在Ubuntu上,点击登录工具条并选择terminal,也可以快捷键Ctrl+Alt+T)。

The terminal starts in the home directory. We default to '~/src/Firmware' and clone the upstream repository. Experienced developers might clone their fork instead.(终端启动后在home路径下。我们默认到'~/src/Firmware' 路径下,并且克隆相应源码。有经验工程师可能会克隆代替

mkdir -p ~/src
cd ~/src
git clone https://github.com/PX4/Firmware.git(远程操作的第一步,通常是从远程主机克隆一个版本库,这时就要用到git clone命令。即:git clone <版本库的网址>;该命令会在本地主机生成一个目录,与远程主机的版本库同名。如果要指定不同的目录名,可以将目录名作为git clone命令的第二个参数,即git clone <版本库的网址> <本地目录名>;git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等,下面是一些例子:
$ git clone http[s]://example.com/path/to/repo.git/
$ git clone ssh://example.com/path/to/repo.git/
$ git clone git://example.com/path/to/repo.git/
$ git clone /opt/git/project.git 
$ git clone file:///opt/git/project.git
$ git clone ftp[s]://example.com/path/to/repo.git/
$ git clone rsync://example.com/path/to/repo.git/   )
cd Firmware
git submodule update --init --recursive(当使用git clone下来的工程中带有submodule时,初始的时候,submodule的内容并不会自动下载下来的,此时,只需执行该指令,即可将子模块内容下载下来后工程才不会缺少相应的文件。
cd ..

Now its time to build the binaries by compiling the source code. But before going straight to the hardware, asimulation run is recommended as the next step. Users preferring to work in a graphical development environment should continue with the next section.(现在就可编译源码构建二进制代码了。但在直接到硬件前,仿真运行作为下一步的推荐。喜欢使用图形开发环境的用户应当继续下一部分学习。)

NuttX / Pixhawk based boards

cd Firmware
make px4fmu-v2_default

Note the syntax: 'make' is the build tool, 'px4fmu-v2' is the hardware / autopilot version and 'default' is the default configuration. All PX4 build targets follow this logic. A successful run will end with this output:(注意语法:make是编译工具;px4fmu-v2是硬件版本,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

By appending 'upload' to these commands the compiled binary will be uploaded via USB to the autopilot hardware:(通过执行加载命令,编译的二进制代码将被通过USB加载到无人机中。)

make px4fmu-v2_default upload

A successful run will end with this output:(成功运行有如下输出)

Erase  : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.

[100%] Built target upload

Raspberry Pi 2/3 boards

The command below builds the target for Raspbian.

Cross-compiler build
cd Firmware
make posix_rpi_cross # for cross-compiler build

The "mainapp" executable file is in the directory build_posix_rpi_cross/src/firmware/posix. Make sure you can connect to your RPi over ssh, see instructions how to access your RPi.

Then set the IP (or hostname) of your RPi using:

export AUTOPILOT_HOST=192.168.X.X

And upload it with:

cd Firmware
make posix_rpi_cross upload # for cross-compiler build

Then, connect over ssh and run it with :

./mainapp mainapp.config
Native build

If you're building directly on the Pi, you will want the native build target (posix_rpi_native).

cd Firmware
make posix_rpi_native # for native build

The "mainapp" executable file is in the directory build_posix_rpi_native/src/firmware/posix. Run it directly with :

./build_posix_rpi_native/src/firmware/posix/mainapp ./posix-configs/rpi/mainapp.config

A successful build followed by executing mainapp will give you this :

[init] shell id: 1996021760
[init] task name: mainapp

______  __   __    ___
| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

Ready to fly.


pxh>

Parrot Bebop

Support for the Bebop is really early stage and should not be used.
Build it
cd Firmware
make posix_bebop_default

Turn on your Bebop and connect your host machine with the Bebop's wifi. Then, press the power button four times to enable ADB and start the telnet daemon.

make posix_bebop_default upload
Note this will also copy mainapp.config file.
Run it

Connect to the Bebop's wifi and press the power button four times.

telnet 192.168.42.1

Run mainapp with:

mainapp
You can also use adb shell to start the mainapp.

QuRT / Snapdragon based boards

Build it

The commands below build the targets for the Linux and the DSP side. Both executables communicate viamuORB.

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](https://github.com/PX4/Firmware/blob/master/posix-configs/eagle/flight/mainapp.config) and [px4.config](https://github.com/PX4/Firmware/blob/master/posix-configs/eagle/flight/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 it

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.

Auto-start mainapp

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

Compiling in a graphical IDE(图形集成开发环境编译)

The PX4 system supports Qt Creator, Eclipse and Sublime Text. Qt Creator is the most user-friendly variant and hence the only officially supported IDE. Unless an expert in Eclipse or Sublime, their use is discouraged. Hardcore users can find an Eclipse project and a Sublime project in the source tree.(PX4系统支持Qt Creator, Eclipse and Sublime和 Sublime Text。Qt Creator是最友好的,因此是官方支持的IDE。除非是 Eclipse 或 Sublime专家,否则他们的使用是让人气馁的。硬核使用者可以找到 Eclipse p工程Sublime工程在源码树中。

frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/Bkk8zttWxEI" style="box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased;font-size:undefined; border-style: none; border-width: initial; position: absolute; top: 0px; left: 0px; width: 770px; height: 458.125px;">

Qt Creator Functionality(Qt Creator功能)

Qt creator offers clickable symbols, auto-completion of the complete codebase and building and flashing firmware.(Qt creator提供了可点击符号,自动代码补全和构建、刷新固件功能)。

Qt Creator on Linux

Before starting Qt Creator, the project file needs to be created:(在使用Qt Creator之前,工程文件需要先创建)

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

Then load the CMakeLists.txt in the root firmware folder via File -> Open File or Project -> Select the CMakeLists.txt file.(然后加载CMakeLists.txt到根固件文件夹通过File -> Open File or Project -> Select the CMakeLists.txt file.操作)

After loading, the 'play' button can be configured to run the project by selecting 'custom executable' in the run target configuration and entering 'make' as executable and 'upload' as argument.(加载之后,运行按钮可以被配置为运行项目通过在运行配置中选择'custom executable',并且输入“make”作为执行,‘upload' 作为参数。)

Qt Creator on Windows

Windows has not been tested with Qt creator yet.

Qt Creator on Mac OS

Before starting Qt Creator, the project file needs to be created:

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

That's it! Start Qt Creator, then complete the steps in the video below to set up the project to build.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值