Building PX4

Source code

Getting the PX4 source code is easy:

Oh, and if you don’t have git yet just run this:

We are currently testing using the 1.6.0rc1 version, but the latest master branch should be ok too. Now to build it you will need the right tools.

PX4 Build tools

The full instructions are available on the dev.px4.io website, but we’ve copied the relevant subset of those instructions here for your convenience.

(Note that BashOnWindows) can be used to build the SITL version, but not the ARM firmware for pixhawk harddware).

First run this command to cache your admin credentials:

Now you can block copy/paste the following to a bash terminal and it should run them all to completion, but be sure to check each command for success:

Build SITL version

Now you can make the SITL version that runs in posix, from the Firmware folder you created above:

Note: this build system is quite special, it knows how to update git submodules (and there’s a lot of them), then it runs cmake (if necessary), then it runs the build itself. So in a way the root Makefile is a meta-meta makefile :-)

It shouldn’t take long, about 2 minutes. If all succeeds, the last line will link the px4 app, which you can then run using the following:

And you should see output that looks like this:

so this is good, first run sets up the px4 parameters for SITL mode. Second run has less output. This app is also an interactive console where you can type commands. Type ‘help’ to see what they are and just type ctrl-C to kill it. You can do that and restart it any time, that’s a great way to reset any wonky state if you need to (it’s equivalent to a Pixhawk hardware reboot).

ARM embedded tools

If you plan to build the PX4 firmware for real Pixhawk hardware then you will need the gcc cross-compiler for ARM Cortex-M4 chipset. You can find out what version, if any, you may already have by typing this command arm-none-eabi-gcc --version. Note: you do not need this to build the SITL version of PX4.

Note: This does not work in BashOnWindows because the arm-none-eabi-gcc tool is a 32-bit app which BashOnWindows cannot run. See installing arm-none-eabi-gcc on BashOnWindows at the bottom of this page.

Anyway, first we make sure to remove any old version of arm-none-eabi-gcc:

That previous command prompts you to hit ENTER, so be sure to run that separately before the following:

So now when you type this command arm-none-eabi-gcc --version and you should see:

Build PX4 for ARM hardware

Now you can build the PX4 firmware for running on real pixhawk hardware:

This build will take a little longer because it is building a lot more including the NuttX real time OS, all the drivers for the sensors in the Pixhawk flight controller, and more. It is also running the compiler in super size-squeezing mode so it can fit all that in a 1 megabyte ROM !!

One nice tid bit is you can plug in your pixhawk USB, and type make px4fmu-v2_default upload to flash the hardware with these brand new bits, so you don’t need to use QGroundControl for that.

Some Useful Parameters

PX4 has many customizable parameters (over 700 of them, in fact) and to get best results with AirSim we have found the following parameters are handy:

Installing arm-none-eabi-gcc in BashOnWindows

SolinGuo built a 64 bit version of gcc-arm-none-eabi so that it will run inside BashOnWindows. See gcc-arm-none-eabi-5_4-2017q2-20170512-linux.tar.bz2. If you download the *.tar.bz2 file to your machine and unpack it using this command line in BashOnWindows console:

you will get the following folder which contains the arm gcc cross-compiler:

If you add this folder to your PATH using the usual export PATH=... trick then the PX4 build will be able to find and run this compiler. After that, you can run make px4fmu-v2_default in BashOnWindows and the firmware will appear here: build_px4fmu-v2_default/src/firmware/nuttx/px4fmu-v2_default.px4. You can then flash this new firmware on your Pixhawk using QGroundControl.