PX4 firmware can be built from source code on the console or in an IDE, for both simulated and hardware targets.
You need to build PX4 in order to use simulators, or if you want to modify PX4 and create a custom build. If you just want to try out PX4 on real hardware then load the prebuilt binaries using QGroundControl (there is no need to follow these instructions).
:::ノート これらの手順に従う前に、まずホストOSとターゲットハードウェアに Developer Toolchain をインストールする必要があります。 If you have any problems after following these steps see the Troubleshooting section below. :::
PX4のソースコードは,Githubの PX4/PX4-Autopilot に保存されています.
To get the very latest (main
branch) version onto your computer, enter the following command into a terminal:
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
Note that you may already have done this when installing the Developer Toolchain
::: info This is all you need to do in order to get the latest code. If needed you can also get the source code specific to a particular release. GIT Examples provides a lot more information working with releases and contributing to PX4. :::
最初に、ホストOS上で機体のシミュレーションをビルドします。 これにより、実際にハードウェアとIDEで設定する前にシステムを検証することができます。
Navigate into the PX4-Autopilot directory. Depending on your operating system you will have installed either Gazebo SITL or Gazebo Classic SITL (if you don't know which you can try both).
:::: tabs
::: tab Gazebo Start Gazebo SITL using the following command:
make px4_sitl gz_x500
:::
::: tab Gazebo-Classic Start Gazebo SITL using the following command:
make px4_sitl gazebo-classic
:::
::::
This will bring up the PX4 console:
::: info You may need to start QGroundControl before proceeding, as the default PX4 configuration requires a ground control connection before takeoff. こちら からダウンロードできます。 :::
The drone can be flown by typing the following command (as shown in the console above):
pxh> commander takeoff
The vehicle will take off and you'll see this in the simulator UI:
:::: tabs
::::
ドローンは commander land
コマンドによって着陸します.また,CTRL+C (または shutdown
コマンド)によってシミュレーションを停止できます。
QGroundControlでシミュレーションすることは、車両の実際の動作に近くなります。 飛行中に地図上の場所をクリックし、スライダーを有効にします。 これにより、車両の位置が変更されます。
NuttX-またはPixhawkベースのボード用に構築する PX4-Autopilot ディレクトリに移動し、 make
をビルドターゲットに対して使用します.
たとえば、 Pixhawk 4 ハードウェア用にビルドするには、次のコマンドを使用します。
cd PX4-Autopilot
make px4_fmu-v5_default
実行が成功すると、次のような出力で終了します。
-- Build files have been written to: /home/youruser/src/PX4-Autopilot/build/px4_fmu-v4_default
[954/954] Creating /home/youruser/src/PX4-Autopilot/build/px4_fmu-v4_default/px4_fmu-v4_default.px4
The first part of the build target px4_fmu-v4
indicates the target flight controller hardware for the firmware. The suffix, in this case _default
, indicates a firmware configuration, such as supporting or omitting particular features.
::: info The _default
suffix is optional. For example, make px4_fmu-v5
and px4_fmu-v5_default
result in the same firmware.
:::
次のリストは、 Pixhawk 標準 ボードのビルドコマンドを示しています。
- Holybro Pixhawk 6X-RT (FMUv6X):
make px4_fmu-v6xrt_default
- Holybro Pixhawk 6X (FMUv6X):
make px4_fmu-v6x_default
- Holybro Pixhawk 6C (FMUv6C):
make px4_fmu-v6c_default
- Holybro Pixhawk 6C Mini (FMUv6C):
make px4_fmu-v6c_default
- Holybro Pix32 v6 (FMUv6C):
make px4_fmu-v6c_default
- Holybro Pixhawk 5X (FMUv5X):
make px4_fmu-v5x_default
- Pixhawk 4 (FMUv5):
make px4_fmu-v5_default
- Pixhawk 4 Mini (FMUv5):
make px4_fmu-v5_default
- CUAV V5+ (FMUv5):
make px4_fmu-v5_default
- CUAV V5 nano (FMUv5):
make px4_fmu-v5_default
- Pixracer (FMUv4):
make px4_fmu-v4_default
- Pixhawk 3:
make px4_fmu-v5_default
- Pixhawk :
make px4_fmu-v5_default
- Pixhawk 2 (Cube Black) (FMUv3):
make px4_fmu-v3_default
- mRo Pixhawk (FMUv3):
make px4_fmu-v3_default
(supports 2MB Flash) - Holybro pix32 (FMUv2):
make px4_fmu-v2_default
- Pixfalcon (FMUv2):
make px4_fmu-v2_default
- Dropix (FMUv2):
make px4_fmu-v2_default
- Pixhawk 1 (FMUv2):
make px4_fmu-v2_default
:::warning You must use a supported version of GCC to build this board (e.g. the same as used by CI/docker) or remove modules from the build. Building with an unsupported GCC may fail, as PX4 is close to the board's 1MB flash limit. :::
- Pixhawk 1 with 2 MB flash:
make px4_fmu-v3_default
Pixhawk NuttX 以外のフライトコントローラ(および他のすべてのボード)用のビルドコマンドは、個々の フライトコントローラボード のドキュメントに記載されています。
upload
をmakeコマンドに追加し、コンパイル済みバイナリをUSB経由でハードウェアにアップロードします。 例:
make px4_fmu-v4_default upload
実行が成功すると、次のような出力で終了します。
Erase : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.
[100%] Built target upload
Build commands for other boards are given the board-specific flight controller pages (usually under a heading Building Firmware).
以下のコマンドを使用して、すべての構成ターゲットを列挙することもできます。
make list_config_targets
VScode は、PX4開発で正式にサポートされている(そして推奨されている)IDEです。 セットアップは簡単で、シミュレーション環境とハードウェア環境の両方でPX4をコンパイルできます。
ビルドの問題の多くは、サブモジュールの不一致またはビルド環境のクリーンアップが不完全なために発生します サブモジュールを更新して distclean
を実行すると、エラーが修正されます。
git submodule update --recursive
make distclean
region 'flash' overflowed by XXXX bytes
エラーは、ファームウェアのサイズがハードウェアの容量に対して大きすぎることを示しています。 これは フラッシュ サイズが1MBに制限されている場合に,make px4_fmu-v2_default
ビルドで一般的に起こりえます.
If you're building the vanilla master branch, the most likely cause is using an unsupported version of GCC. この場合、 Developer Toolchain の説明で指定されたバージョンをインストールします。
If building your own branch, it is possible that you have increased the firmware size over the 1MB limit. この場合、ビルドから不要なドライバ/モジュールを削除する必要があります。
MacOSでは、実行中のすべてのプロセスでデフォルトで最大256個のファイルを開くことができます。 PX4ビルドシステムは多数のファイルを開くため、この数を超える可能性があります。
次に示すように、ビルドツールチェーンは、 Too many open files
エラーを出力します.
/usr/local/Cellar/gcc-arm-none-eabi/20171218/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: cannot find NuttX/nuttx/fs/libfs.a: Too many open files
解決策は、開いているファイルの最大許容数を増やすことです (e.g. to 300). You can do this in the macOS Terminal for each session:
-
Run this script Tools/mac_set_ulimit.sh, or
-
次のコマンドを入力します。
ulimit -S -n 300
As of macOS Catalina 10.15.1 there may be problems when trying to build the simulator with cmake. このプラットフォームでビルドに問題がある場合は、ターミナルで次のコマンドを実行してみてください。
xcode-select --install
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
arm_none_eabi_gcc
に関連するビルドの問題は、g++ ツールチェーンのインストールが壊れていることが原因の可能性があります。 以下を使用して不足している依存関係を確認することで、この場合であることを確認できます。
arm-none-eabi-gcc --version
arm-none-eabi-g++ --version
arm-none-eabi-gdb --version
arm-none-eabi-size --version
依存関係が不足しているbash出力の例:
arm-none-eabi-gdb --version
arm-none-eabi-gdb: command not found
これは、コンパイラーを削除して再インストールすることで解決できます。
See Visual Studio Code IDE (VSCode) > Troubleshooting.
"Failed to import" errors when running the make px4_sitl jmavsim
command indicates that some Python packages are not installed (where expected).
Failed to import jinja2: No module named 'jinja2'
You may need to install it using:
pip3 install --user jinja2
If you have already installed these dependencies this may be because there is more than one Python version on the computer (e.g. Python 2.7.16 Python 3.8.3), and the module is not present in the version used by the build toolchain.
You should be able to fix this by explicitly installing the dependencies as shown:
pip3 install --user pyserial empty toml numpy pandas jinja2 pyyaml pyros-genmsg packaging
The previous sections showed how you can call make to build a number of different targets, start simulators, use IDEs etc. This section shows how make options are constructed and how to find the available choices.
The full syntax to call make with a particular configuration and initialization file is:
make [VENDOR_][MODEL][_VARIANT] [VIEWER_MODEL_DEBUGGER_WORLD]
VENDOR_MODEL_VARIANT: (also known as CONFIGURATION_TARGET
)
- VENDOR: The manufacturer of the board:
px4
,aerotenna
,airmind
,atlflight
,auav
,beaglebone
,intel
,nxp
, etc. The vendor name for Pixhawk series boards ispx4
. - MODEL: The board model "model":
sitl
,fmu-v2
,fmu-v3
,fmu-v4
,fmu-v5
,navio2
, etc. - VARIANT: Indicates particular configurations: e.g.
bootloader
,cyphal
, which contain components that are not present in thedefault
configuration. Most commonly this isdefault
, and may be omitted.
:::tip
You can get a list of all available CONFIGURATION_TARGET
options using the command below:
make list_config_targets
:::
VIEWER_MODEL_DEBUGGER_WORLD:
- VIEWER: This is the simulator ("viewer") to launch and connect:
gz
,gazebo
,jmavsim
,none
:::tip
none
can be used if you want to launch PX4 and wait for a simulator (jmavsim, Gazebo, Gazebo Classic, or some other simulator). For example, make px4_sitl none_iris
launches PX4 without a simulator (but with the iris airframe).
:::
- MODEL: The vehicle model to use (e.g.
iris
(default),rover
,tailsitter
, etc), which will be loaded by the simulator. The environment variablePX4_SIM_MODEL
will be set to the selected model, which is then used in the startup script to select appropriate parameters. - DEBUGGER: Debugger to use:
none
(default),ide
,gdb
,lldb
,ddd
,valgrind
,callgrind
. For more information see Simulation Debugging. - WORLD: (Gazebo Classic only). Set the world (PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds) that is loaded. Default is empty.world. For more information see Gazebo Classic > Loading a Specific World.
:::tip
You can get a list of all available VIEWER_MODEL_DEBUGGER_WORLD
options using the command below:
make px4_sitl list_vmd_make_targets
:::
::: info
- Most of the values in the
CONFIGURATION_TARGET
andVIEWER_MODEL_DEBUGGER
have defaults, and are hence optional. For example,gazebo-classic
is equivalent togazebo-classic_iris
orgazebo-classic_iris_none
. - You can use three underscores if you want to specify a default value between two other settings. For example,
gazebo-classic___gdb
is equivalent togazebo-classic_iris_gdb
. - You can use a
none
value forVIEWER_MODEL_DEBUGGER
to start PX4 and wait for a simulator. For example start PX4 usingmake px4_sitl_default none
and jMAVSim using./Tools/simulation/jmavsim/jmavsim_run.sh -l
.
:::
The VENDOR_MODEL_VARIANT
options map to particular px4board configuration files in the PX4 source tree under the /boards directory. Specifically VENDOR_MODEL_VARIANT
maps to a configuration file boards/VENDOR/MODEL/VARIANT.px4board (e.g. px4_fmu-v5_default
corresponds to boards/px4/fmu-v5/default.px4board).
Additional make targets are discussed in relevant sections:
bloaty_compare_master
: Binary Size Profiling- ...
The PX4 Firmware Version and Custom Firmware Version are published using the MAVLink AUTOPILOT_VERSION message, and displayed in the QGroundControl Setup > Summary airframe panel:
These are extracted at build time from the active git tag for your repo tree. The git tag should be formatted as <PX4-version>-<vendor-version>
(e.g. the tag in the image above was set to v1.8.1-2.22.1
).
:::warning If you use a different git tag format, versions information may not be displayed properly. :::