Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

MagPoseFactor

Open In Colab

Overview

The MagPoseFactor<POSE> is a templated factor designed to constrain the orientation component of a Pose2 or Pose3 variable using magnetometer readings. It’s similar in purpose to MagFactor1 but operates directly on pose types and explicitly handles an optional transformation between the body frame and the sensor frame.

It assumes the magnetometer calibration parameters (scale, bias) and the local magnetic field direction are known.

Measurement Model

The underlying model is the same as for MagFactor:

bMmeasured=Rbn⋅(s⋅d^n)+bbM_{measured} = R_{bn} \cdot (s \cdot \hat{d}_n) + b

However, MagPoseFactor allows specifying an optional body_P_sensor transform. If provided, the factor internally adjusts the measurement and bias to be consistent with the body frame before calculating the error.

Let:

  • Tnb=(Rnb,pnb)T_{nb} = (R_{nb}, p_{nb}) be the Pose state.

  • TbsT_{bs} be the pose of the sensor in the body frame (body_P_sensor). If not given, TbsT_{bs} is identity.

  • sMmeasuredsM_{measured} be the raw measurement in the sensor frame.

  • sBsB be the bias in the sensor frame.

  • ss, d^n\hat{d}_n be the known scale and nav-frame direction.

The factor computes the predicted measurement in the body frame:

bMpredicted=Rbs[Rsn(s⋅d^n)+sB]bM_{predicted} = R_{bs} [ R_{sn} (s \cdot \hat{d}_n) + sB ]

where Rsn=RsbRbn=RbsT⋅RnbTR_{sn} = R_{sb} R_{bn} = R_{bs}^T \cdot R_{nb}^T.

Alternatively, and perhaps more clearly, it predicts the field in the sensor frame and compares it to the measurement:

sMpredicted=Rsn(s⋅d^n)+sBsM_{predicted} = R_{sn} (s \cdot \hat{d}_n) + sB

e=sMmeasured−sMpredictede = sM_{measured} - sM_{predicted}

The implementation transforms the measurement and bias to the body frame first for efficiency if body_P_sensor is provided. The error ee is calculated in the body frame.

Key Functionality / API

  • Template Parameter: POSE (must be gtsam.Pose2 or gtsam.Pose3).

  • Constructor: MagPoseFactor(poseKey, measured, scale, direction, bias, model, body_P_sensor=None)

    • poseKey: Key of the Pose2 or Pose3 variable.

    • measured: Measured magnetic field vector (Point2 or Point3) in the sensor frame.

    • scale: Known scale factor.

    • direction: Known magnetic field direction (Point2 or Point3) in the navigation frame.

    • bias: Known bias vector (Point2 or Point3) in the sensor frame.

    • model: Noise model (2D or 3D).

    • body_P_sensor: Optional Pose2 or Pose3 describing the sensor’s pose relative to the body frame.

  • evaluateError(nPb): Calculates the error vector (2D or 3D) based on the current pose estimate nPb.

Usage Example (Pose3)

Using a magnetometer to help estimate a Pose3 orientation, assuming known calibration and a sensor offset.

Created MagPoseFactor<Pose3>:
  keys = { x0 }
isotropic dim=3 sigma=50
local field (nM): [35176.3235; 5025.18908; 35176.3235];
measured field (bM): [28523.6117; 5040.18908; 40745.2206];
magnetometer bias: [-10; 15; -5];

Error at ground truth pose (should be zero): [0. 0. 0.]
Error at test pose: [-3660.19475195     0.          2331.80122523]

Important Considerations

  • Frame Consistency: Ensure direction is in the nav frame, while measured and bias are in the sensor frame when body_P_sensor is provided. If body_P_sensor is None, then measured and bias are assumed to be in the body frame.

  • Units: Maintain consistent units (e.g., nT) for scale, bias, measurement, and noise sigma.