# Creating Airframe Configurations for APX4

## What is an Airframe File?

After setting up, configuring, and tuning a new vehicle, an airframe configuration file should be created to store the setup and tuning parameters. Using airframe configurations the tuning can then easily be applied to other vehicles of the same type, as all relevant parameters will be loaded from this file.

In APX4 the airframe configuration file does mainly two things:

1. **Load pre-defined parameters**:\
   APX4 is configured by changing various parameters to tune the behaviour of the autopilot. Pre-defining parameters is convenient for setting up a large number of the same aircrafts
2. **Configure the Control Allocation (Input/Output mixing):**\
   Control allocation handles the mapping of control inputs to motor and servo outputs. All parameters starting with `CA_` are related to Control Allocation and therefore affect the mixing.

## Example of an Airframe File

The airframes supported by PX4 and Auterion PX4 can be found in [PX4's official documentation](https://docs.px4.io/main/en/airframes/airframe_reference.html).

In this example we want to create an airframe file for a Generic quadrotor x configuration. The [PX4 Airframe Reference](https://docs.px4.io/main/en/airframes/airframe_reference.html#airframes-reference) specifies that this airframe configuration has the ID `4001`. Inside the PX4 Github Repository, we can find the [file corresponding to the Generic quadrotor x airframe](https://github.com/PX4/PX4-Autopilot/blob/main/ROMFS/px4fmu_common/init.d/airframes/4001_quad_x).

{% code title="4001\_quad\_x" lineNumbers="true" %}

```sh
#!/bin/sh
#
# @name Generic Quadcopter
#
# @type Quadrotor x
# @class Copter
#
# @maintainer Lorenz Meier <lorenz@px4.io>
#

. ${R}etc/init.d/rc.mc_defaults

# Square quadrotor X PX4 numbering
param set-default CA_ROTOR_COUNT 4
param set-default CA_ROTOR0_PX 1
param set-default CA_ROTOR0_PY 1
param set-default CA_ROTOR1_PX -1
param set-default CA_ROTOR1_PY -1
param set-default CA_ROTOR2_PX 1
param set-default CA_ROTOR2_PY -1
param set-default CA_ROTOR2_KM -0.05
param set-default CA_ROTOR3_PX -1
param set-default CA_ROTOR3_PY 1
param set-default CA_ROTOR3_KM -0.05
```

{% endcode %}

This airframe configuration file is composed of two main parts.\
The first one loads the default parameters valid for a general multicopter frame:

```
. ${R}etc/init.d/rc.mc_defaults
```

The second one specifies all PX4 parameters that need to be different from the default ones. This examples shows the definition of the number of motors and the frame geometry.\
In a previous chapter ([Actuators Setup](/hardware-integration/hardware-integration/actuators-setup.md)) we have also seen how to change these parameters via the AMC UI by using the actuators tab.

```
param set-default CA_ROTOR_COUNT 4
param set-default CA_ROTOR0_PX 1
param set-default CA_ROTOR0_PY 1
param set-default CA_ROTOR1_PX -1
param set-default CA_ROTOR1_PY -1
param set-default CA_ROTOR2_PX 1
param set-default CA_ROTOR2_PY -1
param set-default CA_ROTOR2_KM -0.05
param set-default CA_ROTOR3_PX -1
param set-default CA_ROTOR3_PY 1
param set-default CA_ROTOR3_KM -0.05
```

{% hint style="info" %}
We recommend that the motors' position specified by the `CA_ROTORx_P` parameters are configured to match your vehicle geometry precisely.
{% endhint %}

## Creating a custom Airframe Configuration File

{% hint style="info" %}
The easiest way to create a custom airframe file is to start with an existing one.

You can either copy one from the [PX4 Github Repository](https://github.com/PX4/PX4-Autopilot/tree/main/ROMFS/px4fmu_common/init.d/airframes), or create a completely new .txt file named ID\_customName (e.g. 1230010\_custom) locally on your PC/Laptop.
{% endhint %}

For our example, we would start by modifying the header and keeping the multicopter defaults, since our custom drone is also a multicopter.\
Our Custom Config file should look as follows:

{% code title="1230010\_custom.txt" %}

```
#!/bin/sh
#
# @name Custom Quadcopter
#
# @type X500 Quadrotor
# @class Copter
#
# @maintainer YourName
#
. ${R}etc/init.d/rc.mc_defaults
```

{% endcode %}

Now you need to gather the parameters we changed during the sensors and actuators Setup. To do that the easiest way is to access the MavlinkConsole present inside AMC.

Connect your Skynode via USB-C to your PC/Laptop and open AMC. Access the [Advanced Mode](/hardware-integration/flight-controller-customization/amcs-advanced-mode.md). Click on the "Analyze" Tab present in the Left-hand sidebar menu and then choose MAVLink Console:

<figure><img src="/files/8BNImeEbyzqSOJGAR3wz" alt=""><figcaption></figcaption></figure>

Type the following command inside the MAVLink Console:

```
param show-for-airframe
```

And then type "Enter".

At this point you should be presented with the following output:

<figure><img src="/files/HI7qmgFIhrAFCiPl6RZb" alt=""><figcaption></figcaption></figure>

Now Select and copy the parameters inside your custom Airframe Configuration file, like this:

{% code title="1230010\_custom.txt" %}

```
#!/bin/sh
#
# @name Custom Quadcopter
#
# @type X500 Quadrotor
# @class Copter
#
# @maintainer YourName
#
. ${R}etc/init.d/rc.mc_defaults

param set-default CA_ROTOR0_PX 0.2500
param set-default CA_ROTOR0_PY 0.2500
param set-default CA_ROTOR1_PX -0.2500
param set-default CA_ROTOR1_PY -0.2500
param set-default CA_ROTOR2_PX 0.2500
param set-default CA_ROTOR2_PY -0.2500
param set-default CA_ROTOR3_PX -0.2500
param set-default CA_ROTOR3_PY 0.2500
param set-default COM_FLTMODE1 6
param set-default COM_FLTMODE2 0
param set-default GPS_1_CONFIG 0
param set-default PWM_AUX_FUNC1 101
param set-default PWM_AUX_FUNC2 102
param set-default PWM_AUX_FUNC3 103
param set-default PWM_AUX_FUNC4 104
param set-default PWM_AUX_TIM0 -3
param set-default SENS_EN_INA226 0
```

{% endcode %}

Now save this file locally on your PC/Laptop.

## Getting your Airframe File onto Skynode

{% hint style="danger" %}
Remove the propellers before proceeding
{% endhint %}

The airframe file we just created can be bundled with AuterionOS for deployment on Skynodes.

1. First you have to install the Auterion OEM Tools: [OEM Tools Installation](/hardware-integration/auterion-developer-tools/auterion-developer-tools-installation.md)
2. Save your airframe file as `aepx4-oem-tools-2.x.x/fmu/config/airframes/1230010_custom`
3. Edit the file `rc.autostart` under `aepx4-oem-tools-2.x.x/fmu/config` and add your custom airframe there:

{% code title="rc.autostart" %}

```bash
if param compare SYS_AUTOSTART 1230010
then
	sh /fs/microsd/ext_autostart/airframes/1230010_custom
fi
```

{% endcode %}

5. Make sure that your Skynode is coonnected to your PC/Laptop via USB.
6. Package your configuration file by executing the following command from your OEM tools folder:

   ```bash
   # In the Auterion OEM Tools directory:
   make fmu-update configurationDir=fmu/config
   ```
7. Wait for your Skynode to boot and connect to [Auterion Mission Control](broken://spaces/7S1QElc9VpiBzRbPAWCp/pages/-Lug87QZ72SXmrLxeW8i). Change the parameter `SYS_AUTOSTART = 1230010` and `SYS_AUTOCONFIG = reset parameters to airframe defaults.`

   <figure><img src="/files/NcRSx3gFQNHJ3KrzNegb" alt=""><figcaption></figcaption></figure>
8. Reboot your vehicle.
9. **ATTENTION: REMOVE THE PROPELLERS BEFORE PROCEEDING**

   Check if you motors and servos move correctly by repeating the procedure explained [here](/hardware-integration/hardware-integration/actuators-setup.md#test-the-actuators).

From now on you can directly upload this configuration file to your vehicles by following the procedure explained [above](#getting-your-airframe-file-onto-skynode).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.auterion.com/hardware-integration/hardware-integration/airframe-setup-in-software.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
