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

OrbitPropObserver.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file OrbitPropObserver.cpp
00003 *  \brief Orbit propagator observer class.
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.1 $
00006 *  \date    $Date: 2007/08/31 16:09:30 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /*!
00009 */
00010 //////////////////////////////////////////////////////////////////////////////////////////////////
00011 
00012 
00013 #include "OrbitPropObserver.h"
00014 
00015 using namespace std;
00016 
00017 /*! \brief Default Constructor */
00018 OrbitPropObserver::OrbitPropObserver( )
00019 {
00020         Initialize( );
00021 }
00022 
00023 /*! \brief Create a GPS observer from XML handle and whorl object
00024  *  @param handle XML handle with current whorl as starting node
00025  *  @param ptr_whorl Pointer to a whorl object
00026  */
00027 OrbitPropObserver::OrbitPropObserver( TiXmlHandle handle, Whorl* ptr_whorl )
00028 {
00029         m_whorl = ptr_whorl;
00030 
00031         Initialize( );
00032 
00033         // call parse function to get inertial measurement vectors
00034         Parse( handle );
00035 }
00036 
00037 /*! \brief DeConstructor for OrbitPropObserver object */
00038 OrbitPropObserver::~OrbitPropObserver( )
00039 { }
00040 
00041 /*! \brief Initialize GPS observer
00042 */
00043 int OrbitPropObserver::Initialize( )
00044 {
00045 
00046         /* Host name and port for communicating with the Numerical Propagator */
00047         static const char               HOST[]  = "severian.aoe.vt.edu"; //"128.173.191.9"; // severian.aoe.vt.edu
00048         static const unsigned short     PORT    = 30002; // Port specified by server program
00049 
00050         try
00051         {
00052 
00053         /* Create Client Socket to communicate with numerical propagator */
00054         m_clientSocket = new ClientSocket;
00055         m_clientSocket -> Connect( HOST, PORT );
00056         //m_clientSocket -> Connect( "128.173.191.9", 30002 );
00057 
00058         cerr << "Connected to Propagator Host. " << endl;
00059 
00060         }
00061         catch ( SocketException& e )
00062         {
00063                 std::cout << "Exception was caught:" << e.description() << "\n";
00064         }
00065 
00066         m_ECIVector.initialize(6);
00067 
00068         /* Vehicle Id number */
00069         m_vehicleID = 1;
00070         
00071         /* Current time */
00072         m_currentTime = Now( );
00073 
00074         /* Radial, In-track, Cross-Track directions [m/s^2] */
00075         m_acceleration.initialize(3);        
00076         //m_controlTorque.initialize(3);
00077         //Vector m_acceleration;
00078 
00079         /* Space Vehicle mass [kg] */
00080         m_mass = 100;
00081  
00082         return( 0 );
00083 }
00084 
00085 /*! \brief Parse inertial measurement vectors from configuration file
00086         * @param handle XML handle with current whorl as starting node
00087         */
00088 void OrbitPropObserver::Parse( TiXmlHandle handle )
00089 {
00090 
00091 }
00092 
00093 /*! \brief Take measurements and update state vector in whorl object */
00094 int OrbitPropObserver::Run( )
00095 {
00096         m_currentTime = Now( );
00097 
00098         /* Get Current Position ECI [km, km/s] */
00099         m_ECIVector = GetState( m_clientSocket, m_vehicleID, m_currentTime.GetSeconds( ), m_acceleration, m_mass );
00100         
00101         /* Determine Osculating Orbital Elements */
00102         m_SpaceVehicleOsculatingCOE.SetOsculatingOrbitalElements( m_ECIVector/1000 );
00103 
00104         /* Determine Mean Orbital Elements */
00105         m_SpaceVehicleMeanCOE = m_SpaceVehicleOsculatingCOE.GetMeanOrbitalElements( ) ;
00106 
00107         /* Set ECI */
00108         m_whorl->SetECI( m_ECIVector );
00109         
00110         /* Set Osculating Orbital Elements */
00111         m_whorl->SetOscCOE( m_SpaceVehicleOsculatingCOE.GetOsculatingOrbitalElements( ) );
00112         
00113         /* Set Mean Classical Orbital Elements */
00114         m_whorl->SetCOE( m_SpaceVehicleMeanCOE );
00115 
00116         return( 0 );
00117 }
00118 
00119 Vector OrbitPropObserver::GetState( ClientSocket *_clientSocket, int _vehicleID, double _currentTime, CAMdoubleVector _acceleration, double _newMass )
00120 {
00121         ostringstream dataOut;
00122         dataOut.precision( 18 );
00123         dataOut << "SC" << _vehicleID << " " << "GET_STATE" << " " << _currentTime << " " << _acceleration(1)
00124                 << " " << _acceleration(2) << " " << _acceleration(3) << " " << _newMass << endl;
00125 
00126         //cout << dataOut.str( ) << endl;
00127         string reply;
00128         try
00129         {
00130                 /* Send string */
00131                 *_clientSocket << dataOut.str( );
00132                 /* Receive string */
00133                 *_clientSocket >> reply;
00134         }
00135         catch ( SocketException& e )
00136         {
00137                 std::cout << "Exception was caught:" << e.description() << "\n";
00138         }
00139 
00140         return ( ParseState( reply ) );
00141 }
00142 
00143 Vector OrbitPropObserver::ParseState( string _reply )
00144 {
00145         stringstream parseString;
00146         parseString.str( _reply );
00147 
00148         string command;
00149         CAMdoubleVector ECIVector(6);
00150 
00151         parseString >> command;
00152 
00153         if( command =="Failure" )
00154         {
00155                 cerr << "BAD RESPONSE from SERVER " << endl;
00156         }
00157         if( command == "STATE" )
00158         {
00159                 for ( int iterator = 1; iterator < 7; iterator++ )
00160                 {
00161                         parseString >> ECIVector( iterator );
00162                 }
00163         }
00164         else
00165         {
00166                 cerr << "ERROR in Parsing LOOP" << endl;
00167         }
00168 
00169         return ( ECIVector );
00170 };
00171 
00172 
00173 // Do not change the comments below - they will be added automatically by CVS
00174 /*****************************************************************************
00175 *       $Log: OrbitPropObserver.cpp,v $
00176 *       Revision 1.1  2007/08/31 16:09:30  jayhawk_hokie
00177 *       Initial Submission.
00178 *
00179 *
00180 *
00181 ******************************************************************************/
00182 
00183 

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