BasicModel.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: BasicModel.cpp 2939 2011-10-23 19:55:11Z yanweignss $"
00002 
00010 //============================================================================
00011 //
00012 //  This file is part of GPSTk, the GPS Toolkit.
00013 //
00014 //  The GPSTk is free software; you can redistribute it and/or modify
00015 //  it under the terms of the GNU Lesser General Public License as published
00016 //  by the Free Software Foundation; either version 2.1 of the License, or
00017 //  any later version.
00018 //
00019 //  The GPSTk is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU Lesser General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU Lesser General Public
00025 //  License along with GPSTk; if not, write to the Free Software Foundation,
00026 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 //
00028 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2007, 2008, 2009
00029 //
00030 //============================================================================
00031 
00032 
00033 #include "BasicModel.hpp"
00034 
00035 
00036 namespace gpstk
00037 {
00038 
00039 
00040       // Index initially assigned to this class
00041    int BasicModel::classIndex = 4000000;
00042 
00043 
00044       // Returns an index identifying this object.
00045    int BasicModel::getIndex() const
00046    { return index; }
00047 
00048 
00049       // Returns a string identifying this object.
00050    std::string BasicModel::getClassName() const
00051    { return "BasicModel"; }
00052 
00053 
00054 
00055       /* Explicit constructor taking as input reference
00056        * station coordinates.
00057        *
00058        * Those coordinates may be Cartesian (X, Y, Z in meters) or Geodetic
00059        * (Latitude, Longitude, Altitude), but defaults to Cartesian.
00060        *
00061        * Also, a pointer to GeoidModel may be specified, but default is
00062        * NULL (in which case WGS84 values will be used).
00063        *
00064        * @param aRx   first coordinate [ X(m), or latitude (degrees N) ]
00065        * @param bRx   second coordinate [ Y(m), or longitude (degrees E) ]
00066        * @param cRx   third coordinate [ Z, height above ellipsoid or
00067        *              radius, in meters ]
00068        * @param s     coordinate system (default is Cartesian, may be set
00069        *              to Geodetic).
00070        * @param geoid pointer to GeoidModel (default is null, implies WGS84)
00071        */
00072    BasicModel::BasicModel( const double& aRx,
00073                            const double& bRx,
00074                            const double& cRx,
00075                            Position::CoordinateSystem s,
00076                            GeoidModel *geoid )
00077    {
00078 
00079       minElev = 10.0;
00080       pDefaultEphemeris = NULL;
00081       defaultObservable = TypeID::C1;
00082       useTGD = false;
00083       setInitialRxPosition(aRx, bRx, cRx, s, geoid);
00084       setIndex();
00085 
00086    }  // End of 'BasicModel::BasicModel()'
00087 
00088 
00089       // Explicit constructor, taking as input a Position object
00090       // containing reference station coordinates.
00091    BasicModel::BasicModel(const Position& RxCoordinates)
00092    {
00093 
00094       minElev = 10.0;
00095       pDefaultEphemeris = NULL;
00096       defaultObservable = TypeID::C1;
00097       useTGD = false;
00098       setInitialRxPosition(RxCoordinates);
00099       setIndex();
00100 
00101    }  // End of 'BasicModel::BasicModel()'
00102 
00103 
00104 
00105       /* Explicit constructor, taking as input reference station
00106        * coordinates, ephemeris to be used, default observable
00107        * and whether TGD will be computed or not.
00108        *
00109        * @param RxCoordinates Reference station coordinates.
00110        * @param dEphemeris    EphemerisStore object to be used by default.
00111        * @param dObservable   Observable type to be used by default.
00112        * @param applyTGD      Whether or not C1 observable will be
00113        *                      corrected from TGD effect or not.
00114        *
00115        */
00116    BasicModel::BasicModel( const Position& RxCoordinates,
00117                            XvtStore<SatID>& dEphemeris,
00118                            const TypeID& dObservable,
00119                            const bool& applyTGD )
00120    {
00121 
00122       minElev = 10.0;
00123       setInitialRxPosition(RxCoordinates);
00124       setDefaultEphemeris(dEphemeris);
00125       defaultObservable = dObservable;
00126       useTGD = applyTGD;
00127       setIndex();
00128 
00129    }  // End of 'BasicModel::BasicModel()'
00130 
00131 
00132 
00133       /* Returns a satTypeValueMap object, adding the new data generated when
00134        * calling a modeling object.
00135        *
00136        * @param time      Epoch.
00137        * @param gData     Data object holding the data.
00138        */
00139    satTypeValueMap& BasicModel::Process( const DayTime& time,
00140                                          satTypeValueMap& gData )
00141       throw(ProcessingException)
00142    {
00143 
00144       try
00145       {
00146 
00147          SatIDSet satRejectedSet;
00148 
00149             // Loop through all the satellites
00150          satTypeValueMap::iterator stv;
00151          for( stv = gData.begin();
00152               stv != gData.end();
00153               ++stv )
00154          {
00155                // Scalar to hold temporal value
00156             double observable( (*stv).second(defaultObservable) );
00157 
00158                // A lot of the work is done by a CorrectedEphemerisRange object
00159             CorrectedEphemerisRange cerange;
00160 
00161             try
00162             {
00163                   // Compute most of the parameters
00164                cerange.ComputeAtTransmitTime( time,
00165                                               observable,
00166                                               rxPos,
00167                                               (*stv).first,
00168                                               *(getDefaultEphemeris()) );
00169             }
00170             catch(InvalidRequest& e)
00171             {
00172 
00173                   // If some problem appears, then schedule this satellite
00174                   // for removal
00175                satRejectedSet.insert( (*stv).first );
00176 
00177                continue;    // Skip this SV if problems arise
00178 
00179             }
00180 
00181                // Let's test if satellite has enough elevation over horizon
00182             if ( rxPos.elevationGeodetic(cerange.svPosVel) < minElev )
00183             {
00184 
00185                   // Mark this satellite if it doesn't have enough elevation
00186                satRejectedSet.insert( (*stv).first );
00187 
00188                continue;
00189 
00190             }
00191 
00192                // Computing Total Group Delay (TGD - meters), if possible
00193             double tempTGD(getTGDCorrections( time,
00194                                               (*pDefaultEphemeris),
00195                                               (*stv).first ) );
00196 
00197                // Now we have to add the new values to the data structure
00198             (*stv).second[TypeID::dtSat] = cerange.svclkbias;
00199 
00200                // Now, lets insert the geometry matrix
00201             (*stv).second[TypeID::dx] = cerange.cosines[0];
00202             (*stv).second[TypeID::dy] = cerange.cosines[1];
00203             (*stv).second[TypeID::dz] = cerange.cosines[2];
00204 
00205             (*stv).second[TypeID::dSatX] = -cerange.cosines[0];
00206             (*stv).second[TypeID::dSatY] = -cerange.cosines[1];
00207             (*stv).second[TypeID::dSatZ] = -cerange.cosines[2];
00208 
00209                // When using pseudorange method, this is 1.0
00210             (*stv).second[TypeID::cdt] = 1.0;
00211 
00212                // Now we have to add the new values to the data structure
00213             (*stv).second[TypeID::rho] = cerange.rawrange;
00214             (*stv).second[TypeID::rel] = -cerange.relativity;
00215             (*stv).second[TypeID::elevation] = cerange.elevationGeodetic;
00216             (*stv).second[TypeID::azimuth] = cerange.azimuthGeodetic;
00217 
00218                // Let's insert satellite position at transmission time
00219             (*stv).second[TypeID::satX] = cerange.svPosVel.x[0];
00220             (*stv).second[TypeID::satY] = cerange.svPosVel.x[1];
00221             (*stv).second[TypeID::satZ] = cerange.svPosVel.x[2];
00222 
00223                // Let's insert satellite velocity at transmission time
00224             (*stv).second[TypeID::satVX] = cerange.svPosVel.v[0];
00225             (*stv).second[TypeID::satVY] = cerange.svPosVel.v[1];
00226             (*stv).second[TypeID::satVZ] = cerange.svPosVel.v[2];
00227 
00228                // Let's insert receiver position 
00229             (*stv).second[TypeID::recX] = rxPos.X();
00230             (*stv).second[TypeID::recY] = rxPos.Y();
00231             (*stv).second[TypeID::recZ] = rxPos.Z();
00232 
00233                // Let's insert receiver velocity 
00234             (*stv).second[TypeID::recVX] = 0.0;
00235             (*stv).second[TypeID::recVY] = 0.0;
00236             (*stv).second[TypeID::recVZ] = 0.0;
00237 
00238                // Apply correction to C1 observable, if appropriate
00239             if(useTGD)
00240             {
00241                   // Look for C1
00242                if( (*stv).second.find(TypeID::C1) != (*stv).second.end() )
00243                {
00244                   (*stv).second[TypeID::C1] =
00245                                        (*stv).second[TypeID::C1] - tempTGD;
00246                };
00247             };
00248 
00249             (*stv).second[TypeID::instC1] = tempTGD;
00250 
00251          } // End of loop for(stv = gData.begin()...
00252 
00253             // Remove satellites with missing data
00254          gData.removeSatID(satRejectedSet);
00255 
00256          return gData;
00257 
00258       }   // End of try...
00259       catch(Exception& u)
00260       {
00261             // Throw an exception if something unexpected happens
00262          ProcessingException e( getClassName() + ":"
00263                                 + StringUtils::asString( getIndex() ) + ":"
00264                                 + u.what() );
00265 
00266          GPSTK_THROW(e);
00267 
00268       }
00269 
00270    }  // End of method 'BasicModel::Process()'
00271 
00272 
00273 
00274       /* Method to set the initial (a priori) position of receiver.
00275        * @return
00276        *  0 if OK
00277        *  -1 if problems arose
00278        */
00279    int BasicModel::setInitialRxPosition( const double& aRx,
00280                                          const double& bRx,
00281                                          const double& cRx,
00282                                          Position::CoordinateSystem s,
00283                                          GeoidModel *geoid )
00284    {
00285 
00286       try
00287       {
00288          Position rxpos(aRx, bRx, cRx, s, geoid);
00289          setInitialRxPosition(rxpos);
00290          return 0;
00291       }
00292       catch(GeometryException& e)
00293       {
00294          return -1;
00295       }
00296 
00297    }  // End of method 'BasicModel::setInitialRxPosition()'
00298 
00299 
00300 
00301       // Method to set the initial (a priori) position of receiver.
00302    int BasicModel::setInitialRxPosition(const Position& RxCoordinates)
00303    {
00304 
00305       try
00306       {
00307          rxPos = RxCoordinates;
00308          return 0;
00309       }
00310       catch(GeometryException& e)
00311       {
00312          return -1;
00313       }
00314 
00315    }  // End of method 'BasicModel::setInitialRxPosition()'
00316 
00317 
00318 
00319       // Method to set the initial (a priori) position of receiver.
00320    int BasicModel::setInitialRxPosition()
00321    {
00322       try
00323       {
00324          Position rxpos(0.0, 0.0, 0.0, Position::Cartesian, NULL);
00325          setInitialRxPosition(rxpos);
00326          return 0;
00327       }
00328       catch(GeometryException& e)
00329       {
00330          return -1;
00331       }
00332 
00333    }  // End of method 'BasicModel::setInitialRxPosition()'
00334 
00335 
00336 
00337       // Method to get TGD corrections.
00338    double BasicModel::getTGDCorrections( DayTime Tr,
00339                                          const XvtStore<SatID>& Eph,
00340                                          SatID sat )
00341       throw()
00342    {
00343 
00344       try
00345       {
00346          const GPSEphemerisStore& bce =
00347                                  dynamic_cast<const GPSEphemerisStore&>(Eph);
00348 
00349          bce.findEphemeris(sat,Tr);
00350 
00351          return ( bce.findEphemeris(sat,Tr).getTgd() * C_GPS_M );
00352       }
00353       catch(...)
00354       {
00355          return 0.0;
00356       }
00357 
00358    }  // End of method 'BasicModel::getTGDCorrections()'
00359 
00360 
00361 
00362 }  // End of namespace gpstk

Generated on Tue May 22 03:30:56 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1