Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayitzin committed Oct 1, 2024
2 parents 62c1717 + cfaf62c commit 5eb7190
Show file tree
Hide file tree
Showing 35 changed files with 2,209 additions and 603 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.DS_Store
build/*
dist/*
*/.ipynb_checkpoints/*

# test-related
.coverage
Expand All @@ -20,6 +21,7 @@ dist/*
# developer environments
.idea
.vscode
.env

# Documentation
doctest/*
Expand Down
44 changes: 10 additions & 34 deletions ahrs/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
**Geodesy**
The following constants are set as defined in the latest report of the World
Geodetic System 1984 [WGS84]_ and can be compared against [Chambat]_. The
CODATA constants are differentiated with a suffix of their origin indicating
their epoch as of [CODATA2014]_ or [CODATA2018]_.
Geodetic System 1984 :cite:p:`wgs84-2014` and can be compared against
:cite:p:`chambat2001`. The CODATA constants :cite:p:`mohr2016` and
:cite:p:`tiesinga2021` are differentiated with an ending indicating their epoch
as ``CODATA2014`` and ``CODATA2018`` respectively.
==================================== ============================================== =============
Name Description Value
Expand Down Expand Up @@ -67,9 +68,9 @@
``UNIVERSAL_GRAVITATION_WGS84`` Universal Gravitation defined in WGS84 ``6.67428e-11``
==================================== ============================================== =============
The values above are set as defined in [WGS84]_, although most of these values
can be also obtained with the class ``WGS`` of this package, which builds the
World's Geodetic System independently.
The values above are set as defined in :cite:p:`wgs84-2014`, although most of
these values can be also obtained with the class ``WGS`` of this package, which
builds the World's Geodetic System independently.
The elemental defining parameters (equatorial radius, flattening, gravitational
constant and rotational velocity) are set, by default, to that of Earth's, and
Expand All @@ -93,8 +94,9 @@
0.0066943799901413165
These values are, so far, determined for the Earth. However, other celestial
bodies have been measured and their values are, as defined in [Archinal]_,
[Park]_ and [Williams]_, set as follows:
bodies have been measured and their values are, as defined in
:cite:p:`archinal2018`, :cite:p:`park2019` and :cite:p:`williams2024`, set as
follows:
========================== ==========================
Name Value
Expand Down Expand Up @@ -145,32 +147,6 @@
``PLUTO_MASS`` ``1.303e22``
========================== ==========================
References
----------
.. [WGS84] World Geodetic System 1984. Its Definition and Relationships with
Local Geodetic Systems. National Geospatial-Intelligence Agency (NGA)
Standarization Document. 2014.
(ftp://ftp.nga.mil/pub2/gandg/website/wgs84/NGA.STND.0036_1.0.0_WGS84.pdf)
.. [Chambat] F. Chambat. Mean radius, mass, and inertia for reference Earth
models. Physics of the Earth and Planetary Interiors Vol 124 (2001)
p237–253.
.. [Archinal] Archinal, B.A. et al. 2018. "Report of the IAU/IAG Working Group
on cartographic coordinates and rotational elements: 2015" Celestial Mech.
Dyn. Astr. 130:22.
(https://astropedia.astrogeology.usgs.gov/download/Docs/WGCCRE/WGCCRE2015reprint.pdf)
.. [CODATA2018] 2018 CODATA Recommended Values of the Fundamental Constants of
Physics and Chemistry. NIST. June 2019.
(https://physics.nist.gov/cuu/pdf/wallet_2018.pdf)
.. [CODATA2014] 2014 CODATA Recommended Values of the Fundamental Constants of
Physics and Chemistry. NIST. August 2015.
(https://physics.nist.gov/cuu/pdf/wallet_2014.pdf)
.. [Park] Ryan S. Park. Planets and Pluto: Physical Characteristics. NASA Jet
Propulsion Laboratory. California Institute of Technology. 29th May 2020.
(https://ssd.jpl.nasa.gov/?planet_phys_par)
.. [Williams] David R. Williams. Planetary Fact Sheet - Metric. NASA Goddard
Space Flight Center. 21st October 2019.
(https://nssdc.gsfc.nasa.gov/planetary/factsheet/)
"""

import math
Expand Down
70 changes: 22 additions & 48 deletions ahrs/common/dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
rotation matrix in :math:`SO(3)`.
`Direction cosines <https://en.wikipedia.org/wiki/Direction_cosine>`_ are
cosines of angles between a vector and a base coordinate frame [WikipediaDCM]_.
In this case, the direction cosines describe the differences between orthogonal
vectors :math:`\\mathbf{r}_i` and the base frame. The matrix containing these
differences is commonly named the **Direction Cosine Matrix**.
cosines of angles between a vector and a base coordinate frame
:cite:p:`Wiki_DirectionCosine`. In this case, the direction cosines describe
the differences between orthogonal vectors :math:`\\mathbf{r}_i` and the base
frame. The matrix containing these differences is commonly named the
**Direction Cosine Matrix**.
These matrices are used for two main purposes:
Expand All @@ -72,32 +73,12 @@
Because of the latter, the DCM is also known as the **rotation matrix**.
DCMs are, therefore, the most common representation of rotations
[WikipediaRotMat]_, especially in real applications of spacecraft tracking and
location.
:cite:p:`Wolfram_RotationMatrix`, especially in real applications of spacecraft
tracking and location.
Throughout this package they will be used to represent the attitudes with
respect to the global frame.
References
----------
.. [WikipediaDCM] Wikipedia: Direction Cosine.
(https://en.wikipedia.org/wiki/Direction_cosine)
.. [WikipediaRotMat] Wikipedia: Rotation Matrix
(https://mathworld.wolfram.com/RotationMatrix.html)
.. [Ma] Yi Ma, Stefano Soatto, Jana Kosecka, and S. Shankar Sastry. An
Invitation to 3-D Vision: From Images to Geometric Models. Springer
Verlag. 2003.
(https://www.eecis.udel.edu/~cer/arv/readings/old_mkss.pdf)
.. [Huyhn] Huynh, D.Q. Metrics for 3D Rotations: Comparison and Analysis. J
Math Imaging Vis 35, 155–164 (2009).
.. [Curtis] Howard D Curtis. Orbital Mechanics for Engineering Students (Third
Edition) Butterworth-Heinemann. 2014.
.. [Kuipers] Kuipers, Jack B. Quaternions and Rotation Sequences: A Primer with
Applications to Orbits, Aerospace and Virtual Reality. Princeton;
Oxford: Princeton University Press, 1999.
.. [Diebel] Diebel, James. Representing Attitude; Euler Angles, Unit
Quaternions, and Rotation. Stanford University. 20 October 2006.
"""

from typing import Tuple
Expand Down Expand Up @@ -338,6 +319,7 @@ class DCM(np.ndarray):
All DCM are created as an identity matrix, which means no rotation.
>>> from ahrs import DCM
>>> from ahrs import DEG2RAD
>>> DCM()
DCM([[1., 0., 0.],
[0., 1., 0.],
Expand All @@ -346,23 +328,23 @@ class DCM(np.ndarray):
A rotation around a single axis can be defined by giving the desired axis
and its value, in degrees.
>>> DCM(x=10.0)
>>> DCM(x=10.0*DEG2RAD)
DCM([[ 1. , 0. , 0. ],
[ 0. , 0.98480775, -0.17364818],
[ 0. , 0.17364818, 0.98480775]])
>>> DCM(y=20.0)
>>> DCM(y=20.0*DEG2RAD)
DCM([[ 0.93969262, 0. , 0.34202014],
[ 0. , 1. , 0. ],
[-0.34202014, 0. , 0.93969262]])
>>> DCM(z=30.0)
>>> DCM(z=30.0*DEG2RAD)
DCM([[ 0.8660254, -0.5 , 0. ],
[ 0.5 , 0.8660254, 0. ],
[ 0. , 0. , 1. ]])
If we want a rotation conforming the roll-pitch-yaw sequence, we can give
the corresponding angles.
>>> DCM(rpy=[30.0, 20.0, 10.0])
>>> DCM(rpy=np.array([30.0, 20.0, 10.0])*DEG2RAD)
DCM([[ 0.81379768, -0.44096961, 0.37852231],
[ 0.46984631, 0.88256412, 0.01802831],
[-0.34202014, 0.16317591, 0.92541658]])
Expand All @@ -371,7 +353,7 @@ class DCM(np.ndarray):
Notice the angles are given in reverse order, as it is the way the
matrices are multiplied.
>>> DCM(z=30.0) @ DCM(y=20.0) @ DCM(x=10.0)
>>> DCM(z=30.0*DEG2RAD) @ DCM(y=20.0*DEG2RAD) @ DCM(x=10.0*DEG2RAD)
DCM([[ 0.81379768, -0.44096961, 0.37852231],
[ 0.46984631, 0.88256412, 0.01802831],
[-0.34202014, 0.16317591, 0.92541658]])
Expand All @@ -380,11 +362,11 @@ class DCM(np.ndarray):
elements: the order of the axis to rotate about, and the value of the
rotation angles (again in reverse order)
>>> DCM(euler=('zyz', [40.0, 50.0, 60.0]))
>>> DCM(euler=('zyz', np.array([40.0, 50.0, 60.0])*DEG2RAD))
DCM([[-0.31046846, -0.74782807, 0.58682409],
[ 0.8700019 , 0.02520139, 0.49240388],
[-0.38302222, 0.66341395, 0.64278761]])
>>> DCM(z=40.0) @ DCM(y=50.0) @ DCM(z=60.0)
>>> DCM(z=40.0*DEG2RAD) @ DCM(y=50.0*DEG2RAD) @ DCM(z=60.0*DEG2RAD)
DCM([[-0.31046846, -0.74782807, 0.58682409],
[ 0.8700019 , 0.02520139, 0.49240388],
[-0.38302222, 0.66341395, 0.64278761]])
Expand All @@ -402,7 +384,7 @@ class DCM(np.ndarray):
Finally, we can also build the rotation matrix from an axis-angle
representation:
>>> DCM(axang=([1., 2., 3.], 60.0))
>>> DCM(axang=([1., 2., 3.], 60.0*DEG2RAD))
DCM([[-0.81295491, 0.52330834, 0.25544608],
[ 0.03452394, -0.3945807 , 0.91821249],
[ 0.58130234, 0.75528436, 0.30270965]])
Expand Down Expand Up @@ -623,7 +605,7 @@ def log(self) -> np.ndarray:
Logarithm of DCM.
The logarithmic map is defined as the inverse of the exponential map
[Cardoso]_ . It corresponds to the logarithm given by the Rodrigues
:cite:p:`cardoso2009`. It corresponds to the logarithm given by the Rodrigues
rotation formula:
.. math::
Expand Down Expand Up @@ -658,14 +640,6 @@ def log(self) -> np.ndarray:
[-0.26026043, 0. , 0.5473806 ],
[-0.29531805, -0.5473806 , 0. ]])
Reference
---------
.. [Cardoso] J. Cardoso and F. Silva Leite. Exponentials of
skew-symmetric matrices and logarithms of orthogonal matrices.
Journal of Computational and Applied Mathematics. Volume 233, Issue
11, 1 April 2010, Pages 2867-2875.
(https://www.sciencedirect.com/science/article/pii/S0377042709007791)
"""
trace_R = self.A.trace()
if np.isclose(trace_R, 3.0):
Expand Down Expand Up @@ -1039,14 +1013,14 @@ def to_quaternion(self, method: str='shepperd', **kw) -> np.ndarray:
There are five methods available to obtain a quaternion from a
Direction Cosine Matrix:
* ``'shepperd'`` as described in [Chiaverini]_.
* ``'hughes'`` as described in [Hughes]_.
* ``'itzhack'`` as described in [Bar-Itzhack]_ using version ``3`` by
* ``'chiaverini'`` as described in :cite:p:`Chiaverini1999`.
* ``'hughes'`` as described in :cite:p:`hughes1986spacecraft17`.
* ``'itzhack'`` as described in :cite:p:`BarItzhack2000` using version ``3`` by
default. Possible options are integers ``1``, ``2`` or ``3``.
* ``'sarabandi'`` as described in [Sarabandi]_ with a threshold equal
* ``'sarabandi'`` as described in :cite:p:`sarabandi2019` with a threshold equal
to ``0.0`` by default. Possible threshold values are floats between
``-3.0`` and ``3.0``.
* ``'shepperd'`` as described in [Shepperd]_.
* ``'shepperd'`` as described in :cite:p:`shepperd1978`.
Parameters
----------
Expand Down
7 changes: 2 additions & 5 deletions ahrs/common/mathfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def sind(x):

def skew(x):
"""
Return the 3-by-3 skew-symmetric matrix [Wiki_skew]_ of a 3-element vector x.
Return the 3-by-3 skew-symmetric matrix :cite:p:`Wiki_skew` of a 3-element
vector ``x``.
Parameters
----------
Expand All @@ -102,10 +103,6 @@ def skew(x):
[ 6. 0. -4.]
[-5. 4. 0.]]
References
----------
.. [Wiki_skew] https://en.wikipedia.org/wiki/Skew-symmetric_matrix
"""
if isinstance(x, (list, tuple, np.ndarray)):
x = np.copy(x)
Expand Down
Loading

0 comments on commit 5eb7190

Please sign in to comment.