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

DefaultController.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file DefaultController.cpp
00003 *  \brief Implementation of the DefaultController class.
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.10 $
00006 *  \date    $Date: 2007/08/31 15:53:26 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /*! 
00009 */
00010 //////////////////////////////////////////////////////////////////////////////////////////////////
00011 
00012 
00013 #include "DefaultController.h"
00014 
00015 /* Constructor */
00016 DefaultController::DefaultController( )
00017 { 
00018 }
00019 
00020 DefaultController::DefaultController( Whorl* ptr_whorl ) 
00021 {
00022         /* Set Maximum control torque for wheels. */
00023         m_uMax = 1.5; // [N-m]
00024 
00025         // From Controller Class
00026         m_whorl = ptr_whorl;
00027         
00028         Initialize( );
00029         
00030 }
00031 
00032 /* Deconstructor */
00033 DefaultController::~DefaultController() 
00034 { }
00035 
00036 int DefaultController::Initialize( ) 
00037 {
00038         /* Initialize control torque */
00039         m_controlTorque.initialize(3); // [N-m]
00040 
00041         m_uMax =1.5; // [N-m]
00042 
00043         /* Gain */
00044         m_K = 1.5;
00045 
00046         /* Set the contorl gain matrix. semi automatic gain selection */
00047         m_gainMatrix.initialize(3,3);
00048         Matrix _inertiaTemp(3,3);
00049         _inertiaTemp = m_whorl->GetMOI( );
00050         for ( int i=1; i<4; i++ )
00051         {
00052                 m_gainMatrix(i,i) = pow( ( m_K* _inertiaTemp(i,i) ), 0.5 );
00053         }
00054         
00055         /* Get orientation of Momentum Wheels */
00056         A = FindA( );
00057 
00058         /* Get Momentum Wheel spin axis MOI */
00059         MOI_sw = FindMOI_sw( );
00060 
00061         /* Reference Model, Regulator problem, therefore desired states are zero. */
00062         Quaternion qri( 0.0, 0.0, 0.0, 1.0 );
00063         m_quaternionReference(1) = qri(1);
00064         m_quaternionReference(2) = qri(2);
00065         m_quaternionReference(3) = qri(3);
00066         m_quaternionReference(4) = qri(4);
00067         m_mrpReference = ModifiedRodriguezParameters( qri );
00068         m_angularRateReference(1) = 0.0; // [rad/s]
00069         m_angularRateReference(2) = 0.0; // [rad/s]
00070         m_angularRateReference(3) = 0.0; // [rad/s]
00071 
00072         return( 0 );
00073 }
00074 
00075 int DefaultController::Run( )
00076 {
00077 
00078         Vector wheelSpeed(3);
00079         double meastime;
00080         m_whorl->GetMomentumWheel("REACTION_X")->GetWheelSpeed( wheelSpeed(1), meastime );
00081         m_whorl->GetMomentumWheel("REACTION_Y")->GetWheelSpeed( wheelSpeed(2), meastime );
00082         m_whorl->GetMomentumWheel("REACTION_Z")->GetWheelSpeed( wheelSpeed(3), meastime );
00083         
00084         // For continuity store values that are used at multiple times.
00085         Vector angularRateBody(3);
00086         angularRateBody = m_whorl->GetOmegaBL( ); 
00087         
00088         Quaternion attitude( m_whorl-> GetQuaternion( ) );
00089         ModifiedRodriguezParameters mrp( attitude );
00090         mrp.Switch( 1 );
00091 
00092         /* Set Whorl Error Values */
00093         m_whorl->SetMRPError( mrp );
00094         m_whorl->SetAngularRateError( angularRateBody );
00095 
00096         /* Set Whorl Reference Parameters */
00097         m_whorl->SetReferenceOmegaBL( m_angularRateReference );
00098         m_whorl->SetReferenceQuaternion( m_quaternionReference );
00099         
00100         /* Reaction Wheel Angular Momentum */
00101         Vector hs(3);
00102         Vector w(3);
00103         Matrix ws(1,1);
00104         for ( int i=1; i<4; i++ )
00105         {
00106                 w(1) = A(1,i); 
00107                 w(2) = A(2,i); 
00108                 w(3) = A(3,i); 
00109                 ws = ~w*m_whorl->GetOmegaBL( );
00110                 hs(i) = MOI_sw(i,i) * ( ws(1,1) + wheelSpeed(i) );
00111         }
00112         
00113         /* MRP Controller - attitude and angular rate for any simulator */
00114         m_controlTorque = (~A)*( -m_K*(mrp) + -(m_gainMatrix) * angularRateBody 
00115                 + skew( angularRateBody )*(A)*hs ); // [N-m]
00116 
00117         /* Wheel Saturation Function */
00118         m_controlTorque = WheelSaturation( m_controlTorque ); // [N-m]
00119 
00120         /* Set the desird contorl torque in the whorl object */
00121         m_whorl->SetControl( m_controlTorque ); // [N-m]
00122 
00123         /* Set the torque for the momentum wheels to produce */
00124         SetWheelTorque( m_controlTorque ); // [N-m]
00125 
00126         return( 0 );
00127 }
00128 
00129 // Do not change the comments below - they will be added automatically by CVS
00130 /*****************************************************************************
00131 *       $Log: DefaultController.cpp,v $
00132 *       Revision 1.10  2007/08/31 15:53:26  jayhawk_hokie
00133 *       Modified.
00134 *       
00135 *       Revision 1.9  2007/07/24 09:36:44  jayhawk_hokie
00136 *       Updated.
00137 *       
00138 *       Revision 1.8  2007/05/30 23:45:34  jayhawk_hokie
00139 *       Cleaned up file and set error values.
00140 *       
00141 *       Revision 1.7  2007/04/09 14:03:06  jayhawk_hokie
00142 *       Modified controller.
00143 *       
00144 *       Revision 1.6  2007/02/06 21:47:05  jayhawk_hokie
00145 *       Update Run Function.
00146 *       
00147 *       Revision 1.5  2005/02/25 18:40:53  cakinli
00148 *       Created Makefiles and organized include directives to reduce the number of
00149 *       include paths.  Reorganized libraries so that there is now one per source
00150 *       directory.  Each directory is self-contained in terms of its Makefile.
00151 *       The local Makefile in each directory includes src/config.mk, which has all
00152 *       the definitions and general and pattern rules.  So at most, to see what
00153 *       goes into building a target, a person needs to examine the Makefile in
00154 *       that directory, and ../config.mk.
00155 *       
00156 *       Revision 1.4  2003/08/18 19:05:27  mavandyk
00157 *       Removed wheel speed query to speed up controller.
00158 *       
00159 *       Revision 1.3  2003/08/14 18:10:41  mavandyk
00160 *       Added momentum wheel speed querying.
00161 *       
00162 *       Revision 1.2  2003/08/13 23:17:20  mavandyk
00163 *       Altered structure as outline in meeting.
00164 *       
00165 *       Revision 1.1  2003/07/31 20:43:14  mavandyk
00166 *       This is the default controller for Whorl.
00167 *       
00168 *       Revision 1.3  2003/07/07 14:11:24  simpliciter
00169 *       Removed GetWhorlObject() calls following Whorl pointers.
00170 *       
00171 *       
00172 *
00173 ******************************************************************************/

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