tshell_blog

ソフトウェアと車輪がついた乗り物のはなし

ESP32用のArdupilotをビルドする

Arudupilotを見ていたらどうやらESP32上でも動かせそうです。 ESP32-CAMなんかをフライトコントローラにしたら,100g未満でウェイポイント飛行しながら空撮できる固定翼ドローンができるんじゃないでしょうか? まずはArdupilotをESP32向けにビルドしてみます。

環境

  • Ubuntu 20.04
  • Docker version 20.10.14, build a224086349

ソースのクローン

以下のコマンドでソースをクローンしてきます。

$ git clone https://github.com/ArduPilot/ardupilot.git
$ cd ardupilot
$ git submodule --init --recursive

ビルド環境コンテナイメージの作成

用意されているDockerfileを使います。以下のページにビルド手順が書いてあります。

ardupilot.org

Dockerfileがあるディレクトリで以下を実行します。

$ docker build . -t ardupilot

ardupilotディレクトリをマウントしてコンテナを起動します。

$ docker run --rm -it -name="ardupilot" -v `pwd`:/ardupilot ardupilot:latest bash

ESP32用ビルド環境の追加

ESP32向けのビルド方法は以下に書いてあります。

github.com

コンテナ内で以下のコマンドを実行します。

$ sudo apt update
$ sudo apt-get install git wget flex bison gperf python-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util
$ sudo apt-get install python3 python3-pip python3-setuptools
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

後のビルドステップでエラーが出るので以下のコマンドを実行してlibusb,empy, pexpectをインストールしておきます。

$ sudo apt install -y libusb-1.0-0
$ python -m pip install empy pexpect

以下のコマンドでESP32のビルドツールをインストールします。

$ ./Tools/scripts/esp32_get_idf.sh
$ cd modules/esp_idf
$ ./install.sh
$ . ./export.sh

別のターミナルを開いてdocker commitしておきます。

$ docker commit ardupilot ardupilot:esp32

ソースの修正

あとは./waf configureしたあと./wafでビルドするだけですが,以下2つのissueを参考にソースを修正しておきます。

以下に修正手順を示しますが,修正済みのソースを置きましたので,以下をクローンしてもOKです。

github.com

Tools/ardupilotwaf/board.py

Tools/ardupilotwaf/boards.pyの119行目付近を以下のように修正します。

# allow enable of custom controller for any board
# enabled on sitl by default
# if (cfg.options.enable_custom_controller or self.get_name() == "sitl") and not cfg.options.no_gcs:
#     env.ENABLE_CUSTOM_CONTROLLER = True
#     env.DEFINES.update(
#         AP_CUSTOMCONTROL_ENABLED=1,
#     )
#     env.AP_LIBRARIES += [
#         'AC_CustomControl'
#     ]
#     cfg.msg("Enabled custom controller", 'yes')
# else:
env.DEFINES.update(
    AP_CUSTOMCONTROL_ENABLED=0,
)
cfg.msg("Enabled custom controller", 'no', color='YELLOW')

GCS_FTPのエラー

libraries/AP_Filesystem/AP_Filesystem.hの35行目〜37行目をlibraries/GCS_MAVLink/GCS_FTP.cppにコピーします。

ビルド

上記の修正を行ったら,以下のコマンドでビルドします。

$ cd /ardupilot
$ . ./modules/esp_idf/export.sh
$ ./waf configure
$ ./waf configure --board=esp32diy
$ python -m pip install empy
$ python -m pip install pexpect
$ ./waf copter

以上でとりあえずエラーを回避してビルドできました。issueが立っているのでそのうちこういう小手先の修正をしなくてもビルドできるようになるでしょう。(人任せ)