00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "DefaultController.h"
00014
00015
00016 DefaultController::DefaultController( )
00017 {
00018 }
00019
00020 DefaultController::DefaultController( Whorl* ptr_whorl )
00021 {
00022
00023 m_uMax = 1.5;
00024
00025
00026 m_whorl = ptr_whorl;
00027
00028 Initialize( );
00029
00030 }
00031
00032
00033 DefaultController::~DefaultController()
00034 { }
00035
00036 int DefaultController::Initialize( )
00037 {
00038
00039 m_controlTorque.initialize(3);
00040
00041 m_uMax =1.5;
00042
00043
00044 m_K = 1.5;
00045
00046
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
00056 A = FindA( );
00057
00058
00059 MOI_sw = FindMOI_sw( );
00060
00061
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;
00069 m_angularRateReference(2) = 0.0;
00070 m_angularRateReference(3) = 0.0;
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
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
00093 m_whorl->SetMRPError( mrp );
00094 m_whorl->SetAngularRateError( angularRateBody );
00095
00096
00097 m_whorl->SetReferenceOmegaBL( m_angularRateReference );
00098 m_whorl->SetReferenceQuaternion( m_quaternionReference );
00099
00100
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
00114 m_controlTorque = (~A)*( -m_K*(mrp) + -(m_gainMatrix) * angularRateBody
00115 + skew( angularRateBody )*(A)*hs );
00116
00117
00118 m_controlTorque = WheelSaturation( m_controlTorque );
00119
00120
00121 m_whorl->SetControl( m_controlTorque );
00122
00123
00124 SetWheelTorque( m_controlTorque );
00125
00126 return( 0 );
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173