00001 #include <iostream.h>
00002 #include <iomanip.h>
00003 #include "Rotation.h"
00004 #include "Matrix.h"
00005 #include "Attitude.h"
00006 #include "LinearInterpolator.h"
00007 #include "RungeKuttaIntegrator.h"
00008 using namespace O_SESSAME;
00009
00010
00011 Vector NullFunctor(const ssfTime& _pSSFTime, const OrbitState& _pOrbitState, const AttitudeState& _pAttitudeState)
00012 {
00013 return Vector(3);
00014 }
00015
00016 static Vector EugeneDynamics(const ssfTime &_time, const Vector& _integratingState, Orbit *_Orbit, Attitude *_Attitude, const Matrix &_parameters, const Functor &_forceFunctorPtr)
00017 {
00018
00019 static Vector h = _integratingState(_(1,3));
00020 static double T = _integratingState(4);
00021
00022 Matrix I(3,3);
00023 I(1,1) = 100;
00024 I(2,2) = 200;
00025 I(3,3) = 150;
00026 static Vector w = I.inverse() * h;
00027 Vector ge(3);
00028
00029 static Vector hdot = skew(w) * h + ge;
00030 static Vector wdot = I.inverse() * hdot;
00031 static Matrix temp = (~ge * wdot);
00032 double Tdot = temp(1,1);
00033
00034 static Vector statedot(hdot.getIndexBound() + 1);
00035 statedot(_(1, hdot.getIndexBound())) = hdot(_);
00036 statedot(hdot.getIndexBound()+1) = Tdot;
00037
00038 return statedot;
00039
00040 }
00041
00042 static Vector AttituteDynamics(const ssfTime &_time, const Vector& _integratingState, Orbit *_Orbit, Attitude *_Attitude, const Matrix &_parameters, const Functor &_forceFunctorPtr)
00043 {
00044 static Vector stateDot(7);
00045 static Matrix bMOI(3,3);
00046 static Matrix qtemp(4,3);
00047 static Matrix Tmoment(3,1);
00048 static Vector qIn(4);
00049 static Vector wIn(3);
00050 qIn = _integratingState(_(VectorIndexBase,VectorIndexBase + 3));
00051 wIn = _integratingState(_(VectorIndexBase + 4,VectorIndexBase + 6));
00052 qIn /= norm2(qIn);
00053
00054
00055 qtemp(_(VectorIndexBase+0,VectorIndexBase+2),_(VectorIndexBase+0,VectorIndexBase+2)) = skew(qIn(_(VectorIndexBase+0,VectorIndexBase+2))) + qIn(VectorIndexBase+3) * eye(3);
00056 qtemp(VectorIndexBase+3, _(VectorIndexBase+0,VectorIndexBase+2)) = -(~qIn(_(VectorIndexBase+0,VectorIndexBase+2)));
00057 qtemp(_,MatrixIndexBase) = 0.5 * qtemp * wIn;
00058
00059 bMOI = _parameters(_(MatrixIndexBase+0,MatrixIndexBase+2),_(MatrixIndexBase+0,MatrixIndexBase+2));
00060 Tmoment = (bMOI.inverse() * (Tmoment - skew(wIn) * (bMOI * wIn)));
00061
00062 stateDot(_(VectorIndexBase,VectorIndexBase + 3)) = qtemp(_,MatrixIndexBase);
00063 stateDot(_(VectorIndexBase + 4,VectorIndexBase + 6)) = Tmoment(_,MatrixIndexBase);
00064
00065 return stateDot;
00066 }
00067 int main()
00068 {
00069
00070
00071
00072 Quaternion q(0.5,0.5,0.5,0.5);
00073
00074
00075
00076 cout << q << q.GetMRP() << endl;
00077
00078
00079 DirectionCosineMatrix dcm(10,-30,150, 321);
00080
00081
00082 Rotation qrot(q);
00083 Rotation dcmrot(dcm);
00084
00085
00086 Rotation rot2;
00087 rot2 = qrot + dcmrot;
00088 cout << rot2.GetDCM() << endl;
00089
00090
00091
00092 ssfTime time;
00093 time.SetEpoch(Now());
00094 time.Set(time.GetEpoch()+50);
00095
00096 tm date = time.GetDateTime();
00097 cout << date.tm_mday << " " << date.tm_mon << " " << date.tm_year << endl << endl << endl;
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 Vector timevec(10);
00109 Matrix datavec(10,1);
00110 for (int J = 1; J < 11; J = J+1){
00111 timevec(J) = J/10.0;
00112 datavec(J,1) = sin(J/10.0);}
00113
00114 LinearInterpolator interp(timevec,datavec);
00115 Vector chk = interp.Evaluate(0.25);
00116 cout << timevec << endl << datavec << endl << chk << endl;
00117
00118
00119
00120
00121 Quaternion q2(0,0,0,1);
00122 Rotation rot(q2);
00123 AttitudeState att(rot);
00124
00125
00126
00127 RungeKuttaIntegrator myIntegrator;
00128 myIntegrator.SetNumSteps(1000);
00129
00130
00131 AttitudeState myAttitudeState;
00132 myAttitudeState.SetRotation(Rotation(Quaternion(0,0,0,1)));
00133 Vector initAngVelVector(3);
00134 initAngVelVector(1) = 0.1;
00135 myAttitudeState.SetAngularVelocity(initAngVelVector);
00136
00137
00138 Matrix Parameters = eye(3);
00139
00140
00141 vector<ssfTime> integrationTimes;
00142 ssfTime begin(0);
00143 ssfTime end(begin + 20);
00144 integrationTimes.push_back(begin);
00145 integrationTimes.push_back(end);
00146 cout << "PropTime = " << begin.GetSeconds() << " s -> " << end.GetSeconds() << " s" << endl;
00147 cout << "Attitude State: " << ~myAttitudeState.GetState() << endl;
00148
00149 SpecificFunctor AttitudeForcesFunctor(&NullFunctor);
00150
00151 Matrix I(3,3);
00152 I(1,1) = 100;
00153 I(2,2) = 200;
00154 I(3,3) = 150;
00155 Vector h(3);
00156 h(1) = 10;
00157 h(2) = 20;
00158 h(3) = 30;
00159
00160 Vector w = I.inverse() * h;
00161 Matrix Tmat = 0.5 * (~w * (I * w));
00162 Vector initEugeneState(4);
00163 initEugeneState(_(1,3)) = h(_(1,3));
00164 initEugeneState(4) = Tmat(1,1);
00165
00166 tick();
00167 Matrix history = myIntegrator.Integrate(
00168 integrationTimes,
00169 &AttituteDynamics,
00170 myAttitudeState.GetState(),
00171 NULL,
00172 NULL,
00173 Parameters,
00174 AttitudeForcesFunctor
00175 );
00176 cout << tock();
00177 return 0;
00178 }
00179
00180