WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
clockwerk::Quaternion Class Reference

Quaternion class for attitude representation. More...

#include <Quaternion.h>

Inheritance diagram for clockwerk::Quaternion:

Public Member Functions

 Quaternion ()
 Default constructor generates Quaternion sequence as zero rotation – 1 0 0 0.
 Quaternion (const floating_point(&initial)[QUATERNION_NUM_ELEMENTS])
 Quaternion (const Quaternion &initial)
 Quaternion (const std::array< floating_point, QUATERNION_NUM_ELEMENTS > &initial)
 ~Quaternion ()
Quaternionoperator= (const Quaternion &other)
 Equals operator overload for quaternion.
Quaternion operator* (const Quaternion &other) const
 Multiplication operator overload for quaternion to quaternion multiplication.
CartesianVector< 3 > operator* (const CartesianVector< 3 > &vec__f2) const
 Multiplication operator overload for rotating a vector in frame 2 by a quat_f1_f2.
void rate (const CartesianVector< 3 > &omega_f1_f2__f1, Matrix< QUATERNION_NUM_ELEMENTS, 1 > &quatdot_f1_f2) const
 Function to calculate the rate of change in the current representation based on the omega vector.
void rate (const Matrix< 3, 1 > &omega_f1_f2__f1, Matrix< QUATERNION_NUM_ELEMENTS, 1 > &quatdot_f1_f2) const
void toDCM (DCM &dcm_f1_f2) const
 Function to convert current attitude to DCM.
DCM toDCM () const
void toMRP (MRP &mrp_f1_f2) const
 Function to convert current attitude to MRP.
MRP toMRP () const
int16 rotationAngle (floating_point &val) const
 Calculate the rotation angle represented by the quaternion.
floating_point rotationAngle () const
void inverse (Quaternion &quat_f2_f1) const
 Function to convert quaternion rotation to inverse quaternion (assumes unit quaternion and outputs its conjugate).
Quaternion inverse () const
void dRate_dOmega (Matrix< QUATERNION_NUM_ELEMENTS, 3 > &jacobian) const
 Function to compute the partial derivative of dq/dt (Quaternion::rate) with respect to omega_f1_f2__f1.
Matrix< QUATERNION_NUM_ELEMENTS, 3 > dRate_dOmega () const
void dRate_dQuat (const CartesianVector< 3 > &omega_f1_f2__f1, Matrix< QUATERNION_NUM_ELEMENTS, QUATERNION_NUM_ELEMENTS > &jacobian) const
 Function to compute the partial derivative of dq/dt (Quaternion::rate) with respect to quat_f1_f2.
Matrix< QUATERNION_NUM_ELEMENTS, QUATERNION_NUM_ELEMENTSdRate_dQuat (const CartesianVector< 3 > &omega_f1_f2__f1) const
void dRotatedVec_dQuat (const CartesianVector< 3 > &vec__f2, Matrix< 3, QUATERNION_NUM_ELEMENTS > &jacobian) const
 Function to compute the partial derivative of quat_f1_f2*vec__f2 with respect to quat_f1_f2.
Matrix< 3, QUATERNION_NUM_ELEMENTSdRotatedVec_dQuat (const CartesianVector< 3 > &vec__f2) const
void dInvRotatedVec_dQuat (const CartesianVector< 3 > &vec__f1, Matrix< 3, QUATERNION_NUM_ELEMENTS > &jacobian) const
 Function to compute the partial derivative of quat_f2_f1*vec__f1 with respect to quat_f1_f2 (note the inverse quaternion).
Matrix< 3, QUATERNION_NUM_ELEMENTSdInvRotatedVec_dQuat (const CartesianVector< 3 > &vec__f1) const
Public Member Functions inherited from clockwerk::CartesianVector< QUATERNION_NUM_ELEMENTS >
 CartesianVector ()
 ~CartesianVector ()
floating_point & operator[] (uint32 idx)
 Function to return a vector value.
int set (uint32 idx, floating_point value)
 Setter specific to the vector class.
int get (uint32 idx, floating_point &result) const
 Getter specific to the vector class.
int16 norm (floating_point &result) const
 Function to take the norm of a vector.
int16 normSquared (floating_point &result) const
 Function to take the squared norm of a vector.
int16 unit (CartesianVector< L > &result) const
 Function to return the unitized version of the vector.
int16 unitize ()
 Function to unitize the current vector.
int16 normalize ()
 Function to unitize the current vector.
Public Member Functions inherited from clockwerk::Matrix< L, 1 >
 Matrix ()
 Default constructor to initialize a matrix to all zeroes for ease of use.
 ~Matrix ()
int16 str (char *output, size_t size) const
 Function to dump information on matrix.
int16 fromStr (const char *val)
 Set value of matrix from string in same format as str().
int16 set (uint32 row, uint32 col, const floating_point &value)
 Function to set a single value in the matrix.
int16 get (uint32 row, uint32 col, floating_point &result) const
 Function to get a single value in the matrix.
void setFromArray (const floating_point *start_ptr, bool column_major=false)
 Function to set the values of the matrix row-wise.
void getAsArray (floating_point *start_ptr, bool column_major=false) const
 Function to get the values of the matrix row-wise.
void getCopy (Matrix< R, C > &result) const
 Function to get a copy of the matrix.
Matrix< R, C > & operator= (const Matrix< R, C > &other)
 Equals operator overload for matrix.
floating_point * operator[] (uint32 idx)
 Function to return a matrix row or vector value.
std::pair< uint32, uint32 > size () const
 Function to get the size of the matrix.
void max (floating_point &result, std::pair< uint32, uint32 > &index) const
 Function to return the maximum value in the matrix.
void min (floating_point &result, std::pair< uint32, uint32 > &index) const
 Function to return the minimum value in the matrix.
int16 det (floating_point &result) const
 Function to return the determinant of the matrix.
int16 chol (Matrix< R, C > &retval) const
 Take the cholesky decomposition of this matrix.
int16 inverse (Matrix< R, C > &result) const
 Function to return the inverse of the matrix.
int16 pseudoinverse (Matrix< C, R > &result) const
void transpose (Matrix< C, R > &result) const
 Function to return the transpose of the matrix.
int16 trace (floating_point &result) const
 Function to return the trace of the matrix.
void setToZeros ()
 Function to set all elements of the matrix to zero.
int16 identity ()
 Function to set matrix to identity, if it is a square matrix.
int16 eye ()

Additional Inherited Members

Public Attributes inherited from clockwerk::Matrix< L, 1 >
std::array< std::array< floating_point, C >, R > values
Protected Member Functions inherited from clockwerk::Matrix< L, 1 >
int16 _checkLookupBoundaries (uint32 start_r, uint32 end_r, uint32 start_c, uint32 end_c) const
int16 _LUPDecompose (floating_point *A[R], uint32 P[R+1]) const
 Function to take a 2-d matrix represented by A and decompose it into LU form.

Detailed Description

Quaternion class for attitude representation.

This file defines a simple Quaternion attitude representation for cartesian coordinate systems. It is largely the same as the base vector, with the following exceptions:

  • Set to be 4 elements
  • Functions defined to convert to other attitude representations
  • Function defined to calculate rate of change as a function of omega

Naming conventions

  • All naming conventions and equations are per Analytical Mechanics of Space Systems by Schaub and Junkins
  • The omega vector is sometimes denoted by w and assumed frame consistent with the attitude representation. For example, if a DCM represents the relative orientation between two frames [BN] the omega vector is assumed to be w_(B/N)
  • The naming convention for all vectors is: variablename_obj1_obj2__frameN (note the double underscore preceding frame) and reads back as: "variable variablename representing the relationship between obj1 and obj2 represented in frameN"
  • Unless otherwise noted angles are in RADIANS

NOTE: All attitude representations, including DCMs, are assumed to represent a three dimensional, cartesian coordinate system because that is what they are used, and in many cases defined, for. NOTE: The math in this class assumes a unit quaternion.

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

clockwerk::Quaternion::Quaternion ( )

Default constructor generates Quaternion sequence as zero rotation – 1 0 0 0.

◆ Quaternion() [2/4]

clockwerk::Quaternion::Quaternion ( const floating_point(&) initial[QUATERNION_NUM_ELEMENTS])

Constructor for Matrix class with initialization. Initializes matrix to values passed in via array

◆ Quaternion() [3/4]

clockwerk::Quaternion::Quaternion ( const Quaternion & initial)

Copy constructor for Quaternion class. Copies data from Quaternion object to the current instance

◆ Quaternion() [4/4]

clockwerk::Quaternion::Quaternion ( const std::array< floating_point, QUATERNION_NUM_ELEMENTS > & initial)

Constructor for Matrix class with initialization. Initializes matrix to values passed in via array

◆ ~Quaternion()

clockwerk::Quaternion::~Quaternion ( )
inline

Destructor – doesn't do anything because we don't dynamically allocate

Member Function Documentation

◆ dInvRotatedVec_dQuat() [1/2]

Matrix< 3, QUATERNION_NUM_ELEMENTS > clockwerk::Quaternion::dInvRotatedVec_dQuat ( const CartesianVector< 3 > & vec__f1) const

◆ dInvRotatedVec_dQuat() [2/2]

void clockwerk::Quaternion::dInvRotatedVec_dQuat ( const CartesianVector< 3 > & vec__f1,
Matrix< 3, QUATERNION_NUM_ELEMENTS > & jacobian ) const

Function to compute the partial derivative of quat_f2_f1*vec__f1 with respect to quat_f1_f2 (note the inverse quaternion).

Parameters
vec__f1Vector that would be rotated by the inverse quaternion
jacobianImplicif return of the partial derivative
Returns
Error code corresponding to success/failure

◆ dRate_dOmega() [1/2]

Matrix< QUATERNION_NUM_ELEMENTS, 3 > clockwerk::Quaternion::dRate_dOmega ( ) const

◆ dRate_dOmega() [2/2]

void clockwerk::Quaternion::dRate_dOmega ( Matrix< QUATERNION_NUM_ELEMENTS, 3 > & jacobian) const

Function to compute the partial derivative of dq/dt (Quaternion::rate) with respect to omega_f1_f2__f1.

Parameters
jacobianImplicit return of the matrix function denoted as E^T in section 1.5.3 of "Quaternions and Dynamics" by Basile Graf
Returns
Error code corresponding to success/failure

◆ dRate_dQuat() [1/2]

Matrix< QUATERNION_NUM_ELEMENTS, QUATERNION_NUM_ELEMENTS > clockwerk::Quaternion::dRate_dQuat ( const CartesianVector< 3 > & omega_f1_f2__f1) const

◆ dRate_dQuat() [2/2]

void clockwerk::Quaternion::dRate_dQuat ( const CartesianVector< 3 > & omega_f1_f2__f1,
Matrix< QUATERNION_NUM_ELEMENTS, QUATERNION_NUM_ELEMENTS > & jacobian ) const

Function to compute the partial derivative of dq/dt (Quaternion::rate) with respect to quat_f1_f2.

Parameters
omega_f1_f2__f1Angular velocity for the attitude representation - omega of frame 1 wrt frame 2 expressed in frame 1
jacobianImplicit return of the matrix function denoted as G^T in section 1.5.4 of "Quaternions and Dynamics" by Basile Graf
Returns
Error code corresponding to success/failure

◆ dRotatedVec_dQuat() [1/2]

Matrix< 3, QUATERNION_NUM_ELEMENTS > clockwerk::Quaternion::dRotatedVec_dQuat ( const CartesianVector< 3 > & vec__f2) const

◆ dRotatedVec_dQuat() [2/2]

void clockwerk::Quaternion::dRotatedVec_dQuat ( const CartesianVector< 3 > & vec__f2,
Matrix< 3, QUATERNION_NUM_ELEMENTS > & jacobian ) const

Function to compute the partial derivative of quat_f1_f2*vec__f2 with respect to quat_f1_f2.

Parameters
vec__f2Vector that would be rotated by the quaternion
jacobianImplicit return of the partial derivative
Returns
Error code corresponding to success/failure

◆ inverse() [1/2]

Quaternion clockwerk::Quaternion::inverse ( ) const

◆ inverse() [2/2]

void clockwerk::Quaternion::inverse ( Quaternion & quat_f2_f1) const

Function to convert quaternion rotation to inverse quaternion (assumes unit quaternion and outputs its conjugate).


Quaternion Conversions

Parameters
quat_f2_f1return of quaternion representation of the inverse rotation of current quaternion
Returns
Integer error code corresponding to errors in clockwerkerrors.h
Warning
This function is only valid for unit quaternions, make sure to unitize before use

◆ operator*() [1/2]

CartesianVector< 3 > clockwerk::Quaternion::operator* ( const CartesianVector< 3 > & vec__f2) const

Multiplication operator overload for rotating a vector in frame 2 by a quat_f1_f2.

Parameters
vec__f2Vector to be rotated expressed in frame 2
Returns
Vector after rotatin expressed in frame 1

◆ operator*() [2/2]

Quaternion clockwerk::Quaternion::operator* ( const Quaternion & other) const

Multiplication operator overload for quaternion to quaternion multiplication.

Parameters
otherQuaternion to multiply with
Returns
Quaternion mutiplication result

◆ operator=()

Quaternion & clockwerk::Quaternion::operator= ( const Quaternion & other)

Equals operator overload for quaternion.

◆ rate() [1/2]

void clockwerk::Quaternion::rate ( const CartesianVector< 3 > & omega_f1_f2__f1,
Matrix< QUATERNION_NUM_ELEMENTS, 1 > & quatdot_f1_f2 ) const

Function to calculate the rate of change in the current representation based on the omega vector.


Dynamics and kinematics functions

Parameters
omega_f1_f2__f1Angular velocity vector for the attitude representation - omega of frame 1 wrt frame 2 expressed in frame 1
quatdot_f1_f2Rate of change in the current Quaternion

◆ rate() [2/2]

void clockwerk::Quaternion::rate ( const Matrix< 3, 1 > & omega_f1_f2__f1,
Matrix< QUATERNION_NUM_ELEMENTS, 1 > & quatdot_f1_f2 ) const

◆ rotationAngle() [1/2]

floating_point clockwerk::Quaternion::rotationAngle ( ) const

◆ rotationAngle() [2/2]

int16 clockwerk::Quaternion::rotationAngle ( floating_point & val) const

Calculate the rotation angle represented by the quaternion.

Parameters
valImplicit return of rotation angle
Returns
Error code corresponding to success/failure

◆ toDCM() [1/2]

DCM clockwerk::Quaternion::toDCM ( ) const

◆ toDCM() [2/2]

void clockwerk::Quaternion::toDCM ( DCM & dcm_f1_f2) const

Function to convert current attitude to DCM.


Conversions to other attitude representations

Parameters
PBRreturn of DCM in PBR case
Returns
Integer error code corresponding to errors in clockwerkerrors.h

◆ toMRP() [1/2]

MRP clockwerk::Quaternion::toMRP ( ) const

◆ toMRP() [2/2]

void clockwerk::Quaternion::toMRP ( MRP & mrp_f1_f2) const

Function to convert current attitude to MRP.

Parameters
PBRreturn of MRP in PBR case
Returns
Integer error code corresponding to errors in clockwerkerrors.h

The documentation for this class was generated from the following files:
  • /Users/mickey/Documents/Projects/warptwin/warpos/clockwerk/src/dynamics/Quaternion.h
  • /Users/mickey/Documents/Projects/warptwin/warpos/clockwerk/src/dynamics/Quaternion.cpp