Skip to main content

Building ArduPilot

Install Support Stuff

On Debian Wheezy Image:

Update compiler for C++11 code that started to creep into APM codebase in early 2015.

# Use apt-pinning to get gcc 4.8 with C++11 support from Jessie repo.
vim /etc/apt/sources.list
# add the following line to the file above.
deb http://ftp.uk.debian.org/debian/ jessie main non-free contrib

Edit the apt pref. to tweak the priority.

vim /etc/apt/preferences

Package: *
Pin: release a=wheezy
Pin-Priority: 900

Package: gcc*
Pin: release a=jessie
Pin-Priority: 910

Update apt and install gcc

sudo aptitude update
sudo aptitude install gcc-4.8/jessie
sudo aptitude install g++-4.8/jessie

# Symlink to 4.8 versions
#cd /usr/bin/
#rm gcc
#ln -s gcc-4.8 gcc
#rm g++
#ln -s g++-4.8 g++

# Register alternatives so that the linker, etc. can find proper components to call.
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
update-alternatives --install /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/g++-4.8 50

Build devicetree

NOTE: not needed on Erle images. Usually, no need to rebuild these on 3.8.x kernel.

Before doing this, clone ardupilot (see building APM section below for details).

cd ~/ardupilot/Tools/Linux_HAL_Essentials/devicetree/pxf/
vim Makefile
# add BB-PXF-01-00A0.dtbo to all: target

make clean
make
make install

cd ~/ardupilot/Tools/Linux_HAL_Essentials
./startup.sh load

On Debian Jessie Image:

NOTE: As of October 2015, PXF devicetree stuff only seems to work with 3.8.x kernel. In fact, devicetree overlay support in general on kernel 4.1.x is still spotty. So IGNORE the following section and DO NOT update the kernel nor use Jessie images. Just use one of the Erle supplied images and stick with 3.8 kernel.

Update & Upgrade Packages

apt-get update
apt-get upgrade

Disable the HDMC and eMMC

This frees up required pins for PXF cape

vim /boot/uEnv.txt
##BeagleBone Black: HDMI (Audio/Video)/eMMC disabled:
dtb=am335x-boneblack-overlay.dtb
##Disable HDMI/eMMC (v3.8.x)
cape_disable=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN,BB-BONE-EMMC-2G
# uncomment the lines above

Install Device Tree

cp ~/ardupilot/Tools/Linux_HAL_Essentials/devicetree/pxf/BB-PXF-01-00A0.dtbo /lib/firmware
vim /boot/uboot/uEnv.txt
# add the following line
cape_enable=capemgr.enable_partno=BB-PXF-01

vim /etc/default/capemgr
# add the following line
CAPE=BB-PXF-01

NOTE: The above steps are obsolete on > v3.8 kernels. The latest is not to use capemgr at all. See: - http://forum.erlerobotics.com/t/hi-how-to-match-hw-version-and-fw-version-of-erle-brain/300/2 - http://forum.erlerobotics.com/t/are-you-planning-to-port-the-firecape-on-the-new-device-tree-overlay/276/5 - https://github.com/vmayoral/ubuntu-vivid/tree/dd9f961671af2df9cec5cb481d436e3b92cd6060/arch/arm/boot/dts - https://github.com/khancyr/ardupilot/tree/PXF-4.1/Tools/Linux_HAL_Essentials/devicetree/pxf

Set hostname

Make sure hostname is properly set in the hosts file for the install script to resolve the device name.

cat /etc/hostname
vim /etc/hosts

Load the PXF cape

Make sure CapeManager is compiled in the kernel

zcat /proc/config.gz | grep CONFIG_BONE_CAPEMGR

# Above should return:
# CONFIG_BONE_CAPEMGR=y

Make a dir for cloning modules

mkdir ~/src
cd ~/src

Install dtc

git clone https://github.com/beagleboard/bb.org-overlays.git
cd bb.org-overlays

# Check Device Tree Compiler version
dtc --version
# Above should return:
# Version: DTC 1.4.1-xxxxx

# Configure git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

# If dtc is not of correct version, upgrade by:
./dtc-overlay.sh

# If the above fails, delete ~/git/dtc/ and try again.

# Install
./install.sh

# Reboot
reboot

Install device tree from Erle

cd ~/src
git clone https://github.com/erlerobot/bbb-devicetree
cd bbb-devicetree

# Don't do the following as it overwrites the latest dtc installed above.
# ./dtc.sh

# To compile dts's:
dtc -O dtb -o am335x-boneblack.dtb -b 0 /root/bbb-devicetree/am335x-boneblack.dts

Manually load device trees

# Before doing this, clone ardupilot (see building APM section below for details).
cd ardupilot/Tools/Linux_HAL_Essentials
./startup.sh load

If running on v4.1 kernel (i.e. Debian Jessie)

git clone https://github.com/RobertCNelson/dtb-rebuilder.git
cd dtb-rebuilder
git checkout 4.1.x

# Check Device Tree Compiler version
dtc --version
# Above should return:
# Version: DTC 1.4.1-xxxxx

# Configure git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

# If dtc is not of correct version, upgrade by:
./dtc-overlay.sh

# Copy old dts source
cp ardupilot/Tools/Linux_HAL_Essentials/devicetree/pxf/*.dts src/arm/

# Build DTS into DTB
make

# Copy resulting dtb's
cp src/arm/*.dtb /boot/dtbs/4.1.xx-boneXX/

vim /boot/uEnv.txt
## Add the following line PXF cape for v4.1
cape_enable=bone_capemgr.enable_partno=BB-PXF-01

# reboot and check dmesg

With older kernel with cape_mgr

cd ardupilot/Tools/Linux_HAL_Essentials/devicetree/pxf/
vim Makefile
# add BB-PXF-01-00A0.dtbo to all: target
make clean
make
cd ../../
./startup.sh load

To load the cape on start up

cd ardupilot/Tools/Linux_HAL_Essentials
cp devicetree/pxf/BB-PXF-01-00A0.dtbo /lib/firmware

*NOTE: Copying the *.dtbo to /lib/firmware/ won't do anything as the actual file that gets loaded lives in vmlinuz/zImage. see: https://github.com/RobertCNelson/boot-scripts/issues/4 *

vim /boot/uEnv.txt
# add the following line
cape_enable=capemgr.enable_partno=BB-PXF-01
## PXF cape for v4.1
cape_enable=bone_capemgr.enable_partno=BB-PXF-01

vim /etc/default/capemgr
# add the following line
CAPE=BB-PXF-01

Check cape loading status

cat /sys/devices/platform/bone_capemgr/slots

To remove a cape

echo -6 > /sys/devices/platform/bone_capemgr/slots

Build APM

NOTE: The latest APM codebase requires g++11 which is not available with g++4.7, the latest available on wheezy, so complie it on desktop linux with arm cross compiler package and copy the binary over to BBB. or install gcc 4.8 as explained above.

https://github.com/diydrones/ardupilot/issues/1986

# Install build tools
apt-get install make gawk arduino-core
# apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
# apt-get install gcc-arm-none-eabi

# Clone git repo
git clone git://github.com/diydrones/ardupilot.git

# OR if using a git repo hosted on local network, get it via SSH
git clone user@host:~/your/git/repo/directory localreponame

cd ardupilot/ArduCopter
# make configure is no longer needed
# make configure
make pxf-quad

OR, with older version of APM, use make linux instead

make linux

Building APM on Desktop Linux Machine

Must be > gcc-4.8. Also, if you are linking against glibc version greater than v2.13 (e.g. Ubuntu 14.04 LTS), it won't run on BBB running debian wheezy.

apt-get install gcc-arm-linux-gnueabihf
apt-get install g++-arm-linux-gnueabihf
cd ardupilot/ArduCopter
make -j3 pxf-quad upload

If you have the latest version with ardupilot/mk/upload_firmware.mk

export BOARD_LINUX_HOST=user@192.168.7.1:~/ardupilot/ArduCopter/
make -j3 pxf-quad upload

Once it's been compiled, run the program on BBB

# Simple version
./ArduCopter.elf

# Options:
#   -A switch: Primary Telemetry Port
#   -B switch: GPS Port
#   -C switch: Secondary Telemetry Port
./ArduCopter.elf -A udp:192.168.7.1:6000 -B /dev/ttyO5 -C /dev/ttyO4

Launching ROS

roscore &
rosnode list
rostopic list

Rerefences: