> For the complete documentation index, see [llms.txt](https://docs.theseus.us/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.theseus.us/cyclops/autopilot-integration/ardupilot/fine-tune-magnetometer.md).

# Fine tune magnetometer

Cyclops performance may benefit from an extended magnetometer calibration if there are issues with heading. Please use this guide to run the extended calibration.

### Step 1: Standard compass calibration

First, calibrate the compass using the standard calibration tool in Mission Planner or QGC. This will create a baseline calibration that our software will use for the extended calibration.

{% hint style="info" %}
Ensure that the external compass you are using is configured as Compass 1 and `CUST_ROT_ENABLE` is set to 0 (disabled).
{% endhint %}

### Step 2: Compass extrinsics

After standard calibration, reboot the flight controller. Then connect to your Cyclops device over Ethernet via SSH.

```bash
ssh pi@192.168.218.100
```

Run the following two commands to start the extended mag cal tool.

```bash
source /opt/vns-sdk/venv/bin/activate
python3 /lib/vns-sdk/scripts/calibrate_compass_extrinsics.py
```

The script will prompt you to *slowly* rotate your airframe two times while connected, first with the wings level, and then with the nose down. This will output three values for your compass' custom rotation.

{% hint style="info" %}
Do not disconnect from your Cyclops device until the extended calibration is complete.
{% endhint %}

Once you have these values, connect to your flight controller and set the following ArduPilot params:

<table><thead><tr><th width="210">ArduPilot Parameter</th><th>Value</th><th>Description</th></tr></thead><tbody><tr><td><code>CUST_ROT_ENABLE</code></td><td><code>1</code></td><td>Enables custom rotations</td></tr><tr><td><code>COMPASS_ORIENT</code></td><td><code>101</code></td><td>Applies custom rotation values to Compass 1</td></tr><tr><td><code>CUST_ROT1_PITCH</code></td><td>(value from script)</td><td>Custom pitch value</td></tr><tr><td><code>CUST_ROT1_ROLL</code></td><td>(value from script)</td><td>Custom roll value</td></tr><tr><td><code>CUST_ROT1_YAW</code></td><td>(value from script)</td><td>Custom yaw value</td></tr></tbody></table>

### Step 3: Final compass calibration

After these parameters are set, run a final compass calibration using the same standard calibration tool as in Step 1. This will use the new compass extrinsics to do a more refined calibration. Reboot the flight controller when finished.

{% hint style="success" %}
Your compass is precisely calibrated with custom rotation values.
{% endhint %}
