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

MappingMeanOsculatingOrbitElements.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file MappingMeanOsculatingOrbitElements.cpp
00003 *  \brief First order mapping algorithm between mean orbit elments and osculating orbit elements.
00004 *       Referenced from "Anayltic Mechanics of Space Systems" by Schaub and Junkins (p.693).
00005 *  \author $Author: jayhawk_hokie $
00006 *  \version $Revision: 1.2 $
00007 *  \date    $Date: 2007/08/31 16:52:10 $
00008 *//////////////////////////////////////////////////////////////////////////////////////////////////
00009 /*
00010 *
00011 */
00012 //////////////////////////////////////////////////////////////////////////////////////////////////
00013 
00014 #include "MappingMeanOsculatingOrbitElements.h"
00015 
00016 namespace O_SESSAME 
00017 {
00018 
00019 /*! \brief Default Deconstructor */
00020 OsculatingOrbitalElements::~OsculatingOrbitalElements()
00021 {
00022 }
00023 
00024 
00025 /*! \brief Return a pointer to a new instance of a OsculatingOrbitELement orbit state representation type.
00026  *
00027  *  This is used to request memory for a new instance of a OsculatingOrbitELement. It is necessary
00028  *      when attempting to get a pointer from the abstract data type OrbitStateRepresentation
00029  *      and the actual representation type isn't known.
00030  * @return a pointer to a new allocation of memory for the Keplerian object.
00031  */
00032 OsculatingOrbitalElements* OsculatingOrbitalElements::NewPointer()
00033 {
00034     return new OsculatingOrbitalElements();
00035 }
00036 
00037 
00038 /*! \brief Return a pointer to a copy of the OsculatingOrbitalElements orbit state representation instance.
00039  *
00040  *  This is used to request memory for a copy of this instance of Keplerian. It is necessary
00041  *      when attempting to get a pointer from the abstract data type OrbitStateRepresentation
00042  *      and the actual representation type isn't known.
00043  * @return a pointer to a copy of the OsculatingOrbitalElements object.
00044  */
00045 OsculatingOrbitalElements* OsculatingOrbitalElements::Clone()
00046 {
00047     return new OsculatingOrbitalElements(*this);
00048 }
00049 
00050 
00051 /*! \brief Create an initially empty OsculatingOrbitalElements orbit state representation. 
00052  *
00053  */
00054 OsculatingOrbitalElements::OsculatingOrbitalElements()  
00055 {
00056 }
00057 
00058 
00059 /*! \brief Set the osculating oribtal elements with this function. 
00060  *
00061  *  @param _OsculatingOrbitalElements
00062  */
00063 //Keplerian OsculatingOrbitalElements::SetOsculatingOrbitalElements( Keplerian &_OsculatingOrbitalElements )
00064 void OsculatingOrbitalElements::SetOsculatingOrbitalElements( Keplerian& _OsculatingOrbitalElements )
00065 {
00066         m_OsculatingOrbitalElements = _OsculatingOrbitalElements.KeplerianCopy( );
00067         
00068         OsculatingToMean( );
00069         
00070         return;
00071 }
00072 
00073 /*! \brief Set the osculating oribtal elements with this function. 
00074  *
00075  *  @param _ECIVector (6x1) km & km/s
00076  */
00077 void OsculatingOrbitalElements::SetOsculatingOrbitalElements( CAMdoubleVector _ECIVector )
00078 {
00079         Keplerian _OsculatingOrbitalElements;
00080         _OsculatingOrbitalElements.SetPositionVelocity( _ECIVector );
00081         m_OsculatingOrbitalElements = _OsculatingOrbitalElements.KeplerianCopy( );
00082         
00083         OsculatingToMean( );
00084         
00085         return;
00086 }
00087 
00088 /*! \brief Set the mean oribtal elements with this function. 
00089  *
00090  */
00091 void OsculatingOrbitalElements::SetMeanOrbitalElements( Keplerian& _MeanOrbitalElements )
00092 {
00093         m_MeanOrbitalElements = _MeanOrbitalElements.KeplerianCopy( );
00094 
00095         MeanToOsculating( );
00096         
00097         return;
00098 }
00099 
00100 /*! \brief Set the mean oribtal elements with this function. 
00101  *
00102  */
00103 void OsculatingOrbitalElements::SetMeanOrbitalElements( CAMdoubleVector _ECIVector )
00104 {
00105         Keplerian _MeanOrbitalElements;
00106         _MeanOrbitalElements.SetPositionVelocity( _ECIVector );
00107         m_MeanOrbitalElements = _MeanOrbitalElements.KeplerianCopy( );
00108 
00109         MeanToOsculating( );
00110         
00111         return;
00112 }
00113 
00114 
00115 /*! \brief Get the Mean oribtal elements with this function. 
00116  *
00117  */
00118 Keplerian OsculatingOrbitalElements::GetMeanOrbitalElements( )
00119 {
00120         return( m_MeanOrbitalElements );
00121 }
00122 
00123 /*! \brief Get the Osculating oribtal elements with this function. 
00124  *
00125  */
00126 Keplerian OsculatingOrbitalElements::GetOsculatingOrbitalElements( )
00127 {
00128         return( m_OsculatingOrbitalElements );
00129 }
00130 
00131 
00132 /*! \brief Convert the Osculating oribtal elements to Mean Orbital Elements. 
00133  *
00134  */
00135 void OsculatingOrbitalElements::OsculatingToMean( )
00136 {
00137         m_Gamma2 = -J2 / 2 * pow( ( Re / m_OsculatingOrbitalElements.GetSemimajorAxis() ),2);
00138 
00139         m_MeanOrbitalElements = Mapping( m_OsculatingOrbitalElements );
00140 
00141         return;
00142 }
00143 
00144 
00145 /*! \brief Convert the Mean oribtal elements to Osculating Orbital Elements. 
00146  *
00147  */
00148 void OsculatingOrbitalElements::MeanToOsculating( )
00149 {
00150         m_Gamma2 = -J2 / 2 * pow( ( Re / m_MeanOrbitalElements.GetSemimajorAxis() ),2);
00151 
00152         m_MeanOrbitalElements = Mapping( m_MeanOrbitalElements );
00153 
00154         return;
00155 }
00156 
00157 
00158 /*! \brief Convert the Mean oribtal elements to Osculating Orbital Elements. 
00159  *  This mapping algorithm is from page 693 of Analytical Mechanics of Space
00160  *  Systems by Schaub and Junkins.
00161  *
00162  *  @param _keplerian variable of class Keplerian
00163  *
00164  *  @return the mapped keplerian representation
00165  */
00166 Keplerian OsculatingOrbitalElements::Mapping( Keplerian& _keplerian )
00167 {
00168 
00169         double  a       = _keplerian.GetSemimajorAxis(); 
00170         double  e       = _keplerian.GetEccentricity();
00171         double  i       = _keplerian.GetInclination();
00172         double  Lon     = _keplerian.GetLongAscNode();
00173         double  Arg     = _keplerian.GetArgPerigee();
00174         double  tru     = _keplerian.GetTrueAnomaly();  
00175 
00176         double eta      = sqrt( 1-pow( e, 2 ) );
00177 
00178         double gamma2_T = m_Gamma2 / pow( eta, 4 ); // gamma2 transformed
00179 
00180         double E        = _keplerian.GetEccentricAnomaly();
00181         /* Require E to be positive */
00182         if( E < 0 )
00183                 E = 2*PI + E; // return the appropriate Eccentric Anomaly which is > 0
00184         /* This is wrong.
00185         if(E < 0)
00186         {
00187                 E = -E;
00188         }
00189         */
00190 
00191         double M        = _keplerian.GetMeanAnomaly();
00192 
00193         double a_r      = ( 1+e*cos( tru ) ) / pow( eta, 2 ); // a/r
00194 
00195         /* Semi-major Axis Mapping (km) */
00196         double _a       = a + a*m_Gamma2*
00197                         (
00198                                 (
00199                                 3*pow(cos(i),2)-1
00200                                 )
00201                         *
00202                                 (
00203                                 pow(a_r,3))-1/(pow(eta,3)
00204                                 )
00205                         + 3*
00206                                 (
00207                                 1-pow(cos(i),2)
00208                                 )
00209                         *pow(a_r,3)*cos(2*Arg+2*tru)
00210                         ); 
00211 
00212         /* Intermediate Results for the transformation */
00213         double de1 = gamma2_T/8*e*pow(eta,2)*
00214                         (
00215                         1-11*pow(cos(i),2)-40*pow(cos(i),4)/(1-5*pow(cos(i),2))
00216                         )
00217                         *cos(2*Arg);
00218 
00219         double de = de1 + pow(eta,2)/2*
00220                 (
00221                 m_Gamma2*
00222                         (
00223                 (3*pow(cos(i),2)-1)/pow(eta,6)*
00224                                 (
00225                 e*eta + e/(1+eta) + 3*cos(tru) + 3*e*pow(cos(tru),2) + pow(e,2)*pow(cos(tru),3)
00226                                 ) 
00227                 + 3*
00228                                 (
00229                 1-pow(cos(i),2)
00230                                 )
00231                 /pow(eta,6)*
00232                                 (
00233                 e + 3*cos(tru) + 3*e*pow(cos(tru),2) + pow(e,2)*pow(cos(tru),3)
00234                                 )
00235                 *cos(2*Arg+3*tru)
00236                         )
00237                 - gamma2_T*
00238                         (
00239                 1-pow(cos(i),2)
00240                         )
00241                 *
00242                         (
00243                 3*cos(2*Arg+tru)+cos(2*Arg+3*tru)
00244                         )
00245                 );
00246 
00247         double di = -e*de1/(pow(eta,2)*tan(i)) + gamma2_T/2*cos(i)*sqrt(1-pow(cos(i),2))*
00248                         (
00249                         3*cos(2*Arg+2*tru) + 3*e*cos(2*Arg+tru) + e*cos(2*Arg+3*tru)
00250                         );
00251 
00252         // M_T+Arg_T+Lon_T = term
00253         double term = M + Arg + Lon + gamma2_T/8*pow(eta,3)*
00254                         (
00255                         1 - 11*pow(cos(i),2) - 40*pow(cos(i),4)/(1-5*pow(cos(i),2))
00256                         )
00257                         -gamma2_T/16*
00258                         (
00259                         2 + pow(e,2) - 11*
00260                                 (
00261                         2+3*pow(e,2)
00262                                 )
00263                         *pow(cos(i),2) - 40*
00264                                 (
00265                         2+5*pow(e,2)
00266                                 )*pow(cos(i),4)/
00267                                 (
00268                         1-5*pow(cos(i),2)
00269                                 )
00270                         -400*pow(e,2)*pow(cos(i),6)/pow((1-5*pow(cos(i),2)),2)
00271                         )
00272                         +gamma2_T/4*
00273                         (
00274                         -6*
00275                                 (
00276                         1-5*pow(cos(i),2)
00277                                 )
00278                         *
00279                                 (
00280                         tru - M + e*sin(tru)
00281                                 )
00282                         +
00283                                 (
00284                         3 - 5*pow(cos(i),2)
00285                                 )
00286                         *
00287                                 (
00288                         3*sin(2*Arg+2*tru) + 3*e*sin(2*Arg+tru) + e*sin(2*Arg+3*tru)
00289                                 )
00290                         )
00291                         -gamma2_T/8*pow(e,2)*cos(i)*
00292                         (
00293                         11 + 80*pow(cos(i),2)/(1-5*pow(cos(i),2)) + 200*pow(cos(i),4)/pow((1-5*pow(cos(i),2)),2)
00294                         )
00295                         -gamma2_T/2*cos(i)*
00296                         (
00297                         6*(tru-M+e*sin(tru))-3*sin(2*Arg+2*tru)-3*e*sin(2*Arg+tru)-e*sin(2*Arg+3*tru)
00298                         );
00299 
00300         double edM = gamma2_T/8*e*pow(eta,3)*
00301                         (
00302                         1 - 11*pow(cos(i),2) - 40*pow(cos(i),2)/(1-5*pow(cos(i),2))
00303                         )
00304                         - gamma2_T/4*pow(eta,3)*
00305                         (
00306                         2*(3*pow(cos(i),2)-1)*
00307                                 (
00308                         pow(a_r*eta,2)+a_r+1
00309                                 )
00310                         *sin(tru) + 3*(1-pow(cos(i),2))*
00311                                 (
00312                                         (
00313                         -pow(a_r*eta,2)-a_r+1
00314                                         )
00315                         *sin(2*Arg+tru) +                 
00316                                         (
00317                         pow(a_r*eta,2)+a_r+1/3
00318                                         )
00319                         *sin(2*Arg+3*tru)
00320                                 )
00321                         );
00322 
00323         double dLon = -gamma2_T/8*pow(e,2)*cos(i)*
00324                         (
00325                         11 + 80*pow(cos(i),2)/(1-5*pow(cos(i),2)) + 200*pow(cos(i),4)/pow((1-5*pow(cos(i),2)),2)
00326                         )
00327                         -gamma2_T/2*cos(i)*
00328                         (
00329                         6*(tru-M+e*sin(tru))-3*sin(2*Arg+2*tru)-3*e*sin(2*Arg+tru)-e*sin(2*Arg+3*tru)
00330                         );
00331 
00332         
00333         /* Compute the remaining transformed orbit elements */
00334         
00335         double d1 = (e+de)*sin(M)+edM*cos(M);
00336         double d2 = (e+de)*cos(M)-edM*sin(M);
00337  
00338         double _M = atan2(d1,d2);
00339 
00340         double _e = sqrt(pow(d1,2)+pow(d2,2));
00341 
00342         double d3 = (sin(i/2)+cos(i/2)*di/2)*sin(Lon)+sin(i/2)*dLon*cos(Lon);
00343         double d4 = (sin(i/2)+cos(i/2)*di/2)*cos(Lon)-sin(i/2)*dLon*sin(Lon);  
00344 
00345         double _Lon     = atan2(d3,d4);
00346 
00347         double _i       = 2*asin(sqrt(pow(d3,2)+pow(d4,2)));
00348 
00349         double _Arg = term - _M - _Lon;
00350 
00351         
00352         /* Format Argument of Perigee so that the number is represented between 0 and 2*pi */
00353         int cycles      = (int)( _Arg / (2*PI) );
00354         _Arg            = _Arg - cycles*2*PI;
00355 
00356         Vector _OrbitalElements(6);
00357         _OrbitalElements( VectorIndexBase + 0 ) = _a;
00358         _OrbitalElements( VectorIndexBase + 1 ) = _e;
00359         _OrbitalElements( VectorIndexBase + 2 ) = _i;
00360         _OrbitalElements( VectorIndexBase + 3 ) = _Lon;
00361         _OrbitalElements( VectorIndexBase + 4 ) = _Arg;
00362         _OrbitalElements( VectorIndexBase + 5 ) = _M;
00363         
00364         Keplerian _MappedKeplerian;
00365         _MappedKeplerian.SetKeplerianRepresentationMeanAnomaly(  _OrbitalElements ) ;
00366 
00367         return( _MappedKeplerian );
00368 } 
00369 
00370 
00371 /*
00372 // test code
00373 int main()
00374 {
00375         cout << "Mean COE Test Section" << endl;
00376         double          re      = 6378.1; // radius of earth (km)
00377         double          J2      = 0.00108263; // gravitational perturbation constant
00378         
00379         Vector ECI(3);
00380         Vector VECI(3);
00381         ECI(1) =  -4255599.88588388; // km
00382         ECI(2) = -4255599.88588388;
00383         ECI(3) = 3200001.26841524;
00384         VECI(1) = 5410.04028290564;
00385         VECI(2) =  -5410.04028290564; // km/s
00386         VECI(3) = 0; // km/s
00387 
00388         //ECI(1) =  6878137; // km
00389         //ECI(2) = 0;
00390         //ECI(3) = 0;
00391         //VECI(1) = 0;
00392         //VECI(2) =  6596.1; // km/s
00393         //VECI(3) = 3808.3; // km/s
00394         
00395         Keplerian test; // initialize test coe
00396         test.SetPositionVelocity(ECI/1000,VECI/1000); // ( m m/s)
00397 
00398         double  a = test.GetSemimajorAxis(); 
00399         double  e = test.GetEccentricity();
00400         double  i = test.GetInclination();
00401         double  Lon = test.GetLongAscNode();
00402         double  Arg = test.GetArgPerigee();
00403         double  tru = test.GetTrueAnomaly();    
00404 
00405         cout << " osc: " << a << " " << e << " " << i << " " << Lon << " " << Arg << " " << tru << endl;
00406 
00407         // 
00408         // Check conversion from ECI to COE and COE to ECI
00409         Vector check(6);
00410         check = COE2ECI(test);
00411         cout << "Original ECI: " << ECI << VECI << endl;
00412         cout << "Recal ECI: " << check << endl;
00413 
00414         //
00415         // Check mean calculation
00416         Transform meanCOE = osculating2mean(test, re, J2);
00417         Vector RV(6);
00418         Vector mycoe(6);
00419         mycoe(1) = meanCOE.SemimajorAxis;
00420         mycoe(2) = meanCOE.Eccentricity;
00421         mycoe(3) = meanCOE.Inclination;
00422         mycoe(4) = meanCOE.LongAscNode;
00423         mycoe(5) = meanCOE.ArgPerigee;
00424         mycoe(6) = test.GetTrueAnomaly();
00425         RV = COE2ECI(mycoe);
00426         Keplerian test2; // initialize test coe
00427         Vector ECI2(3);
00428         Vector VECI2(3);
00429         ECI2(1) = RV(1);
00430         ECI2(2) = RV(2);
00431         ECI2(3) = RV(3);
00432         VECI2(1) = RV(4);
00433         VECI2(2) = RV(5);
00434         VECI2(3) = RV(6);
00435         test2.SetPositionVelocity(ECI2,VECI2); // ( km km/s)
00436         
00437         Transform oscCOE = mean2osculating(test2, re, J2);
00438 
00439         cout << "a mean " << test2.GetSemimajorAxis() << endl;
00440         cout << "Values " << meanCOE.SemimajorAxis << " " << meanCOE.Eccentricity << " " << 
00441         meanCOE.Inclination << " " << meanCOE.LongAscNode << " " << meanCOE.ArgPerigee << " " 
00442         << " " << meanCOE.MeanAnomaly << endl;
00443 
00444         cout << "Osc Values " << oscCOE.SemimajorAxis << " " << oscCOE.Eccentricity << " " << 
00445         oscCOE.Inclination << " " << oscCOE.LongAscNode << " " << oscCOE.ArgPerigee << " " 
00446         << " " << oscCOE.MeanAnomaly << endl;
00447 
00448         return 0;
00449 }
00450 */
00451 
00452 }
00453 
00454 

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