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

simpleOrbit.cpp

Go to the documentation of this file.
00001 /************************************************************************************************/
00002 /*! \file simpleOrbit.cpp
00003 *  \brief Nonlinear Orbit EOM
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.3 $
00006 *  \date    $Date: 2006/08/25 19:14:17 $
00007 ************************************************************************************************/
00008 /*!
00009 *
00010 ************************************************************************************************/
00011 
00012 // Standard System includes
00013 #include <iostream.h>
00014 #include <iomanip.h>
00015 #include <fstream.h>
00016 
00017 // Open-SESSAME Includes
00018 #include "attitude/AttitudeModels/QuaternionAngVelDynamics.h" // Dynamics model
00019 #include "utils/RungeKuttaIntegrator.h" // Integrator function
00020 #include "datahandling/History.h" // attitude and orbit history
00021 
00022 #include "orbit/orbitstaterep/Keplerian.h"
00023 
00024 
00025 // XML Parser Include
00026 #include <dsacssinterface.h>
00027 
00028 using namespace O_SESSAME;
00029 
00030 #define PI M_PI
00031 
00032 // Specify Xml File to Parse
00033 const char *fileName = "DSACSSConfig.xml";
00034 // Define xml config path names
00035 const char *spacecraft = "SPACECRAFT_1";
00036 const char *physicalProperties = "PHYSICAL_PROPERTIES";
00037 const char *attitudeProperties = "ATTITUDE_PROPERTIES";
00038 const char *hardwareProperties = "HARDWARE_PROPERTIES";
00039 const char *initialConditions = "INITIAL_CONDITIONS";
00040 const char *magnetometer = "MAGNETOMETER";
00041 const char *attribute = "value";
00042 
00043 
00044 Vector NullFunctor(const ssfTime& _pSSFTime, const OrbitState& _pOrbitState,
00045 const AttitudeState& _pAttitudeState)
00046 {
00047         return Vector(3);
00048 }
00049 
00050 int main()
00051 {
00052 
00053         /******************************************************************
00054         *  Load Configuration Parameters from xml file 
00055         *******************************************************************/
00056         // Declare TiXmlDocument
00057         TiXmlDocument config( fileName );
00058         // Load Xml File
00059         bool loadOkay = config.LoadFile();
00060         checkLoadFile(loadOkay, fileName, config);
00061         // Declare TiXmlHandle
00062         TiXmlHandle docHandle( &config );
00063         int response;
00064 
00065         /* Get mass from xml config file */
00066         double mass;
00067         response = docHandle.FirstChild( spacecraft ).FirstChild( physicalProperties ).
00068         Child( "MASS", 0 ).Element() -> QueryDoubleAttribute(attribute, &mass);
00069         checkResponse(response);
00070 
00071         /* Get inertia matrix from xml config file */
00072         Matrix inertia = simulatorInertia(docHandle, spacecraft);
00073 
00074         /* Get initial angular rate from xml config file */
00075         Vector angularRateBody(3); // wb_b
00076         for(int iterator=0; iterator<3; iterator++)
00077         {
00078                 response = docHandle.FirstChild( spacecraft ).FirstChild( attitudeProperties ).
00079                 FirstChild( initialConditions ).Child( "ANGULAR_RATE_BODY", iterator ).Element() -> 
00080                 QueryDoubleAttribute( "value", &angularRateBody(VectorIndexBase + iterator) );
00081                 checkResponse(response);
00082         }
00083         
00084         /* Get initial attitude from xml config file */
00085         Vector attitudeVector(4); // quaternion
00086         for(int iterator=0; iterator<4; iterator++)
00087         {
00088                 response = docHandle.FirstChild( spacecraft ).FirstChild( attitudeProperties ).
00089                 FirstChild( initialConditions ).Child( "QUATERNION", iterator ).Element() -> 
00090                 QueryDoubleAttribute( "value", &attitudeVector(VectorIndexBase + iterator) );
00091                 checkResponse(response);
00092         }
00093         Quaternion quaternion(attitudeVector);
00094 
00095         /* Get initial orbit information from xml config file */
00096         Vector orbitVector(6);
00097         Keplerian orbit;
00098         string str = docHandle.FirstChild( spacecraft ).FirstChild( "ORBIT_PROPERTIES" ).
00099         FirstChild( initialConditions ).Child( "KEPLERIAN", 0 ).Element() -> 
00100         Attribute( "selection" );
00101         if ("ON" == str) // Keplarian orbit parameters (a, e, i, OMEGA, omega, f)
00102         {
00103                 for(int iterator=0; iterator<6; iterator++)
00104                 {
00105                         response = docHandle.FirstChild( spacecraft ).FirstChild( "ORBIT_PROPERTIES" ).
00106                         FirstChild( initialConditions ).FirstChild( "KEPLERIAN" ).Child( "VECTOR", iterator ).
00107                         Element() -> QueryDoubleAttribute( "value", &orbitVector(VectorIndexBase + iterator) );
00108                         checkResponse(response);
00109                 }
00110                 // Convert from deg to rad
00111                 for(int iterator=3; iterator<7; iterator++)
00112                 {
00113                         orbitVector(iterator) = Deg2Rad(orbitVector(iterator));
00114                 }
00115                 orbit.SetKeplerianRepresentationTrueAnamoly(orbitVector); // store orbitVector in orbit
00116 
00117                 cout << "\nSemimajor Axis (km): " << orbit.GetSemimajorAxis()
00118                 << " Eccentricity (~): " << orbit.GetEccentricity()
00119                 << " Inclination (rad): " << orbit.GetInclination()
00120                 << " Long Ascending Node (rad): " << orbit.GetLongAscNode()
00121                 << " Argument of Perigee (rad): " << orbit.GetArgPerigee()
00122                 << " True Anomaly (rad): " << orbit.GetTrueAnomaly() 
00123                 << endl << endl;
00124         }
00125 
00126         /* Get numerical integration step size (sec) */
00127         double integrationStepSize;
00128         response = docHandle.FirstChild( spacecraft ).FirstChild( "TIME" ).
00129         Child( "INTEGRATION_STEP_SIZE", 0 ).Element() -> QueryDoubleAttribute(attribute, &integrationStepSize);
00130         checkResponse(response);
00131         
00132         /* Get number of orbits before simulation ends. */
00133         double numberOrbits;
00134         response = docHandle.FirstChild( spacecraft ).FirstChild( "TIME" ).
00135         Child( "NUMBER_OF_ORBITS", 0 ).Element() -> QueryDoubleAttribute(attribute, &numberOrbits);
00136         checkResponse(response);
00137 
00138 
00139         /******************************************************************
00140         *  Numerical Simulation 
00141         *******************************************************************/
00142 
00143         /* Start of execution time */   
00144         tick(); // (sec)
00145 
00146         /* Create attitude object */
00147         AttitudeState spacecraft_1;
00148 
00149         /* Create */
00150         SpecificFunctor AttitudeForcesFunctor(&NullFunctor);
00151 
00152         /* Create integrator object */
00153         RungeKuttaIntegrator attitudeIntegrator;
00154 
00155         /* Set number of integration steps */
00156         double orbitPeriod = 2*PI/( orbit.GetMeanMotion() ); // (sec)
00157         int integrationSteps = orbitPeriod * numberOrbits / integrationStepSize;
00158         attitudeIntegrator.SetNumSteps( integrationSteps );
00159 
00160         /* Create a container class to hold integration times */
00161         vector<ssfTime> integrationTimes;
00162         /* Simulation Time (sec) */
00163         ssfTime begin(0);
00164         ssfTime end( begin + (orbitPeriod * numberOrbits) ); 
00165         /* set integration times */
00166         integrationTimes.push_back(begin);
00167         integrationTimes.push_back(end);
00168 
00169         DirectionCosineMatrix Rbo; // initialize Rbo
00170         Rbo.Set( quaternion ); // create DCM from quaternion
00171 
00172         Vector angularRateInertial(3);
00173         angularRateInertial = angularRateBody; 
00174         //angularRateInertial = angularRateBody  - ( orbit.GetMeanMotion() ) * Rbo( _(i+0,i+2),_(i+1,i+1) ); // wbi_bo
00175 
00176         /* Set attitude and angular rates */
00177         spacecraft_1.SetRotation(Rbo);
00178         spacecraft_1.SetAngularVelocity(angularRateInertial);
00179 
00180         Matrix history = attitudeIntegrator.Integrate(integrationTimes, &AttituteDynamics_QuaternionAngVel, spacecraft_1.GetState(),
00181         NULL, NULL, inertia, AttitudeForcesFunctor);
00182 
00183         /* Save output */
00184         ofstream outputFile;
00185         outputFile.open("DataFiles/GravGradNonLin.dat");
00186         outputFile << history;
00187         outputFile.close();
00188 
00189         /* Output execution time to screen */
00190         cout << "The numerical simulation excution time was " << tock() << " seconds. \n \n" << endl;
00191 
00192         return(0);
00193 }
00194 
00195 
00196 // Do not change the comments below - they will be added automatically by CVS
00197 /*****************************************************************************
00198 *       $Log: simpleOrbit.cpp,v $
00199 *       Revision 1.3  2006/08/25 19:14:17  jayhawk_hokie
00200 *       Modified keplerian representation.
00201 *
00202 *       Revision 1.2  2006/08/11 19:50:28  jayhawk_hokie
00203 *       Added config parameters.
00204 *
00205 *       Revision 1.1  2006/08/08 22:11:43  jayhawk_hokie
00206 *       Initial submission.
00207 *
00208 *
00209 *
00210 *
00211 ******************************************************************************/

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