2016-08-01 19:41:00 -03:00
|
|
|
# Building ArduPilot #
|
2016-01-27 13:05:46 -04:00
|
|
|
|
2020-08-08 17:43:05 -03:00
|
|
|
## Get the Source
|
|
|
|
|
|
|
|
Clone the project from GitHub:
|
|
|
|
```sh
|
|
|
|
git clone --recursive https://github.com/ArduPilot/ardupilot.git
|
|
|
|
cd ardupilot
|
|
|
|
```
|
|
|
|
|
2023-07-12 20:06:07 -03:00
|
|
|
You can also read more about the build system in the
|
2016-10-31 08:22:03 -03:00
|
|
|
[Waf Book](https://waf.io/book/).
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2023-07-12 20:06:07 -03:00
|
|
|
waf should always be called from the locally cloned ardupilot root directory for the local branch you are trying to build from.
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2023-07-12 20:06:35 -03:00
|
|
|
**Note**
|
|
|
|
Do not run `waf` with `sudo`! This leads to permission and environment problems.
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
## Basic usage ##
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2023-07-12 20:06:07 -03:00
|
|
|
There are several commands in the build system for advanced usage, but here we
|
2016-08-01 19:41:00 -03:00
|
|
|
list some basic and more used commands as example.
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
* **Build ArduCopter**
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2018-02-13 01:56:07 -04:00
|
|
|
Below shows how to build ArduCopter for the Pixhawk2/Cube. Many other boards are
|
|
|
|
supported and the next section shows how to get a full list of them.
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
```sh
|
2018-11-20 06:25:55 -04:00
|
|
|
./waf configure --board CubeBlack
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf copter
|
|
|
|
```
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
The first command should be called only once or when you want to change a
|
|
|
|
configuration option. One configuration often used is the `--board` option to
|
|
|
|
switch from one board to another one. For example we could switch to
|
2018-02-13 01:56:07 -04:00
|
|
|
SkyViper GPS drone and build again:
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
```sh
|
2018-02-13 01:56:07 -04:00
|
|
|
./waf configure --board skyviper-v2450
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf copter
|
|
|
|
```
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2017-01-19 23:16:30 -04:00
|
|
|
If building for the bebop2 the binary must be built statically:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
./waf configure --board bebop --static
|
|
|
|
./waf copter
|
|
|
|
```
|
|
|
|
|
2019-11-17 14:35:21 -04:00
|
|
|
The "arducopter" binary should appear in the `build/<board-name>/bin` directory.
|
2017-01-19 22:24:18 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
* **List available boards**
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
It's possible to get a list of supported boards on ArduPilot with the command
|
|
|
|
below
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
```sh
|
|
|
|
./waf list_boards
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
```
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2018-02-13 01:56:07 -04:00
|
|
|
Here are some commands to configure waf for commonly used boards:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
./waf configure --board bebop --static # Bebop or Bebop2
|
|
|
|
./waf configure --board edge # emlid edge
|
2021-01-25 20:19:01 -04:00
|
|
|
./waf configure --board fmuv3 # 3DR Pixhawk 2 boards
|
2018-02-13 01:56:07 -04:00
|
|
|
./waf configure --board navio2 # emlid navio2
|
2018-11-20 06:25:55 -04:00
|
|
|
./waf configure --board Pixhawk1 # Pixhawk1
|
2021-01-25 20:19:01 -04:00
|
|
|
./waf configure --board CubeBlack # Hex/ProfiCNC Cube Black (formerly known as Pixhawk 2.1)
|
2018-11-20 06:25:55 -04:00
|
|
|
./waf configure --board Pixracer # Pixracer
|
2018-02-13 01:56:07 -04:00
|
|
|
./waf configure --board skyviper-v2450 # SkyRocket's SkyViper GPS drone using ChibiOS
|
|
|
|
./waf configure --board sitl # software-in-the-loop simulator
|
|
|
|
./waf configure --board sitl --debug # software-in-the-loop simulator with debug symbols
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2019-11-17 14:35:21 -04:00
|
|
|
* **List of available vehicle types**
|
|
|
|
|
|
|
|
Here is a list of the most common vehicle build targets:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
./waf copter # All multirotor types
|
|
|
|
./waf heli # Helicopter types
|
|
|
|
./waf plane # Fixed wing airplanes including VTOL
|
|
|
|
./waf rover # Ground-based rovers and surface boats
|
|
|
|
./waf sub # ROV and other submarines
|
|
|
|
./waf antennatracker # Antenna trackers
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
* **Clean the build**
|
|
|
|
|
|
|
|
Commands `clean` and `distclean` can be used to clean the objects produced by
|
|
|
|
the build. The first keeps the `configure` information, cleaning only the
|
|
|
|
objects for the current board. The second cleans everything for every board,
|
|
|
|
including the saved `configure` information.
|
|
|
|
|
|
|
|
Cleaning the build is very often not necessary and discouraged. We do
|
|
|
|
incremental builds reducing the build time by orders of magnitude.
|
|
|
|
|
|
|
|
|
|
|
|
* **Upload or install**
|
|
|
|
|
|
|
|
Build commands have a `--upload` option in order to upload the binary built
|
2017-07-24 16:57:51 -03:00
|
|
|
to a connected board. This option is supported by Pixhawk and Linux-based boards.
|
2017-06-29 18:16:35 -03:00
|
|
|
The command below uses the `--targets` option that is explained in the next item.
|
2016-08-01 19:41:00 -03:00
|
|
|
|
|
|
|
```sh
|
2017-01-09 06:13:04 -04:00
|
|
|
./waf --targets bin/arducopter --upload
|
2016-08-01 19:41:00 -03:00
|
|
|
```
|
|
|
|
|
2017-07-25 18:32:46 -03:00
|
|
|
For Linux boards you need first to configure the IP of the board you
|
|
|
|
are going to upload to. This is done on configure phase with:
|
2017-06-29 18:16:35 -03:00
|
|
|
|
|
|
|
```sh
|
|
|
|
./waf configure --board <board> --rsync-dest <destination>
|
|
|
|
```
|
|
|
|
|
2017-07-25 18:32:46 -03:00
|
|
|
The commands below give a concrete example (board and destination
|
2017-07-24 16:57:51 -03:00
|
|
|
IP will change according to the board used):
|
|
|
|
|
|
|
|
```sh
|
|
|
|
./waf configure --board navio2 --rsync-dest root@192.168.1.2:/
|
|
|
|
./waf --target bin/arducopter --upload
|
|
|
|
```
|
2017-06-29 18:16:35 -03:00
|
|
|
|
2017-07-25 18:32:46 -03:00
|
|
|
This allows to set a destination to which the `--upload` option will upload
|
|
|
|
the binary. Under the hood it installs to a temporary location and calls
|
|
|
|
`rsync <temp_install_location>/ <destination>`.
|
|
|
|
|
2017-06-29 18:16:35 -03:00
|
|
|
On Linux boards there's also an install command, which will install to a certain
|
|
|
|
directory, just like the temporary install above does. This can be
|
2016-08-01 19:41:00 -03:00
|
|
|
used by distributors to create .deb, .rpm or other package types:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
./waf copter
|
|
|
|
DESTDIR=/my/temporary/location ./waf install
|
|
|
|
```
|
|
|
|
|
|
|
|
* **Use different targets**
|
|
|
|
|
|
|
|
The build commands in the items above use `copter` as argument. This
|
|
|
|
builds all binaries that fall under the "copter" group. See the
|
|
|
|
section [Advanced usage](#advanced-usage) below for more details regarding
|
|
|
|
groups.
|
|
|
|
|
|
|
|
This shows a list of all possible targets:
|
|
|
|
|
|
|
|
```
|
|
|
|
./waf list
|
|
|
|
```
|
|
|
|
|
|
|
|
For example, to build only a single binary:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Quad frame of ArduCopter
|
2017-01-09 06:13:04 -04:00
|
|
|
./waf --targets bin/arducopter
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
# unit test of our math functions
|
|
|
|
./waf --targets tests/test_math
|
|
|
|
```
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2023-08-17 19:23:19 -03:00
|
|
|
* **Use clang instead of gcc**
|
|
|
|
|
|
|
|
Currently, gcc is the default on linux, and clang is used for MacOS.
|
|
|
|
Building with clang on linux can be accomplished by setting the CXX
|
|
|
|
environment variables during the configure step, e.g.:
|
|
|
|
|
|
|
|
```
|
|
|
|
CXX=clang++ CC=clang ./waf configure --board=sitl
|
|
|
|
```
|
|
|
|
|
|
|
|
Note: Your clang binary names may differ.
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
* **Other options**
|
|
|
|
|
|
|
|
It's possible to see all available commands and options:
|
|
|
|
|
|
|
|
```
|
|
|
|
./waf -h
|
|
|
|
```
|
|
|
|
|
|
|
|
Also, take a look on the [Advanced section](#advanced-usage) below.
|
|
|
|
|
|
|
|
## Advanced usage ##
|
|
|
|
|
|
|
|
This section contains some explanations on how the Waf build system works
|
|
|
|
and how you can use more advanced features.
|
|
|
|
|
|
|
|
Waf build system is composed of commands. For example, the command below
|
|
|
|
(`configure`) is for configuring the build with all the options used by this
|
|
|
|
particular build.
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-27 13:05:46 -04:00
|
|
|
```bash
|
2016-08-01 19:41:00 -03:00
|
|
|
# Configure the Linux board
|
|
|
|
./waf configure --board=linux
|
|
|
|
```
|
|
|
|
|
|
|
|
Consequently, in order to build, a "build" command is issued, thus `waf build`.
|
|
|
|
That is the default command, so calling just `waf` is enough:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Build programs from bin group
|
|
|
|
./waf
|
|
|
|
|
|
|
|
# Waf also accepts '-j' option to parallelize the build.
|
|
|
|
./waf -j8
|
2016-01-27 13:05:46 -04:00
|
|
|
```
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
By default waf tries to parallelize the build automatically to all processors
|
|
|
|
so the `-j` option is usually not needed, unless you are using icecc (thus
|
|
|
|
you want a bigger value) or you don't want to stress your machine with
|
|
|
|
the build.
|
|
|
|
|
|
|
|
### Program groups ###
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-03-31 15:47:10 -03:00
|
|
|
Program groups are used to represent a class of programs. They can be used to
|
2016-06-14 15:18:10 -03:00
|
|
|
build all programs of a certain class without having to specify each program.
|
|
|
|
It's possible for two groups to overlap, except when both groups are main
|
|
|
|
groups. In other words, a program can belong to more than one group, but only
|
|
|
|
to one main group.
|
2016-03-31 15:47:10 -03:00
|
|
|
|
|
|
|
There's a special group, called "all", that comprises all programs.
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
#### Main groups ####
|
2016-03-31 15:47:10 -03:00
|
|
|
|
|
|
|
The main groups form a partition of all programs. Besides separating the
|
|
|
|
programs logically, they also define where they are built.
|
|
|
|
|
|
|
|
The main groups are:
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-28 11:30:31 -04:00
|
|
|
- bin: *the main binaries, that is, ardupilot's main products - the vehicles and
|
|
|
|
Antenna Tracker*
|
|
|
|
- tools
|
|
|
|
- examples: *programs that show how certain libraries are used or to simply
|
|
|
|
test their operation*
|
2016-02-17 09:13:37 -04:00
|
|
|
- benchmarks: *requires `--enable-benchmarks` during configurarion*
|
2016-01-28 11:30:31 -04:00
|
|
|
- tests: *basically unit tests to ensure changes don't break the system's
|
|
|
|
logic*
|
|
|
|
|
|
|
|
All build files are placed under `build/<board>/`, where `<board>` represents
|
2016-03-31 15:47:10 -03:00
|
|
|
the board/platform you selected during configuration. Each main program group
|
|
|
|
has a folder with its name directly under `build/<board>/`. Thus, a program
|
|
|
|
will be stored in `build/<board>/<main_group>/`, where `<main_group>` is the
|
|
|
|
main group the program belongs to. For example, for a linux build, arduplane,
|
|
|
|
which belongs to the main group "bin", will be located at
|
|
|
|
`build/linux/bin/arduplane`.
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
#### Main product groups ####
|
2016-03-31 15:47:10 -03:00
|
|
|
|
|
|
|
Those are groups for ardupilot's main products. They contain programs for the
|
|
|
|
product they represent. Currently only the "copter" group has more than one
|
|
|
|
program - one for each frame type.
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
The main product groups are:
|
2016-03-31 15:47:10 -03:00
|
|
|
|
|
|
|
- antennatracker
|
|
|
|
- copter
|
|
|
|
- plane
|
|
|
|
- rover
|
2016-01-28 11:30:31 -04:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
#### Building a program group ####
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
Ardupilot adds to waf an option called `--program-group`, which receives as
|
|
|
|
argument the group you want it to build. For a build command, if you don't pass
|
|
|
|
any of `--targets` or `--program-group`, then the group "bin" is selected by
|
|
|
|
default. The option `--program-group` can be passed multiple times.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Group bin is the default one
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
# Build all vehicles and Antenna Tracker
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf --program-group bin
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
# Build all benchmarks and tests
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf --program-group benchmarks --program-group tests
|
2016-01-28 11:30:31 -04:00
|
|
|
```
|
2016-08-01 19:41:00 -03:00
|
|
|
#### Shortcut for program groups ####
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
For less typing, you can use the group name as the command to waf. Examples:
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-27 13:05:46 -04:00
|
|
|
```bash
|
2016-01-28 11:30:31 -04:00
|
|
|
# Build all vehicles and Antenna Tracker
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf bin
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-28 11:30:31 -04:00
|
|
|
# Build all examples
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf examples
|
2016-06-14 14:18:57 -03:00
|
|
|
|
|
|
|
# Build arducopter binaries
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf copter
|
2016-01-27 13:05:46 -04:00
|
|
|
```
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
### Building a specific program ###
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
In order to build a specific program, you just need to pass its path relative
|
|
|
|
to `build/<board>/` to the option `--targets`. Example:
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-27 13:05:46 -04:00
|
|
|
```bash
|
2016-03-31 15:47:10 -03:00
|
|
|
# Build arducopter for quad frame
|
2017-01-09 06:13:04 -04:00
|
|
|
./waf --targets bin/arducopter
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-28 11:30:31 -04:00
|
|
|
# Build vectors unit test
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf --targets tests/test_vectors
|
2016-06-14 14:08:37 -03:00
|
|
|
```
|
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
### Checking ###
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
The command `check` builds all programs and then executes the relevant tests.
|
|
|
|
In that context, a relevant test is a program from the group "tests" that makes
|
2016-01-28 11:30:31 -04:00
|
|
|
one of the following statements true:
|
|
|
|
|
|
|
|
- it's the first time the test is built since the last cleanup or when the
|
|
|
|
project was cloned.
|
|
|
|
- the program had to be rebuilt (due to modifications in the code or
|
|
|
|
dependencies, for example)
|
|
|
|
- the test program failed in the previous check.
|
|
|
|
|
|
|
|
That is, the tests are run only if necessary. If you want waf to run all tests,
|
|
|
|
then you can use either option `--alltests` or the shortcut command
|
|
|
|
`check-all`.
|
|
|
|
|
|
|
|
Examples:
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-27 13:05:46 -04:00
|
|
|
```bash
|
2016-01-28 11:30:31 -04:00
|
|
|
# Build everything and run relevant tests
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf check
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-28 11:30:31 -04:00
|
|
|
# Build everything and run all tests
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf check --alltests
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
# Build everything and run all tests
|
2016-08-01 19:41:00 -03:00
|
|
|
./waf check-all
|
2016-01-27 13:05:46 -04:00
|
|
|
```
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
### Debugging ###
|
2016-05-06 18:44:12 -03:00
|
|
|
|
|
|
|
It's possible to pass the option `--debug` to the `configure` command. That
|
|
|
|
will set compiler flags to store debugging information in the binaries so that
|
2018-05-08 23:58:46 -03:00
|
|
|
you can use them with `gdb`, for example. That option might come handy when using SITL.
|
2016-05-06 18:44:12 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
### Build-system wrappers ###
|
|
|
|
|
|
|
|
The `waf` binary on root tree is actually a wrapper to the real `waf` that's
|
|
|
|
maintained in its own submodule. It's possible to call the latter directly via
|
|
|
|
`./modules/waf/waf-light` or to use an alias if you prefer typing `waf` over
|
|
|
|
`./waf`.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
alias waf="<ardupilot-directory>/modules/waf/waf-light"
|
|
|
|
|
|
|
|
```
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-01-27 13:05:46 -04:00
|
|
|
There's also a make wrapper called `Makefile.waf`. You can use
|
2015-12-07 16:04:33 -04:00
|
|
|
`make -f Makefile.waf help` for instructions on how to use it.
|
2015-10-09 11:03:59 -03:00
|
|
|
|
2016-08-01 19:41:00 -03:00
|
|
|
### Command line help ###
|
2016-01-28 11:30:31 -04:00
|
|
|
|
|
|
|
You can use `waf --help` to see information about commands and options built-in
|
|
|
|
to waf as well as some quick help on those added by ardupilot.
|