Davenport’s q-Method#
In 1965 Grace Wahba came up with a simple, yet very intuitive, way to describe the problem of finding a rotation between two coordinate systems.
Given a set of \(N\) vector measurements \(\mathbf{u}\) in the body coordinate system, an optimal attitude matrix \(\mathbf{A}\) would minimize the loss function:
where \(u_i\) is the i-th vector measurement in the body frame, \(v_i\) is the i-th vector in the reference frame, and \(w_i\) are a set of \(N\) nonnegative weights for each observation. This famous formulation is known as Wahba’s problem.
A first elegant solution was proposed by [Davenport1968] that solves this in terms of quaternions, yielding a unique optimal solution. The corresponding gain function is defined as:
The gain function is at maximum when the loss function \(L(\mathbf{A})\) is at minimum. The goal is, then, to find the optimal attitude matrix \(\mathbf{A}\), which maximizes \(g(\mathbf{A})\). We first notice that:
where \(\mathrm{tr}\) denotes the trace of a matrix, and \(\mathbf{B}\) is the attitude profile matrix:
Now, we must parametrize the attitude matrix in terms of a quaternion \(\mathbf{q}\):
where \(\mathbf{I}_3\) is a \(3\times 3\) identity matrix, and the expression \(\lfloor \mathbf{x}\rfloor_\times\) is the skew-symmetric matrix of a vector \(\mathbf{x}\). See the quaternion page for further details about this representation mapping.
The gain function, in terms of quaternion, becomes:
A simpler expression, using helper quantities, can be a bilinear relationship of the form:
where the \(4\times 4\) matrix \(\mathbf{K}\) is built with:
using the intermediate values:
The optimal quaternion \(\hat{\mathbf{q}}\), which parametrizes the optimal attitude matrix, is an eigenvector of \(\mathbf{K}\). With the help of Lagrange multipliers, \(g(\mathbf{q})\) is maximized if the eigenvector corresponding to the largest eigenvalue \(\lambda\) is chosen.
The biggest disadvantage of this method is its computational load in the last step of computing the eigenvalues and eigenvectors to find the optimal quaternion.
References
Paul B. Davenport. A Vector Approach to the Algebra of Rotations with Applications. NASA Technical Note D-4696. August 1968. (https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19680021122.pdf)
Lerner, G. M. “Three-Axis Attitude Determination” in Spacecraft Attitude Determination and Control, edited by J.R. Wertz. 1978. p. 426-428.
- class ahrs.filters.davenport.Davenport(acc: ndarray | None = None, mag: ndarray | None = None, **kw)#
Davenport’s q-Method for attitude estimation
- Parameters:
acc (numpy.ndarray, default: None) – N-by-3 array with measurements of acceleration in in m/s^2
mag (numpy.ndarray, default: None) – N-by-3 array with measurements of magnetic field in mT
weights (array-like) – Array with two weights used in each observation.
magnetic_dip (float) – Magnetic Inclination angle, in degrees. Defaults to magnetic dip of Munich, Germany.
gravity (float) – Normal gravity, in m/s^2. Defaults to normal gravity in Munich, Germany.
- Variables:
acc (numpy.ndarray) – N-by-3 array with N accelerometer samples.
mag (numpy.ndarray) – N-by-3 array with N magnetometer samples.
w (numpy.ndarray) – Weights of each observation.
- Raises:
ValueError – When dimension of input arrays
acc
andmag
are not equal.
- estimate(acc: ndarray | None = None, mag: ndarray | None = None) ndarray #
Attitude Estimation
- Parameters:
acc (numpy.ndarray) – Sample of tri-axial Accelerometer in m/s^2
mag (numpy.ndarray) – Sample of tri-axial Magnetometer in T
- Returns:
q – Estimated attitude as a quaternion.
- Return type:
numpy.ndarray