# Setting up Payload Delivery with Gripper

{% hint style="info" %}
The following configuration must be implemented by the drone manufacturer.
{% endhint %}

## Payload Delivery Architecture Diagram

<figure><img src="/files/ZK9A9oXymHfLVSKWke1Z" alt=""><figcaption><p>Architecture of Payload delivery mechanism</p></figcaption></figure>

Payload delivery works by having a specified **Mission item** (e.g. Gripper) that sends out the Release mechanism **vehicle command** (e.g. Gripper Deploy), and having either internal/external entity sending back the **acknowledgement** (Vehicle Command Ack), which then allows a mission to progress to the next item.

Understanding of the detailed mechanism is not necessary for following the instructions below, but having a brief overview of the architecture by viewing the diagram above can be helpful for further insights.

## Configuring the Airframe file

If you aren't familiar with this concept, check out the [Creating Airframe Configurations for APX4](/~/changes/TDRfjBXXgHmxK48cWqay/hardware-integration/hardware-integration/airframe-setup-in-software.md) documentation, which provides also instructions on how to load the airframe configuration to the Auterion Skynode using the Auterion Developer Tools. From this point, we will be setting up an imaginary airframe `1300000_my_custom_airframe` for the payload delivery feature.

### Enabling Payload Delivery Gripper

Payload Delivery feature isn't enabled by default. To enable, insert the following lines into the airframe file.

{% code title="1300000\_my\_custom\_airframe" %}

```bash
# Enable payload delivery feature (Gripper)
param set-default PD_GRIPPER_EN 1
```

{% endcode %}

This would allow the Auterion PX4's startup script to detect that the payload delivery gripper mechanism is enabled, and would run the appropriate module to enable this feature.

### Enabling Pre-arm mode

By default, the Servos connected to the vehicle will be in a disarmed position when the vehicle is disarmed. However, since operator needs to open / close the gripper for mounting the payload while the vehicle is disarmed, we need to set a parameter to allow pre-arming, which allows Servos to move freely when disarmed, but not the motors.

{% code title="1300000\_my\_custom\_airframe" %}

```bash
# Always enable Prearm mode to allow Gripper to actuate when vehicle is disarmed
# This allows the operator to open / close the mechanism even when vehicle is disarmed
param set-default COM_PREARM_MODE 2
```

{% endcode %}

### Profiling the Gripper

Some mechanism specific settings need to be modified to make sure the system is aware of the mechanism's physical properties. Since every gripper works differently (speed / range of motion / behavior), you should not skip this step!

#### Gripper Mechanism Type

You need to select the **type** of the gripper. Currently only the **Servo** type is available, but in the future other types of gripper mechanisms might be supported.

This is the table of parameter value to set according to the gripper type.

| Gripper Type | PD\_GRIPPER\_TYPE value |
| :----------: | :---------------------: |
|   Undefined  |            -1           |
|     Servo    |            0            |

Paste the code below into the airframe file to set the gripper type to "servo":

{% code title="1300000\_my\_custom\_airframe" %}

```bash
# Set the griper type (uncomment one of the lines below to select)
param set-default PD_GRIPPER_TYPE 0 # Servo mechanism
# param set-default PD_GRIPPER_TYPE 1 # (NOT SUPPORTED YET) Winch mechanism
```

{% endcode %}

#### **Gripper Actuation Time**

You need to specify an **actuation time**, which is the time it takes to open or close. As most grippers don't have a sensor to detect successful actuation (close/opening), the payload delivery feature will rely on this value to estimate gripper's position.

To measure gripper actuation time, go to the [MAVLink Shell in AMC](/~/changes/TDRfjBXXgHmxK48cWqay/hardware-integration/flight-controller-customization/flight-controller-shell.md#mavlink-shell) and execute the following code while the drone is on a bench **and the propellers are removed**:

{% code title="AMC > MAVLink Shell" %}

```bash
payload_deliverer gripper_test
```

{% endcode %}

Then observe how long it takes for the gripper to go from open position to closed position, and vise versa for opening. Note down the actuation time for both cases and choose the maximum measurement for the actuation time.

As an alternative test method, you can utilize the Joystick capability of AMC to trigger gripper open and close actions as well.

{% hint style="info" %}
If you get an error message like "\[payload\_deliverer] not running", make sure that you have gone through the setup procedures above and rebooted the vehicle. Or alternatively, you could run `payload_deliverer start` command in the nuttx shell to bypass reboot.
{% endhint %}

After measuring the opening and closing actuation times, add the maximum value to the airframe file as shown below. The default value for `PD_GRIPPER_TO` is 3 seconds.

{% code title="1300000\_my\_custom\_airframe" %}

```bash
# Set Gripper timeout in seconds (opening / closing time)
# This must be set as the time gripper takes to open/close
# If opening/closing time differs, choose the longer time as timeout!
param set-default PD_GRIPPER_TO <timeout-in-seconds>
```

{% endcode %}

### Mission timeout

To use Auterion's payload delivery feature as part of a mission, it is important to make sure that a potential actuation failure does not cause the mission to be halted or interrupted.

For missions Auterion has therefore added an additional safeguard in form of a timeout, after which a mission is continued even if the gripper's successful actuation acknowledgement (which is published by the `payload_deliverer` module in charge of the Payload Delivery feature) is not received.

Possible causes could be **actuator failures** (*currently not the case since Gripper state feedback sensor is not supported*), but also **internal communication errors** (*Auterion PX4's internal messaging system can in rare-cases drop the acknowledgement message*).

{% hint style="info" %}
Currently, for PWM Grippers we rely on the [#gripper-actuation-time](#gripper-actuation-time "mention") alone to determine whether the actuation was successful or not.
{% endhint %}

Note that this timeout must be long enough to allow the delivery mechanism to actuate under all nominal conditions. Therefore chose a timeout that is larger than the [#gripper-actuation-time](#gripper-actuation-time "mention").

Once an appropriate timeout value is known, add it with the following line to the airframe configuration file. The default value for `MIS_PD_TO` is 5 seconds.

{% code title="1300000\_my\_custom\_airframe" %}

```bash
# Set Mission's Payload Delivery safeguard timeout in seconds
# NOTE: This must be bigger than the actuation timeout setting of the mechanism (e.g. PD_GRIPPER_TO)
param set-default MIS_PD_TO <timeout-in-seconds>
```

{% endcode %}

## Sanity Check

### Gripper Action check

You must make sure that Payload deliverer module's Gripper close/open command actually closes/opens the gripper. If not set up correctly, gripper may grab the package instead of releasing it during the release phase.

#### Open action test

Execute the following command in the AMC's MAVLink Shell:

{% code title="AMC > MAVLink Shell" %}

```bash
payload_deliverer gripper_open
```

{% endcode %}

Check if the gripper moves to an 'open' position, releasing the pacakge.

#### Close action test

Execute the following command in AMC's MAVLink Shell:

{% code title="AMC > MAVLink Shell" %}

```bash
payload_deliverer gripper_close
```

{% endcode %}

Check if the gripper moves to the 'close' position, grabbing the package.

#### How to fix the gripper action mis-configuration

If you noticed that the open/close tests above results in a different action of the actual gripper, you must re-configure the [Gripper mixer](/~/changes/TDRfjBXXgHmxK48cWqay/hardware-integration/airframe-integration/gripper-integration.md#writing-a-mixer-for-the-gripper).

Note, if the gripper doesn't move at all, make sure you followed the full procedure in the [Gripper Integration](/~/changes/TDRfjBXXgHmxK48cWqay/hardware-integration/airframe-integration/gripper-integration.md) documentation and [#configuring-the-airframe-file](#configuring-the-airframe-file "mention") section above.

As the only case of failure can be mixing up the release/grab, **for this you would simply need to apply the reversed gripper mixer** (indicated by the `-10000` in the line starting with `O: ...` below.

{% code title="gripper\_reversed.aux.mix" %}

```bash
# AUX1 pin is used for Payload deploy (Gripper / Winch)
# It uses 'Control Group 6 (Payload), channel 0' to avoid conflict with other flight controls
# More about control group 6: https://docs.px4.io/v1.13/en/concept/mixing.html#control-group-6-first-payload
# Read more about Summing mixer here: https://docs.px4.io/v1.13/en/concept/mixing.html#summing-mixer
M: 1
O:      -10000  -10000      0 -10000  10000
S: 1 4  10000  10000      0 -10000  10000
```

{% endcode %}

Then follow the rest of the process of [Gripper Integration](/~/changes/TDRfjBXXgHmxK48cWqay/hardware-integration/airframe-integration/gripper-integration.md#custom-mixer-for-gripping-mechanism) to load the custom mixer in the airframe & apply it to your vehicle.


---

# 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/~/changes/TDRfjBXXgHmxK48cWqay/hardware-integration/airframe-integration/gripper-integration/setting-up-payload-delivery-with-gripper.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.
