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

GPSObserver.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file GPSObserver.cpp
00003 *  \brief Observes attitute with the GPS algorithm
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 "GPSObserver.h"
00014 
00015 using namespace std;
00016 
00017 /*! \brief Default Constructor */
00018 GPSObserver::GPSObserver( )
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 GPSObserver::GPSObserver( 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 GPSObserver object */
00038 GPSObserver::~GPSObserver( )
00039 { }
00040 
00041 /*! \brief Initialize GPS observer
00042 */
00043 int GPSObserver::Initialize( )
00044 {
00045         /* Host name and port for communicating with the GPS receiver */
00046         static const char               GPS_HOST[]      = "128.173.89.201"; // euripides.ece.vt.edu in GPS Lab
00047         static const unsigned short     GPS_PORT        = 5002; // ports range from 5000-5005
00048 
00049         /* Create Object associated with Ashtech G12 GPS Receiver */
00050         m_SpaceVehicle.Connect( GPS_HOST, GPS_PORT );
00051 
00052         m_WGS84Vector.initialize(6);
00053         m_ECEFVector.initialize(6);
00054         m_ECIVector.initialize(6);
00055 
00056         m_InitialTime = Now( );
00057         
00058         return( 0 );
00059 }
00060 
00061 /*! \brief Parse inertial measurement vectors from configuration file
00062         * @param handle XML handle with current whorl as starting node
00063         */
00064 void GPSObserver::Parse( TiXmlHandle handle )
00065 {
00066 /*
00067         int response;
00068         // create handles with magnetometer and accelerometer nodes as starting points
00069         TiXmlHandle accelElement =  handle.FirstChild( m_whorl->GetSimulatorName( ) ).FirstChild("HARDWARE_PROPERTIES").FirstChild("DMU_ACCELEROMETER");
00070         TiXmlHandle magElement = handle.FirstChild( m_whorl->GetSimulatorName( ) ).FirstChild("HARDWARE_PROPERTIES").FirstChild("MAGNETOMETER");
00071 
00072         // get magnetometer inertial vector and normalize
00073         response = magElement.Child("INERTIAL_VECTOR", 0).Element() ->  QueryDoubleAttribute( "valueX", &(m_magInertial)(1) );
00074         checkResponse(response);
00075         response = magElement.Child("INERTIAL_VECTOR", 0).Element() ->  QueryDoubleAttribute( "valueY", &(m_magInertial)(2) );
00076         checkResponse(response);
00077         response = magElement.Child("INERTIAL_VECTOR", 0).Element() ->  QueryDoubleAttribute( "valueZ", &(m_magInertial)(3) );
00078         checkResponse(response);
00079 
00080         // Normalize magnetmeter inertial vector
00081         normalize( m_magInertial );
00082 
00083         // get accelerometer inertial vector and normalize
00084         response = accelElement.Child("INERTIAL_VECTOR", 0).Element() -> QueryDoubleAttribute( "valueX", &(m_accelInertial)(1) );
00085         checkResponse(response);
00086         response = accelElement.Child("INERTIAL_VECTOR", 0).Element() -> QueryDoubleAttribute( "valueY", &(m_accelInertial)(2) );
00087         checkResponse(response);
00088         response = accelElement.Child("INERTIAL_VECTOR", 0).Element() -> QueryDoubleAttribute( "valueZ", &(m_accelInertial)(3) );
00089         checkResponse(response);
00090 */
00091 
00092 }
00093 
00094 /*! \brief Take measurements and update state vector in whorl object */
00095 int GPSObserver::Run( )
00096 {
00097         
00098         /* Get Current Position */
00099         if ( m_SpaceVehicle.GetCurrentPosition( m_SpaceVehiclePosition ) )
00100         {
00101                 cerr << "WARNING: GPS Status returned failure.  "<< endl;
00102                 return( 0 );
00103         }
00104 
00105         if (  m_SpaceVehiclePosition.m_numSatellites <= 4 )
00106         {
00107                 cerr << "WARNING: Number of GPS Satellites less than 4.  "<< endl;
00108                 return( 0 );
00109         }
00110 
00111 
00112         /* Print gps data to screen */
00113         //GPS2Screen( m_SpaceVehiclePosition );
00114 
00115         TangentPlaneState( m_SpaceVehiclePosition, m_WGS84Vector );
00116         
00117         m_ECEFVector = WGS842ECEF( m_WGS84Vector(1), m_WGS84Vector(2), m_WGS84Vector(3),  m_WGS84Vector(4),  m_WGS84Vector(5),  m_WGS84Vector(6) );
00118 
00119         /* Determine Time */
00120         static ssfTime currentTime = Now( );
00121         static tm currentTimetm;
00122         currentTimetm = currentTime.GetDateTime( );
00123         tm G12Time;
00124         G12Time.tm_mday = currentTimetm.tm_mday;
00125         G12Time.tm_mon = currentTimetm.tm_mon;
00126         G12Time.tm_year = currentTimetm.tm_year;
00127         G12Time.tm_hour = int( m_SpaceVehiclePosition.m_UTC_Timetag ) /10000; // hour
00128         G12Time.tm_min = int( ( m_SpaceVehiclePosition.m_UTC_Timetag - double( G12Time.tm_hour )*10000 ) /100 ); // minute
00129         G12Time.tm_sec = int( ( m_SpaceVehiclePosition.m_UTC_Timetag - G12Time.tm_hour*10000 ) - G12Time.tm_min*100 ); // second
00130         static double u_sec = ( ( m_SpaceVehiclePosition.m_UTC_Timetag - G12Time.tm_hour*10000 ) - G12Time.tm_min*100 ) - G12Time.tm_sec; // second
00131         static ssfTime GPSTime( G12Time );
00132         static ssfTime Time( GPSTime.GetSeconds( ) + u_sec );
00133 
00134 
00135         m_ECIVector = ECEF2ECI( m_ECEFVector, Time.GetJulianDate( ) );
00136 
00137         /* Determine Osculating Orbital Elements */
00138         m_SpaceVehicleOsculatingCOE.SetOsculatingOrbitalElements( m_ECIVector/1000 );
00139 
00140         /* Determine Mean Orbital Elements */
00141         m_SpaceVehicleMeanCOE = m_SpaceVehicleOsculatingCOE.GetMeanOrbitalElements( ) ;
00142         static double a, e, i, Lon, Arg, tru, E, M, M0;
00143                                 a = m_SpaceVehicleMeanCOE.GetSemimajorAxis( );
00144                                 e = m_SpaceVehicleMeanCOE.GetEccentricity( );
00145                                 i = m_SpaceVehicleMeanCOE.GetInclination( );
00146                                 Lon = m_SpaceVehicleMeanCOE.GetLongAscNode( );
00147                                 Arg = m_SpaceVehicleMeanCOE.GetArgPerigee( );
00148                                 tru = m_SpaceVehicleMeanCOE.GetTrueAnomaly( );
00149                                 E = m_SpaceVehicleMeanCOE.GetEccentricAnomaly( );
00150                                 M = m_SpaceVehicleMeanCOE.GetMeanAnomaly( );
00151                                 M0 = M - m_SpaceVehicleMeanCOE.GetMeanMotion( ) * ( Time.GetSeconds( ) - m_InitialTime.GetSeconds( ) );
00152         /*
00153                                 cout << endl << endl << "Mean CLassical Orbital Elements: " <<  endl
00154                                 << "Semi-Major Axis (km): " << a << endl
00155                                 << "Eccentricity: " << e << endl
00156                                 << "Inclination (deg): " << Rad2Deg(i) << endl
00157                                 << "Longitude of Ascending Node (deg): " << Rad2Deg(Lon) <<  endl
00158                                 << "Argument of Peripsis (deg): " << Rad2Deg(Arg) << endl
00159                                 //<< "True Anomaly (deg): " << Rad2Deg(tru) << endl
00160                                  << "Mean Anomaly: " << M <<  endl;
00161         */
00162 
00163         m_whorl->SetCOE( m_SpaceVehicleMeanCOE );
00164         m_whorl->SetOscCOE( m_SpaceVehicleOsculatingCOE.GetOsculatingOrbitalElements( ) );
00165         m_whorl->SetECI( m_ECIVector );
00166 
00167         return( 0 );
00168 }
00169 
00170 Vector GPSObserver::GetWGS84( )
00171 {
00172         return( m_WGS84Vector );
00173 }
00174 
00175 Vector GPSObserver::GetECEF( )
00176 {
00177         return( m_ECEFVector );
00178 }
00179 
00180 Vector GPSObserver::GetECI( )
00181 {
00182         return( m_ECIVector );
00183 }
00184 
00185 Keplerian GPSObserver::GetOsculatingOrbitalElements( )
00186 {
00187         return( m_SpaceVehicleOsculatingCOE.GetOsculatingOrbitalElements( ) );
00188 }
00189 
00190 Keplerian GPSObserver::GetMeanOrbitalElements( )
00191 {
00192         return( m_SpaceVehicleMeanCOE );
00193 }
00194 
00195 
00196 void GPSObserver::GPS2Screen( AshtechG12_GPS_PhysicalDevice::Position _spaceVehicle )
00197 {
00198         cout << "......Navigation Information Obtained from GPS Receiver......." << endl;
00199         cout << "RTCM... " << _spaceVehicle.m_RTCM << endl;
00200         cout << "Num Sats...   " <<  _spaceVehicle.m_numSatellites << endl;
00201         printf ("UTC Timetag: %6.2f\n", _spaceVehicle.m_UTC_Timetag);
00202         cout << "latitude... " << _spaceVehicle.m_latitude << endl;
00203         cout << "latitude sector... " << _spaceVehicle.m_latitudeSector << endl;
00204         cout << "long... " << _spaceVehicle.m_longitude << endl;
00205         cout << "long sector... " << _spaceVehicle.m_longitudeSector << endl;
00206         cout << "alt.. " << _spaceVehicle.m_altitude << endl;
00207         cout << "ground.. " << _spaceVehicle.m_groundTrack << endl;
00208         cout << "speed.. " << _spaceVehicle.m_groundSpeed << endl;
00209         cout << "vert.. " << _spaceVehicle.m_verticalVelocity << endl;
00210         cout << "Pdop.. " << _spaceVehicle.m_PDOP << endl;
00211         cout << "hdop.. " << _spaceVehicle.m_HDOP << endl;
00212         cout << "vdop.. " << _spaceVehicle.m_VDOP << endl;
00213         cout << "Tdop.. " << _spaceVehicle.m_TDOP << endl;
00214 }
00215 
00216 
00217 // Do not change the comments below - they will be added automatically by CVS
00218 /*****************************************************************************
00219 *       $Log: GPSObserver.cpp,v $
00220 *       Revision 1.1  2007/08/31 16:09:30  jayhawk_hokie
00221 *       Initial Submission.
00222 *
00223 *
00224 *
00225 ******************************************************************************/
00226 
00227 

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