The supported/tested Linux OS versions for PX4 development are Ubuntu Linux LTS 18.04 (Bionic Beaver) and 20.04 (Focal Fossa). These allow you to build for the most PX4 targets (NuttX based hardware, Qualcomm Snapdragon Flight hardware, Linux-based hardware, Simulation).
Bash scripts are provided to help make it easy to install development environment for different target platforms:
- [ubuntu.sh](https://github.com/PX4/Firmware/blob/{{ book.px4_version }}/Tools/setup/ubuntu.sh): Installs Gazebo 9 and jMAVSim simulators and/or NuttX/Pixhawk tools. Does not include dependencies for FastRTPS.
- [ubuntu_sim_ros_melodic.sh](https://raw.githubusercontent.com/PX4/Devguide/{{ book.px4_version }}/build_scripts/ubuntu_sim_ros_melodic.sh): Installs ROS "Melodic" and PX4 on Ubuntu 18.04 LTS (and later).
Tip The scripts have been tested on clean Ubuntu 18.04 LTS and Ubuntu 20.04 LTS installations. They may not work as expected if installed "on top" of an existing system, or on a different Ubuntu release.
The instructions below explain how to download and use the scripts.
Use the [ubuntu.sh](https://github.com/PX4/Firmware/blob/{{ book.px4_version }}/Tools/setup/ubuntu.sh) script to set up a development environment that includes Gazebo 9 and jMAVSim simulators, and/or the NuttX/Pixhawk toolchain.
To install the toolchain:
- Download PX4 Source Code:
git clone https://github.com/PX4/Firmware.git --recursive
- Run the ubuntu.sh with no arguments (in a bash shell) to install everything:
bash ./Tools/setup/ubuntu.sh
- Acknowledge any prompts as the script progress.
- You can use the
--no-nuttx
and--no-sim-tools
to omit the nuttx and/or simulation tools.
- Restart the computer on completion.
Note You can alternatively download [ubuntu.sh](https://github.com/PX4/Firmware/blob/{{ book.px4_version }}/Tools/setup/ubuntu.sh) and [requirements.txt](https://github.com/PX4/Firmware/blob/{{ book.px4_version }}/Tools/setup/requirements.txt) from the PX4 source repository (/Tools/setup/) and run ubuntu.sh in place:
wget https://raw.githubusercontent.com/PX4/Firmware/{{ book.px4_version }}/Tools/setup/ubuntu.sh
wget https://raw.githubusercontent.com/PX4/Firmware/{{ book.px4_version }}/Tools/setup/requirements.txt
bash ubuntu.sh
Notes:
- PX4 works with Gazebo 7, 8, and 9. The script uses gazebosim.org instructions to install Gazebo9.
- If you're going work with ROS then follow the ROS/Gazebo instructions instead (these install Gazebo automatically, as part of the ROS installation).
- You can verify the the NuttX installation by confirming the gcc version as shown:
$arm-none-eabi-gcc --version arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To get the build toolchain for Raspberry Pi:
- Download [ubuntu.sh](https://github.com/PX4/Firmware/blob/{{ book.px4_version }}/Tools/setup/ubuntu.sh) and [requirements.txt](https://github.com/PX4/Firmware/blob/{{ book.px4_version }}/Tools/setup/requirements.txt) from the PX4 source repository (/Tools/setup/):
wget https://raw.githubusercontent.com/PX4/Firmware/{{ book.px4_version }}/Tools/setup/ubuntu.sh
wget https://raw.githubusercontent.com/PX4/Firmware/{{ book.px4_version }}/Tools/setup/requirements.txt
- Run ubuntu.sh in a terminal to get just the common dependencies:
bash ubuntu.sh --no-nuttx --no-sim-tools
- Then setup an ARMv7 cross-compiler (either GCC or clang) as described in the following sections.
The official Raspberry Pi toolchains are not supported as PX4 has requires C++14 (which they do not support).
Ubuntu provides a set of pre-compiled toolchains that you can use instead. Install these with the terminal command:
sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
These package contains GCC/G++ 7.4.0 at time of writing. To test the toolchain, please execute:
arm-linux-gnueabihf-gcc -v
arm-linux-gnueabihf-g++ -v
First install GCC (needed to use clang).
We recommend you to get clang from the Ubuntu software repository as follows:
sudo apt-get install clang
Example below for building PX4 firmware out of tree, using CMake.
cd <PATH-TO-PX4-SRC>
mkdir build/px4_raspberrypi_default_clang
cd build/px4_raspberrypi_default_clang
cmake \
-G"Unix Makefiles" \
-DCONFIG=px4_raspberrypi_default \
-UCMAKE_C_COMPILER \
-DCMAKE_C_COMPILER=clang \
-UCMAKE_CXX_COMPILER \
-DCMAKE_CXX_COMPILER=clang++ \
../..
make
Additional developer information for using PX4 on Raspberry Pi (including building PX4 natively) can be found here: Raspberry Pi 2/3 Navio2 Autopilot.
This section explains how to install ROS/Gazebo ("Melodic") for use with PX4.
To install the development toolchain:
- Download the script in a bash shell:
wget https://raw.githubusercontent.com/PX4/Devguide/{{ book.px4_version }}/build_scripts/ubuntu_sim_ros_melodic.sh
- Run the script:
You may need to acknowledge some prompts as the script progresses.
bash ubuntu_sim_ros_melodic.sh
Note:
- ROS Melodic is installed with Gazebo9 by default.
- Your catkin (ROS build system) workspace is created at ~/catkin_ws/.
- The script uses instructions from the ROS Wiki "Melodic" Ubuntu page.
Setup instructions for Snapdragon Flight are provided in the PX4 User Guide:
eProsima Fast RTPS is a C++ implementation of the RTPS (Real Time Publish Subscribe) protocol. FastRTPS is used, via the RTPS/ROS2 Interface: PX4-FastRTPS Bridge, to allow PX4 uORB topics to be shared with offboard components.
Follow the instructions in Fast RTPS Installation to install it.
After setting up the build/simulation toolchain, see Additional Tools for information about other useful tools.
Once you have finished setting up the environment, continue to the build instructions.