Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

MRPTracking.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file MRPTracking.cpp
00003 *  \brief The MRPTracking class contains the control law for MRP and angular velocity control.
00004 *         It is derived from the Contorller class.
00005 *  \author $Author: jayhawk_hokie $
00006 *  \version $Revision: 1.4 $
00007 *  \date    $Date: 2007/08/31 15:53:26 $
00008 *//////////////////////////////////////////////////////////////////////////////////////////////////
00009 /*! 
00010 */
00011 //////////////////////////////////////////////////////////////////////////////////////////////////
00012 
00013 #include "MRPTracking.h"
00014 
00015 /* Constructor */
00016 MRPTracking::MRPTracking( )
00017 { 
00018 }
00019 
00020 MRPTracking::MRPTracking( Whorl* ptr_whorl ) 
00021 {
00022         /* Defined in Controller Class. */
00023         m_whorl = ptr_whorl;
00024         
00025         Initialize( );
00026         
00027 }
00028 
00029 /* Deconstructor */
00030 MRPTracking::~MRPTracking() 
00031 { 
00032 }
00033 
00034 int MRPTracking::Initialize( ) 
00035 {
00036         m_controlTorque.initialize(3);  
00037         
00038         m_uMax =1.5; // [N-m]
00039 
00040         /* Set scalar gain for MRP vector. */
00041         m_mrpGain = 2.5;
00042 
00043         /* Set the contorl gain matrix for angular rates. Semi-automatic gain selection */
00044         Matrix _inertiaTemp = m_whorl->GetMOI( );
00045         m_gainMatrix.initialize(3,3);
00046         for ( int i=1; i<4; i++ )
00047         {
00048                 m_gainMatrix(i,i) = pow( ( m_mrpGain* _inertiaTemp(i,i) ), 0.5 );
00049         }
00050 
00051         /* Get orientation of Momentum Wheels. Defined in Controller Class. */
00052         A = FindA( );
00053 
00054         /* Get Momentum Wheel spin axis MOI. Defined in Controller Class */
00055         MOI_sw = FindMOI_sw( );
00056         
00057         /* Reference Model */
00058         Quaternion qri( 0.0, 0.0, 0.0, 1.0 );
00059         m_quaternionReference(1) = qri(1);
00060         m_quaternionReference(2) = qri(2);
00061         m_quaternionReference(3) = qri(3);
00062         m_quaternionReference(4) = qri(4);
00063         m_mrpReference = ModifiedRodriguezParameters( qri );
00064         m_angularRateReference(1) = 0; 
00065         m_angularRateReference(2) = 0.0; 
00066         m_angularRateReference(3) = 0.0; // [rad/s] 
00067 
00068         ssfTime time;
00069         time = Now( );
00070         m_previousTime = time.GetSeconds( );
00071 
00072         return( 0 );
00073 }
00074 
00075 int MRPTracking::Run( )
00076 {
00077         static ssfTime currentTime;
00078         currentTime = Now( );
00079         static ssfTime deltaTime;
00080         deltaTime = ( currentTime.GetSeconds( ) - m_previousTime );
00081         //m_previousTime = currentTime.GetSeconds( ); // update time
00082         // dont' update time, thus provides duration time in seconds.   
00083 
00084         /* Desired State. Reference Model */
00085         //ReferenceModelSC( deltaTime );
00086         ReferenceTrajectory( deltaTime );       
00087 
00088         ModifiedRodriguezParameters mrp( m_whorl->GetMRP( ) );
00089         ModifiedRodriguezParameters mrpReference( m_mrpReference );
00090 
00091         /* Determine Rotation Matirx */
00092         Rotation RBN( mrp ); // body relative to inertial frame
00093         Rotation RRN( mrpReference ); // reference relative to inertial frame
00094         Rotation RBR; // body relative to reference frame
00095         RBR = RBN*~RRN;
00096 
00097         /* Error */
00098         static Vector angularRateError(3);
00099         angularRateError = m_whorl->GetOmegaBL( ) - RBR*(m_angularRateReference); // angular rate error [rad/s]
00100         ModifiedRodriguezParameters mrpError;
00101         mrpError = mrp - mrpReference; // mrp error
00102         mrpError.Switch( 1 ); // important to activate switch condition
00103 
00104         /* Set Whorl Error Values */
00105         m_whorl->SetMRPError( mrpError );       
00106         m_whorl->SetAngularRateError( angularRateError );       
00107 
00108         /* Set Whorl Reference Parameters */
00109         m_whorl->SetReferenceOmegaBL( m_angularRateReference ); 
00110         m_whorl->SetReferenceQuaternion( m_quaternionReference );       
00111 
00112         /* Reaction Wheel Speed */
00113         static Vector wheelSpeed(3);
00114         double meastime;
00115         m_whorl->GetMomentumWheel("REACTION_X")->GetWheelSpeed( wheelSpeed(1), meastime );
00116         m_whorl->GetMomentumWheel("REACTION_Y")->GetWheelSpeed( wheelSpeed(2), meastime );
00117         m_whorl->GetMomentumWheel("REACTION_Z")->GetWheelSpeed( wheelSpeed(3), meastime );
00118 
00119         /* Reaction Wheel Angular Momentum */
00120         static Vector hs(3);
00121         for ( int i=1; i<4; i++ )
00122         {
00123                 static Vector w(3);
00124                 w(1) = A(1,i);
00125                 w(2) = A(2,i);
00126                 w(3) = A(3,i);
00127                 static Matrix ws(1,1);
00128                 ws = ~w*m_whorl->GetOmegaBL( );
00129                 hs(i) = MOI_sw(i,i) * ( ws(1,1) + wheelSpeed(i) );
00130         }
00131         
00132         /* MRP tracking control law - attitude and angular rate */
00133         m_controlTorque = (~A)*( -m_mrpGain*( mrpError ) - (m_gainMatrix)*angularRateError 
00134                 + skew( m_whorl->GetOmegaBL( ) )*(m_whorl->GetMOI( )*m_whorl->GetOmegaBL( ) + (A)*hs) 
00135                 + m_whorl->GetMOI( )*( RBR.GetDCM( )*(m_angularAccelReference) 
00136                 - skew( m_whorl->GetOmegaBL( ) )*RBR.GetDCM( )*(m_angularRateReference) ) ); // [N-m]
00137         
00138         /* Wheel Saturation Function */
00139         m_controlTorque = WheelSaturation( m_controlTorque );
00140 
00141         /* Set the desird contorl torque in the whorl object */
00142         m_whorl->SetControl( m_controlTorque );
00143 
00144         /* Set the torque for the momentum wheels to produce */
00145         SetWheelTorque( m_controlTorque );
00146 
00147         return( 0 );
00148 }
00149 
00150 // Do not change the comments below - they will be added automatically by CVS
00151 /*****************************************************************************
00152 *       $Log: MRPTracking.cpp,v $
00153 *       Revision 1.4  2007/08/31 15:53:26  jayhawk_hokie
00154 *       Modified.
00155 *       
00156 *       Revision 1.3  2007/07/24 09:26:41  jayhawk_hokie
00157 *       Updated.
00158 *       
00159 *       Revision 1.2  2007/05/31 17:21:16  jayhawk_hokie
00160 *       *** empty log message ***
00161 *       
00162 *       Revision 1.1  2007/05/23 22:26:01  jayhawk_hokie
00163 *       Initial submission.
00164 *       
00165 *       
00166 *
00167 ******************************************************************************/

Generated on Wed Sep 5 12:54:22 2007 for DSACSS Operational Code by  doxygen 1.3.9.1