The best development environment for PX4 is using Eclipse as IDE in Ubuntu. There are also many other ways to do it. I have included in this log what is working for me and how to do it.
A quick summary:
- Install PX4 toolchain
- Install ninja build system (optional)
- Clone PX4 source code from Github
- Build the code and upload to hardware
- Install Eclipse (optional)
1. Install PX4 toolchain:
Setting up development environment on Ubuntu following the PX4 dev guide is very straight forward and usually trouble free. Make sure you follow the instructions in this link step by step: PX4 Toolchain Installation
Some of the packages can no longer be sudo apt-get install, such as openjdk-8-jdk and openjdk-8-jre. If this happens you need to look for alternative ways to install these packages, the jdks for Ubuntu can be found by a quick google search “java development kit ubuntu”.
So basically, copy these commands into your terminal:
sudo add-apt-repository ppa:george-edison55/cmake-3.x -y
sudo apt-get update
sudo apt-get install python-argparse git-core wget zip python-empy qtcreator cmake build-essential genromfs -y
sudo apt-get install ant protobuf-compiler libeigen3-dev libopencv-dev openjdk-8-jdk openjdk-8-jre clang-3.5 lldb-3.5 -y
sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install python-serial openocd flex bison libncurses5-dev autoconf texinfo build-essential libftdi-dev libtool zlib1g-dev python-empy gcc-arm-embedded -y
Note: watch out for the error messages, if there is an error messages, 99% of the time the problem can be solved by a quick google search.
2. Install ninja build system (optional):
You should also get ninja build system, it is a faster and more clean build experience. Follow the instructions on this page, see screenshot below: Ninja Build System
3. Clone PX4 source code from Github
Open a Ubuntu terminal and type in the following commands:
mkdir -p ~/px4
git clone https://github.com/PX4/Firmware.git
git submodule update --init --recursive
4. Build the code and upload to hardware
While in the ~/px4/Firmware directory, enter the following command in terminal:
You can append the command with upload to upload the firmware to your connected hardware:
make px4fmu-v2_default upload
You should see a screen like this once it is finished uploading.
If you launch QGroundControl now, it should automatically connect to your hardware and recognize that PX4 is on the board.
5. Install Eclipse (optional)
An Integrated Development Environment will make your life much easier, most of them can tell you which function is declared well and tell you in real time where you have introduced a bug without building the code. Any IDE is fine, Qt creator, sublime text etc. I use Eclipse because I already have that installed, and the PX4 source code comes with the Eclipse project files, which make importing projects into Eclipse easy and streamlined. I use Eclipse 3.8.1 for C/C++, and sublime text 2 for text files and scripts not in the project folder.
Here is how to import PX4 into Eclipse properly:
In the source code directory (~/px4/Firmware if you followed the steps above), rename the files “eclipse.cproject” into “.cproject”, and “eclipse.project” into “.project”.
Now launch Eclipse, create a new workspace in whatever directory you prefer, it doesn’t have to be in the same directory as your source code.
After Eclipse is initialized, go to workbench, and in the top menu bar, click File->Import… In the drop down menu choose General->Existing Projects into Workspace, click next.
Click the Browse… button to the right of the Select root directory, direct to your source code directory and click Ok. You should see PX4-Firmware in available projects. Select the project and click finish.