opengnc.attitude_determination package

Submodules

opengnc.attitude_determination.davenport_q module

Davenport’s q-method for optimal attitude determination (Wahba’s problem).

opengnc.attitude_determination.davenport_q.davenport_q(body_vectors: ndarray, ref_vectors: ndarray, weights: ndarray | None = None) ndarray[source]

Solve for the optimal attitude quaternion using Davenport’s q-method.

The optimal quaternion $mathbf{q}$ is the eigenvector corresponding to the maximum eigenvalue $lambda_{max}$ of the Davenport K-matrix: $mathbf{K} mathbf{q} = lambda mathbf{q}$

Parameters:
  • body_vectors (np.ndarray) – Measured body vectors (N, 3).

  • ref_vectors (np.ndarray) – Reference inertial vectors (N, 3).

  • weights (np.ndarray | None, optional) – Weights for observations (N,).

Returns:

Optimal normalized quaternion $[x, y, z, w]$.

Return type:

np.ndarray

Raises:

ValueError – On dimension mismatch.

opengnc.attitude_determination.foam module

Fast Optimal Attitude Matrix (FOAM) algorithm for attitude determination.

opengnc.attitude_determination.foam.foam(body_vectors: ndarray, ref_vectors: ndarray, weights: ndarray | None = None, tol: float = 1e-12, max_iter: int = 20) ndarray[source]

Solve for the optimal attitude matrix using FOAM.

Directly computes the DCM: $mathbf{R}_{BI} = frac{(lambda^2 + |mathbf{B}|_F^2)mathbf{B} + 2lambda text{adj}(mathbf{B})^T - 2mathbf{B} mathbf{B}^T mathbf{B}}{lambda(lambda^2 - |mathbf{B}|_F^2) - 2 det(mathbf{B})}$

Parameters:
  • body_vectors (np.ndarray) – Body measurements (N, 3).

  • ref_vectors (np.ndarray) – Inertial references (N, 3).

  • weights (np.ndarray | None, optional) – Weights (N,).

  • tol (float, optional) – Tolerance. Default 1e-12.

  • max_iter (int, optional) – Max iterations. Default 20.

Returns:

Optimal $3 times 3$ DCM $mathbf{R}_{BI}$.

Return type:

np.ndarray

opengnc.attitude_determination.quest module

QUEST algorithm for optimal attitude determination (Wahba’s problem).

opengnc.attitude_determination.quest.quest(body_vectors: ndarray, ref_vectors: ndarray, weights: ndarray | None = None, tol: float = 1e-12, max_iter: int = 20) ndarray[source]

Solve for the optimal attitude quaternion using QUEST.

QUEST (QUaternion ESTimator) minimizes Wahba’s Loss: $J(mathbf{R}) = frac{1}{2} sum_{i=1}^N w_i |mathbf{b}_i - mathbf{R} mathbf{r}_i|^2$

It achieves this by finding the maximum eigenvalue of the K-matrix: $mathbf{K} mathbf{q}_{opt} = lambda_{max} mathbf{q}_{opt}$

Parameters:
  • body_vectors (np.ndarray) – Body-frame measurements (N, 3).

  • ref_vectors (np.ndarray) – Inertial-frame references (N, 3).

  • weights (np.ndarray | None, optional) – Weights for observations (N,).

  • tol (float, optional) – Newton convergence tolerance. Default 1e-12.

  • max_iter (int, optional) – Max iterations. Default 20.

Returns:

Hamilton quaternion $[x, y, z, w]$ (Inertial $to$ Body).

Return type:

np.ndarray

Raises:

ValueError – On dimension mismatch.

opengnc.attitude_determination.request module

Recursive QUEST (REQUEST) algorithm for recursive attitude estimation.

class opengnc.attitude_determination.request.RequestFilter(initial_k: ndarray | None = None, **kwargs: Any)[source]

Bases: object

Recursive QUEST (REQUEST) filter.

Enables recursive attitude estimation by updating the Davenport K-matrix with a fading memory factor $rho$: $mathbf{K}_k = rho mathbf{K}_{k-1} + delta mathbf{K}_k$

Parameters:

initial_k (np.ndarray | None, optional) – Initial $4 times 4$ K-matrix. Default zero.

property K: ndarray

Alias for the accumulated $4 times 4$ K-matrix.

get_quaternion() ndarray[source]

Extract the optimal normalized quaternion from the current K-matrix.

Returns:

Optimal quaternion $[x, y, z, w]$ (Inertial -> Body).

Return type:

np.ndarray

update(body_vectors: ndarray, ref_vectors: ndarray, weights: ndarray | None = None, rho: float = 1.0) ndarray[source]

Update the accumulated K-matrix with new vector observations.

Parameters:
  • body_vectors (np.ndarray) – New measurements in the body frame (N, 3).

  • ref_vectors (np.ndarray) – Corresponding reference vectors in the inertial frame (N, 3).

  • weights (np.ndarray, optional) – Weights for the new measurements. Defaults to $1/N$.

  • rho (float, optional) – Fading memory factor $0 < \rho \le 1$. Default is 1.0 (no fading).

Returns:

The updated $4\times 4$ K-matrix.

Return type:

np.ndarray

opengnc.attitude_determination.request.request(body_vectors: ndarray, ref_vectors: ndarray, weights: ndarray | None = None, initial_k: ndarray | None = None, rho: float = 1.0) ndarray[source]

One-shot REQUEST update helper.

Parameters:
  • body_vectors (np.ndarray) – New measurements in the body frame (N, 3).

  • ref_vectors (np.ndarray) – Reference vectors in the inertial frame (N, 3).

  • weights (np.ndarray, optional) – Weights for new measurements.

  • initial_k (np.ndarray, optional) – Starting K-matrix.

  • rho (float, optional) – Fading memory factor.

Returns:

Optimal quaternion $[x, y, z, w]$.

Return type:

np.ndarray

opengnc.attitude_determination.triad module

TRIAD algorithm for attitude determination from two vectors.

opengnc.attitude_determination.triad.triad(v_body1: ndarray, v_body2: ndarray, v_ref1: ndarray, v_ref2: ndarray) ndarray[source]

Compute the DCM from reference to body frame using TRIAD.

TRIAD (Tri-Axial Attitude Determination) construction: - $mathbf{t}_{1b} = mathbf{b}_1$ - $mathbf{t}_{2b} = frac{mathbf{b}_1 times mathbf{b}_2}{|mathbf{b}_1 times mathbf{b}_2|}$ - $mathbf{t}_{3b} = mathbf{t}_{1b} times mathbf{t}_{2b}$

The Direction Cosine Matrix is: $mathbf{R}_{BI} = [mathbf{t}_{1b}mathbf{t}_{2b}mathbf{t}_{3b}] [mathbf{t}_{1r}mathbf{t}_{2r}mathbf{t}_{3r}]^T$

Parameters:
  • v_body1 (np.ndarray) – Primary body vector (3,).

  • v_body2 (np.ndarray) – Secondary body vector (3,).

  • v_ref1 (np.ndarray) – Primary reference vector (3,).

  • v_ref2 (np.ndarray) – Secondary reference vector (3,).

Returns:

$3 times 3$ DCM $mathbf{R}_{BI}$ (Reference $to$ Body).

Return type:

np.ndarray

Raises:

ValueError – If vectors are collinear or zero-length.

Module contents