ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
clockwerk::DCM< T > Class Template Reference

Class defining a direction cosine matrix inherited from Matrix. More...

#include <DCM.hpp>

Inheritance diagram for clockwerk::DCM< T >:
Collaboration diagram for clockwerk::DCM< T >:

Public Member Functions

 DCM ()
 Default constructor generates DCM as an identity matrix.
 
 DCM (const T(&initial)[3][3])
 Constructor for Matrix class with initialization. Initializes matrix to values passed in via array.
 
 DCM (const DCM< T > &initial)
 Copy constructor for Matrix class. Copies data from matrix object to the current instance.
 
 DCM (const std::array< std::array< T, 3 >, 3 > &initial)
 Constructor for Matrix class with initialization. Initializes matrix to values passed in via array.
 
 ~DCM ()
 Destructor – doesn't do anything because we don't dynamically allocate.
 
int inverse (DCM< T > &result) const
 Function to return the inverse of the matrix.
 
DCM< T > inverse () const
 
void rate (const CartesianVector< T, 3 > &omega_f1_f2__f1, Matrix< T, 3, 3 > &dcmdot_f1_f2)
 Function to calculate the rate of change in the current representation based on the omega vector.
 
int toEuler321 (Euler321< T > &euler_f1_f2) const
 Function to convert current attitude to 321 Euler sequence.
 
Euler321< T > toEuler321 ()
 
int toQuaternion (Quaternion< T > &q_f1_f2) const
 Overloaded functions to convert current attitude to quaternion.
 
Quaternion< T > toQuaternion ()
 
int toMRP (MRP< T > &mrp_f1_f2) const
 Overloaded functions to convert current attitude to MRP.
 
MRP< T > toMRP ()
 
void dump () const
 Function to dump information on matrix.
 
std::string str () const
 Function to dump information on matrix to string.
 
int set (const unsigned int &row, const unsigned int &col, const T &value)
 Function to set a single value in the matrix.
 
int get (const unsigned int &row, const unsigned int &col, T &result) const
 Function to get a single value in the matrix.
 
get (const unsigned int &row, const unsigned int &col) const
 Function to get a single value in the matrix.
 
void setFromArray (const T *start_ptr)
 Function to set the values of the matrix row-wise.
 
void getAsArray (T *start_ptr) const
 Function to get the values of the matrix row-wise.
 
void getCopy (Matrix< T, R, C > &result) const
 Function to get a copy of the matrix.
 
T * operator[] (unsigned int idx)
 Function to return a matrix row or vector value.
 
std::pair< unsigned int, unsigned int > size ()
 Function to get the size of the matrix.
 
void max (T &result, std::pair< unsigned int, unsigned int > &index) const
 Function to return the maximum value in the matrix.
 
void min (T &result, std::pair< unsigned int, unsigned int > &index) const
 Function to return the minimum value in the matrix.
 
int det (T &result) const
 Function to return the determinant of the matrix.
 
int inverse (Matrix< T, R, C > &result) const
 Function to return the inverse of the matrix.
 
void transpose (Matrix< T, C, R > &result) const
 Function to return the transpose of the matrix.
 
Matrix< T, C, R > transpose () const
 
int trace (T &result) const
 Function to return the trace of the matrix.
 
void setToZeros ()
 Function to set all elements of the matrix to zero.
 
int identity ()
 Function to set matrix to identity, if it is a square matrix.
 
int eye ()
 

Public Attributes

std::array< std::array< T, C >, R > values
 The actual values held by the matrix – a two dimensional array of values indexed as (row, column). NOTE: Public for ease of access and speed (no need to use setter/getter), and functions in Matrix and Safemath libraries are tested safe. Behavior using matrices outside of clockwerk libraries should use setter/getter, rather than direct access, for safety.
 

Protected Member Functions

int _checkLookupBoundaries (const unsigned int &start_r, const unsigned int &end_r, const unsigned int &start_c, const unsigned int &end_c) const
 Function to check, given a set of submatrix boundaries, that those boundaries are valid for the current matrix.
 
int _LUPDecompose (T *A[R], unsigned int P[R+1]) const
 Function to take a 2-d matrix represented by A and decompose it into LU form.
 

Detailed Description

template<typename T>
class clockwerk::DCM< T >

Class defining a direction cosine matrix inherited from Matrix.

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

  • Set to be square, 3x3 (that's where it will primarily be used)
  • Default constructor is identity matrix, rather than zeroes
  • Inverse is set to account for orthogonal matrix
  • Functions defined to convert to other attitude
  • 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.

Member Function Documentation

◆ _LUPDecompose()

int clockwerk::Matrix< T, R, C >::_LUPDecompose ( T *  A[R],
unsigned int  P[R+1] 
) const
protectedinherited

Function to take a 2-d matrix represented by A and decompose it into LU form.

Parameters
AA 2-d matrix represented as a double pointer After ops A contains a copy of both matrices L-E and U as A=(L-E)+U such that P*A=L*U.
PThe permutation matrix to hold info on matrix changes
Returns
Error code corresponding to codes in clockwerkerrors.h
Note
Code borrowed/updated from sample C code on wikipedia here: https://en.wikipedia.org/wiki/LU_decomposition

◆ det()

int clockwerk::Matrix< T, R, C >::det ( T &  result) const
inherited

Function to return the determinant of the matrix.


Operations to return important matrix information

Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ get() [1/2]

T clockwerk::Matrix< T, R, C >::get ( const unsigned int &  row,
const unsigned int &  col 
) const
inherited

Function to get a single value in the matrix.

Parameters
rowThe row index
colThe column index
Returns
Matrix value at index
Note
Does not bounds check and is unsafe for embedded operations

◆ get() [2/2]

int clockwerk::Matrix< T, R, C >::get ( const unsigned int &  row,
const unsigned int &  col,
T &  result 
) const
inherited

Function to get a single value in the matrix.

Parameters
rowThe row index
colThe column index
valuePBR return of the value in the matrix
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ getAsArray()

void clockwerk::Matrix< T, R, C >::getAsArray ( T *  start_ptr) const
inherited

Function to get the values of the matrix row-wise.

Parameters
start_ptrThe data address at which write should begin.
Note
start_ptr must represent an array or similar type of at least R*C values
Not protected. May segfault if not used properly
The matrix [1 2; 3 4] would output as an array [1 2 3 4]

◆ getCopy()

void clockwerk::Matrix< T, R, C >::getCopy ( Matrix< T, R, C > &  result) const
inherited

Function to get a copy of the matrix.

Parameters
resultPBR return of a copy of this matrix

◆ identity()

int clockwerk::Matrix< T, R, C >::identity ( )
inherited

Function to set matrix to identity, if it is a square matrix.

Returns
Error code corresponding to success/failure

◆ inverse() [1/2]

template<typename T >
int clockwerk::DCM< T >::inverse ( DCM< T > &  result) const

Function to return the inverse of the matrix.

Parameters
resultPBR return of matrix inverse
Returns
Integer value corresponding to error codes in clockwerkerrrors.h
Note
Overloaded for value return

◆ inverse() [2/2]

int clockwerk::Matrix< T, R, C >::inverse ( Matrix< T, R, C > &  result) const
inherited

Function to return the inverse of the matrix.

Parameters
resultPBR return of matrix inverse
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ max()

void clockwerk::Matrix< T, R, C >::max ( T &  result,
std::pair< unsigned int, unsigned int > &  index 
) const
inherited

Function to return the maximum value in the matrix.

Parameters
resultPBR return of maximum value

◆ min()

void clockwerk::Matrix< T, R, C >::min ( T &  result,
std::pair< unsigned int, unsigned int > &  index 
) const
inherited

Function to return the minimum value in the matrix.

Parameters
resultPBR return of minimum value

◆ operator[]()

T * clockwerk::Matrix< T, R, C >::operator[] ( unsigned int  idx)
inherited

Function to return a matrix row or vector value.

Parameters
idxThe row index to return
Returns
A pointer to the row element of the matrix. Nullptr if out of range

◆ rate()

template<typename T >
void clockwerk::DCM< T >::rate ( const CartesianVector< T, 3 > &  omega_f1_f2__f1,
Matrix< T, 3, 3 > &  dcmdot_f1_f2 
)

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
dcmdot_f1_f2Rate of change in the current DCM

◆ set()

int clockwerk::Matrix< T, R, C >::set ( const unsigned int &  row,
const unsigned int &  col,
const T &  value 
)
inherited

Function to set a single value in the matrix.


Getters and setters

Parameters
rowThe row index
colThe column index
valueThe value to set the matrix to
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ setFromArray()

void clockwerk::Matrix< T, R, C >::setFromArray ( const T *  start_ptr)
inherited

Function to set the values of the matrix row-wise.

Parameters
start_ptrThe data address at which read should begin.
Note
start_ptr must represent an array or similar type of at least R*C values
Not protected. May segfault if not used properly
The array [1 2 3 4] would read into a matrix as [1 2; 3 4]

◆ size()

std::pair< unsigned int, unsigned int > clockwerk::Matrix< T, R, C >::size ( )
inlineinherited

Function to get the size of the matrix.


Operations to get matrix info

◆ toEuler321()

template<typename T >
int clockwerk::DCM< T >::toEuler321 ( Euler321< T > &  euler_f1_f2) const

Function to convert current attitude to 321 Euler sequence.


Conversions to other attitude representations

Parameters
PBRreturn of 321 Euler sequence in PBR case
Returns
Integer error code corresponding to errors in clockwerkerrors.h
Note
Cannot overload for return by value because conversion isn't guaranteed

◆ toMRP()

template<typename T >
int clockwerk::DCM< T >::toMRP ( MRP< T > &  mrp_f1_f2) const

Overloaded functions to convert current attitude to MRP.

Parameters
PBRreturn of MRP in PBR case
Returns
MRP in return by value case

◆ toQuaternion()

template<typename T >
int clockwerk::DCM< T >::toQuaternion ( Quaternion< T > &  q_f1_f2) const

Overloaded functions to convert current attitude to quaternion.

Parameters
PBRreturn of quaternion in PBR case
Returns
Quaternion in return by value case

◆ trace()

int clockwerk::Matrix< T, R, C >::trace ( T &  result) const
inherited

Function to return the trace of the matrix.

Parameters
resultPBR return of matrix trace
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ transpose()

void clockwerk::Matrix< T, R, C >::transpose ( Matrix< T, C, R > &  result) const
inherited

Function to return the transpose of the matrix.

Parameters
resultPBR return of matrix transpose
Note
Overloaded for return as well

The documentation for this class was generated from the following file: