brilliant-msg
    Preparing search index...

    Class MagCalibration

    Magnetometer calibration for tilt-compensated heading -- the TypeScript mirror of brilliant_msg/calibration.py's runtime MagCalibration and the Flutter example's mag_calibration.dart.

    Three independent corrections make a worn/tilted compass usable:

    1. Hard-iron offset -- per-axis offset that re-centres the mag sphere. Solvable on-device from a tumble.
    2. Mag/accel alignment matrix -- a 3x3 rotation expressing the magnetometer vector in the accelerometer's body frame. The QMC6308 mag and BMA580 accel are separate parts at different mounting orientations, so their axes do not coincide; tilt compensation needs them in one frame. Solving it needs numpy-class math, so it is produced offline by the Python tool (examples/imu_calibrate.py) and loaded here as JSON.
    3. Heading offset headingOffsetDeg -- a scalar fixing the absolute zero. The tumble constrains tilt but not "north"; set it in the use location (local interference shifts the zero).

    Inputs/outputs use the host frame produced by RxIMU (+X right, +Y forward, +Z up), so this composes with the shipped imu.lua remap. The JSON keys match the Python tool exactly, so a mag_calibration.json loads directly.

    Index

    Constructors

    • Parameters

      • options: { fieldUT?: number; headingOffsetDeg?: number; matrix?: Mat3; offset?: Vec3 } = {}

      Returns MagCalibration

    Properties

    fieldUT: number

    Mean field magnitude (raw units) for optional uT scaling; 0 if unknown.

    headingOffsetDeg: number

    Absolute heading zero correction, degrees.

    matrix: Mat3

    3x3 mag->accel alignment rotation (row-major). Identity = hard-iron only.

    offset: Vec3

    Per-axis hard-iron offset, added to the raw magnetometer (host frame).

    haloDefaultAlignment: Mat3 = ...

    Default Halo mag->accel alignment, used when no per-unit matrix is supplied. The QMC6308 (mag) and BMA580 (accel) dies are mounted at a fixed nominal orientation offset (~90deg about Z plus a small tilt) that is consistent across units, so a fresh calibration ships with it and tilt compensation works before any per-unit calibration; identity leaves a residual tilt error. A per-unit tumble or a loaded calibration JSON overrides it. Keep in sync with Python HALO_DEFAULT_ALIGNMENT / Dart haloDefaultAlignment.

    identity: Mat3 = ...

    Accessors

    • get hasAlignment(): boolean

      Whether an alignment matrix (beyond identity) is present.

      Returns boolean

    Methods

    • m_corrected = matrix @ (m_raw + offset), in the host frame.

      Parameters

      • mx: number
      • my: number
      • mz: number

      Returns Vec3

    • Copy with the given fields replaced (used by tumble / set-North / edits).

      Parameters

      • options: { fieldUT?: number; headingOffsetDeg?: number; matrix?: Mat3; offset?: Vec3 } = {}

      Returns MagCalibration

    • Tilt-compensated magnetic heading (deg, 0-360) from a raw host-frame magnetometer + accelerometer sample. Applies hard-iron, alignment and the heading offset; pass declination to also get a true heading.

      Parameters

      • mx: number
      • my: number
      • mz: number
      • ax: number
      • ay: number
      • az: number
      • declination: number = 0.0

      Returns number