# Switching between Mag+GPS and VIO indoors

Source: https://forum.modalai.com/topic/3570/switching-between-mag-gps-and-vio-indoors
Category: Autonomy: VIO, Mapping and Navigation (https://forum.modalai.com/category/19/autonomy-vio-mapping-and-navigation)
Tags: vio
Posted: 2024-06-20 16:00:21 UTC by Rowan Dempster
Replies: 7 · Views: 4630

## Rowan Dempster · 2024-06-20 16:00:21 UTC

Hi Modal,

Cleo is looking into using Magnetometer+GPS combo for outdoor heading and positioning. We're wondering how Modal handles the switch between indoor and outdoor flight, specifically how does the EKF2 know when to stop fusing the magnetometer (definitely don't want to try to keep heading via mag inside)?

Thanks!
Rowan

## Reply by Cliff Wong (ModalAI staff) · 2024-06-20 20:19:23 UTC

Hi there, if you're using GPS+mag+vio then you'll need the following PX4 params changes in addition to our ```vio_gps_baro.params``` helper file:

EKF2_MAG_TYPE = automatic   (voxl default)
EKF2_MAG_CHECK = 1  [or 2/3 for more sensitivity] (voxl default is 0)

Having mag_check = 1 will activate EKF2's field strength checker such that as you proceed indoors should stop mag fusion completely when the field strength goes outside thresholds (hardcoded within PX4 ~ .4gauss variance). It's similar to GPS's DOP threshold where we expect both (gps and mag) to exceed the thresholds where PX4 will stop fusion of those modalities and eventually use vio solely.

PX4's logic tries to maintain "smooth flight", so expect some delay/drift as it starts turning on/off the above (i.e. it will not be instant). Hence, adjust performance in those transitions, you'll need to modify ekf2's baro, gps, and mag ```*_GATE``` params accordingly. 

Note PX4 will adopt whatever heading is being derived from the activated sensors (GPS/Mag/vio) to construction its "global frame", so proceeding indoors you *will still be* operating under a global frame coordinate system (will still have a north reference based on last good mag/gps check).

## Reply by Rowan Dempster · 2024-06-20 20:50:24 UTC (in reply to Cliff Wong)

Hi @Cliff-Wong thank you for the response!

In the version of PX4 that Modal is using (commit: https://github.com/modalai/px4-firmware/blob/b5c45bb232afc6a936b8349f4fa0be1efeb17707/src/modules/ekf2/ekf2_params.c) I see MAG_CHECK as:
```
/**
 * Magnetic field strength test selection
 *
 * When set, the EKF checks the strength of the magnetic field
 * to decide whether the magnetometer data is valid.
 * If GPS data is received, the magnetic field is compared to a World
 * Magnetic Model (WMM), otherwise an average value is used.
 * This check is useful to reject occasional hard iron disturbance.
 *
 * @group EKF2
 * @boolean
 */
PARAM_DEFINE_INT32(EKF2_MAG_CHECK, 1);
```

Do you suggest updating the EKF2 code to the more recent version that supports more advanced mag health checks: 
```
EKF2_MAG_CHECK:
      description:
        short: Magnetic field strength test selection
        long: 'Bitmask to set which check is used to decide whether the magnetometer
          data is valid. If GNSS data is received, the magnetic field is compared
          to a World Magnetic Model (WMM), otherwise an average value is used. This
          check is useful to reject occasional hard iron disturbance. Set bits to
          1 to enable checks. Checks enabled by the following bit positions 0 : Magnetic
          field strength. Set tolerance using EKF2_MAG_CHK_STR 1 : Magnetic field
          inclination. Set tolerance using EKF2_MAG_CHK_INC 2 : Wait for GNSS to find
          the theoretical strength and inclination using the WMM'
      type: bitmask
      bit:
        0: Strength (EKF2_MAG_CHK_STR)
        1: Inclination (EKF2_MAG_CHK_INC)
        2: Wait for WMM
      default: 1
      min: 0
      max: 7
    EKF2_MAG_CHK_STR:
      description:
        short: Magnetic field strength check tolerance
        long: Maximum allowed deviation from the expected magnetic field strength
          to pass the check.
      type: float
      default: 0.2
      min: 0.0
      max: 1.0
      unit: gauss
      decimal: 2
    EKF2_MAG_CHK_INC:
      description:
        short: Magnetic field inclination check tolerance
        long: Maximum allowed deviation from the expected magnetic field inclination
          to pass the check.
      type: float
      default: 20.0
      min: 0.0
      max: 90.0
      unit: deg
      decimal: 1
```

What we are worried about is the mag being used when the measurements are unhealthy.

## Reply by Eric Katzfey (ModalAI staff) · 2024-06-21 16:21:14 UTC (in reply to Rowan Dempster)

@Rowan-Dempster Mainline PX4 now works on VOXL 2. It hasn't received that much testing yet but you are welcome to try it out.

## Reply by Sarika Sharma · 2026-02-27 06:59:32 UTC (in reply to Eric Katzfey)

Hii @Eric-Katzfey we wanted to confirm whether ModalAI has a recommended parameter set or procedure to achieve a smooth transition between outdoor and indoor flight on VOXL 2 mini ??

## Reply by Eric Katzfey (ModalAI staff) · 2026-02-27 15:55:31 UTC (in reply to Sarika Sharma)

@Sarika-Sharma We have a variety of parameters sets available in the voxl-px4-params repo https://gitlab.com/voxl-public/voxl-sdk/utilities/voxl-px4-params/ However, they are mostly for either indoor or outdoor use. Older versions of PX4, like what our fork is based off of, had a hard time with external vision based navigation coexisting with GPS based navigation. Newer versions of PX4, supposedly, are much better at this but we have not spent the time to prepare a parameter set for that yet. You are free to experiment with our mainline PX4 build here: http://voxl-packages.modalai.com/dists/qrb5165/dev/binary-arm64/voxl-mainline-px4_1.17.0-1.0.2-202602240859_arm64.deb. However, if you decide to use the mainline build, be aware that it is considered "experimental" at this point and has very little testing on voxl2 so use extreme caution.

## Reply by Sarika Sharma · 2026-03-16 06:09:12 UTC (in reply to Eric Katzfey)

Hii @Eric-Katzfey , 
I am trying to install the **voxl-mainline-px4** package on a **VOXL2 Mini (M0104)** running **VOXL SDK 1.6.3**.

The installation fails due to a dependency on a newer version of `libfc-sensor`.

### System information

* Hardware: VOXL2 Mini (M0104)
* SDK: 1.6.3
* Installed library:

```
libfc-sensor 1.0.9
```

### Command used

```
sudo dpkg -i voxl-mainline-px4_1.17.0-1.0.2-202602240859_arm64.deb
```

### Error

```
voxl-mainline-px4 depends on libfc-sensor (>= 1.0.10); however:
Version of libfc-sensor on system is 1.0.9.
```

### Package metadata

Running `dpkg -s voxl-mainline-px4` shows:

```
Depends:
libfc-sensor (>= 1.0.10),
voxl-px4-params (>= 0.3.10),
voxl2-system-image (>= 1.5.4),
modalai-slpi (>= 1.1.16)
```

### Repository check

The SDK repository only provides:

```
libfc-sensor 1.0.9
```

```
apt-cache policy libfc-sensor
Installed: 1.0.9
Candidate: 1.0.9
```

### Question

How to solve this issue???

Thanks.

## Reply by Eric Katzfey (ModalAI staff) · 2026-03-16 16:18:55 UTC (in reply to Sarika Sharma)

@Sarika-Sharma You can get v1.0.10 here: http://voxl-packages.modalai.com/dists/qrb5165/dev/binary-arm64/libfc-sensor_1.0.10-202602041609_arm64.deb
