# `BB.Estimator.Ahrs.Mahony`
[🔗](https://github.com/beam-bots/bb_estimator_ahrs/blob/main/lib/bb/estimator/ahrs/mahony.ex#L6)

Mahony AHRS filter, 6-DOF IMU variant, implemented as a `BB.Estimator`.

Uses a Proportional-Integral controller to fuse gyroscope and
accelerometer measurements. Computationally cheaper than Madgwick and
particularly robust under sustained drift.

## Usage

    sensor :imu, BB.Sensor.SomeImu, ... do
      estimator :orientation, {BB.Estimator.Ahrs.Mahony, kp: 2.0, ki: 0.005}
    end

## Options

- `:kp` — proportional gain on the accel/mag error vector. Default `2.0`.
- `:ki` — integral gain (gyro bias estimation). Default `0.0` (P-only).
- `:accel_threshold` — accepted deviation of `|accel| / g` from `1.0`
  before the correction is suppressed. Default `0.1`.
- `:e_int_limit` — anti-windup clamp on the integral term. Default `100.0`.

Ported from [gworkman/ahrs](https://github.com/gworkman/ahrs)' `Ahrs.Mahony`.

# `t`

```elixir
@type t() :: %BB.Estimator.Ahrs.Mahony{
  accel_threshold: float(),
  e_int: {float(), float(), float()},
  e_int_limit: float(),
  ki: float(),
  kp: float(),
  last_monotonic_time: integer() | nil,
  q: BB.Estimator.Ahrs.Quaternion.t()
}
```

# `step`

```elixir
@spec step(t(), {float(), float(), float()}, {float(), float(), float()}, float()) ::
  t()
```

Runs one Mahony step. `gyro` is rad/s, `accel` is m/s², `dt` is
seconds. Returns the updated state.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
