BB.Estimator.Ahrs.Quaternion (bb_estimator_ahrs v0.1.0)

Copy Markdown View Source

Scalar (w, x, y, z) quaternion used internally by the AHRS algorithms.

Kept separate from BB.Math.Quaternion (Nx-backed) because the AHRS filters run at hundreds of Hz and the Nx dispatch overhead per operation dominates the actual arithmetic. Conversion to BB.Math.Quaternion happens at each estimator's input / output boundary.

Ported from gworkman/ahrs' Ahrs.Quaternion.

Summary

Functions

Returns the conjugate of a unit quaternion (also its inverse).

Constructs from a BB.Math.Quaternion.

Calculates , the time-derivative of a quaternion under angular velocity (gx, gy, gz) in rad/s. Returns a {ẇ, ẋ, ẏ, ż} 4-tuple.

Identity quaternion (no rotation).

Hamilton-product multiplication. Non-commutative; composes the right-hand rotation first, then the left.

Normalises a quaternion to a unit quaternion. Returns the input unchanged when its norm is zero.

Converts to a BB.Math.Quaternion for use in a message payload.

Types

t()

@type t() :: %BB.Estimator.Ahrs.Quaternion{
  w: float(),
  x: float(),
  y: float(),
  z: float()
}

Functions

conjugate(quaternion)

@spec conjugate(t()) :: t()

Returns the conjugate of a unit quaternion (also its inverse).

from_bb(q)

@spec from_bb(BB.Math.Quaternion.t()) :: t()

Constructs from a BB.Math.Quaternion.

gyro_derivative(quaternion, gx, gy, gz)

@spec gyro_derivative(t(), float(), float(), float()) ::
  {float(), float(), float(), float()}

Calculates , the time-derivative of a quaternion under angular velocity (gx, gy, gz) in rad/s. Returns a {ẇ, ẋ, ẏ, ż} 4-tuple.

identity()

@spec identity() :: t()

Identity quaternion (no rotation).

multiply(quaternion1, quaternion2)

@spec multiply(t(), t()) :: t()

Hamilton-product multiplication. Non-commutative; composes the right-hand rotation first, then the left.

normalise(q)

@spec normalise(t()) :: t()

Normalises a quaternion to a unit quaternion. Returns the input unchanged when its norm is zero.

to_bb(quaternion)

@spec to_bb(t()) :: BB.Math.Quaternion.t()

Converts to a BB.Math.Quaternion for use in a message payload.