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

Complementary filter for 6-DOF IMUs, implemented as a `BB.Estimator`.

Integrates the gyroscope (high-pass) and blends in an accelerometer-
derived tilt estimate (low-pass) using a fixed weight or a time
constant.

## Usage

    sensor :imu, BB.Sensor.SomeImu, ... do
      estimator :orientation, {BB.Estimator.Ahrs.Complementary, alpha: 0.98}
    end

## Options

- `:alpha` — fixed gyro weight, `0.0..1.0`. Default `0.98` (98% gyro,
  2% accel per update).
- `:time_constant` — optional time constant τ in seconds. When set,
  overrides `:alpha` with `τ / (τ + dt)`, making the filter
  frequency-independent.
- `:accel_threshold` — accepted deviation of `|accel| / g` from `1.0`
  before the correction is suppressed. Default `0.1`.

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

# `t`

```elixir
@type t() :: %BB.Estimator.Ahrs.Complementary{
  accel_threshold: float(),
  alpha: float(),
  last_monotonic_time: integer() | nil,
  q: BB.Estimator.Ahrs.Quaternion.t(),
  time_constant: nil | float()
}
```

# `step`

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

Runs one Complementary filter step.

---

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