00001 #pragma ident "$Id: GeneralEquations.hpp 2939 2011-10-23 19:55:11Z yanweignss $"
00002
00008 #ifndef GPSTK_GENERALEQUATIONS_HPP
00009 #define GPSTK_GENERALEQUATIONS_HPP
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <vector>
00034 #include <map>
00035 #include <iostream>
00036 #include <iomanip>
00037 #include "EquationSystem.hpp"
00038 #include "DataStructures.hpp"
00039
00040 namespace gpstk
00041 {
00042 using namespace std;
00043
00044
00046 typedef std::map<SatID,SourceID> SatSourceMap;
00047
00048 typedef std::map<SourceID,SatID> SourceSatMap;
00049
00050
00054 class GeneralEquations
00055 {
00056 public:
00058 struct SatData
00059 {
00060 std::vector<SatID> satellite;
00061 std::vector<double> elevation;
00062 std::vector<bool> csflag;
00063 std::vector<bool> lockflag;
00064
00065 void addData(SatID sat, double eleva=0.0, double cflag=0.0,
00066 bool lflag=false)
00067 {
00068 satellite.push_back(sat);
00069 elevation.push_back(eleva);
00070 csflag.push_back(cflag);
00071 lockflag.push_back(lflag);
00072 }
00073
00074 inline int indexOfSat(const SatID& sat) const;
00075 inline int indexOfReferenceSat(double minElev = 90.0);
00076 inline int indexOfReferenceSat(SatID oldSat,double minElev = 35.0);
00077
00078 };
00080 typedef std::map<SourceID,SatData> SourceSatDataMap;
00081
00082 public:
00083
00085 GeneralEquations()
00086 { init(); }
00087
00088
00090 ~GeneralEquations() {}
00091
00092
00094 EquationSystem getEquationSystem()
00095 { return getEquations(); }
00096
00097
00099 ConstraintSystem getConstraintSystem()
00100 { return getConstraints(); }
00101
00102
00104 ConstraintSystem getConstraintSystem(gnssRinex& gRin)
00105 {
00106 gnssDataMap gdsMap; gdsMap.addGnssRinex(gRin);
00107 updateSourceSatDataMap(gdsMap);
00108 ConstraintSystem toReturn = getConstraints(gRin);
00109 remarkCycleSlip(gRin);
00110
00111 return toReturn;
00112 }
00113
00114
00116 ConstraintSystem getConstraintSystem(gnssDataMap& gdsMap)
00117 {
00118 updateSourceSatDataMap(gdsMap);
00119 ConstraintSystem toReturn = getConstraints(gdsMap);
00120 remarkCycleSlip(gdsMap);
00121
00122 return toReturn;
00123 }
00124
00125
00126
00127 GeneralEquations& setCoordinatesStatic()
00128 {
00129 pCoordXStoModel = &defaultStochasticModel;
00130 pCoordYStoModel = &defaultStochasticModel;
00131 pCoordZStoModel = &defaultStochasticModel;
00132
00133 return (*this);
00134 };
00135
00136 GeneralEquations& setCoordinatesKinematic(double sigmaX,
00137 double sigmaY,
00138 double sigmaZ)
00139 {
00140 defaultXCoordinatesModel.setSigma(sigmaX);
00141 defaultYCoordinatesModel.setSigma(sigmaY);
00142 defaultZCoordinatesModel.setSigma(sigmaZ);
00143
00144 pCoordXStoModel = &defaultXCoordinatesModel;
00145 pCoordYStoModel = &defaultYCoordinatesModel;
00146 pCoordZStoModel = &defaultZCoordinatesModel;
00147
00148 return (*this);
00149 };
00150
00151 StochasticModel* getXCoordinatesModel() const
00152 { return pCoordXStoModel; };
00153
00154
00155 GeneralEquations& setXCoordinatesModel(StochasticModel* pModel)
00156 { pCoordXStoModel = pModel; return (*this); };
00157
00158
00159 StochasticModel* getYCoordinatesModel() const
00160 { return pCoordYStoModel; };
00161
00162
00163 GeneralEquations& setYCoordinatesModel(StochasticModel* pModel)
00164 { pCoordYStoModel = pModel; return (*this); };
00165
00166
00167 StochasticModel* getZCoordinatesModel() const
00168 { return pCoordZStoModel; };
00169
00170
00171 GeneralEquations& setZCoordinatesModel(StochasticModel* pModel)
00172 { pCoordZStoModel = pModel; return (*this); };
00173
00174
00175 GeneralEquations& setCoordinatesModel(StochasticModel* pModel);
00176
00177
00178 StochasticModel* getTroposphereModel(void) const
00179 { return pTropStoModel; };
00180
00181
00182 GeneralEquations& setTroposphereModel(StochasticModel* pModel)
00183 { pTropStoModel = pModel; return (*this); };
00184
00185
00186 virtual StochasticModel* getIonosphereModel(void) const
00187 { return pIonoStoModel; };
00188
00189
00190 virtual GeneralEquations& setIonosphereModel(StochasticModel* pModel)
00191 { pIonoStoModel = pModel; return (*this); };
00192
00193
00194 virtual StochasticModel* getReceiverClockModel(void) const
00195 { return pClockStoModel; };
00196
00197
00198 virtual GeneralEquations& setReceiverClockModel(StochasticModel* pModel)
00199 { pClockStoModel = pModel; return (*this); };
00200
00201
00202 virtual StochasticModel* getSatClockModel(void) const
00203 { return pSatClockStoModel; };
00204
00205
00206 virtual GeneralEquations& setSatClockModel(StochasticModel* pModel)
00207 { pSatClockStoModel = pModel; return (*this); };
00208
00209
00210
00211 virtual bool getEstimatePosition(void) const
00212 { return estimatePosition; };
00213
00214
00215 virtual GeneralEquations& setEstimatePosition(bool flag = true)
00216 { estimatePosition = flag; return (*this); };
00217
00218
00219 virtual bool getEstimateTropsphere(void) const
00220 { return estimateTropsphere; };
00221
00222
00223 virtual GeneralEquations& setEstimateTropsphere(bool flag = true)
00224 { estimateTropsphere = flag; return (*this); };
00225
00226
00227 virtual bool getEstimateIonosphere(void) const
00228 { return estimateIonosphere; };
00229
00230
00231 virtual GeneralEquations& setEstimateIonosphere(bool flag = true)
00232 { estimateIonosphere = flag; return (*this); };
00233
00234
00235 SourceSatDataMap getSourceSatDataMap()
00236 { return sourceSatDataMap; }
00237
00238
00239 inline void dumpSourceSatData(ostream& s,SourceSatDataMap dataMap);
00240
00241
00242 SatSourceMap getRefSatSourceMap()
00243 { return refsatSourceMap; }
00244
00245
00246 SourceSatMap getSourceRefSatMap()
00247 { return sourceRefsatMap; }
00248
00249
00250 inline EquationSystem getPPPEquations(const SourceID& source);
00251
00252 protected:
00253
00254 virtual EquationSystem getEquations() = 0;
00255
00256
00257 virtual ConstraintSystem getConstraints()
00258 { return ConstraintSystem(); }
00259
00260
00261 virtual ConstraintSystem getConstraints(gnssRinex& gRin)
00262 { return ConstraintSystem(); }
00263
00264
00265 virtual ConstraintSystem getConstraints(gnssDataMap& gdsMap)
00266 { return ConstraintSystem(); }
00267
00268
00270 inline virtual void init();
00271
00272
00274 inline void remarkCycleSlip(gnssRinex& gRin);
00275
00276
00278 inline void remarkCycleSlip(gnssDataMap& gdsMap);
00279
00280
00282 inline void resetCSFlag(const SatSourceMap& satSource,
00283 const SourceSatMap& sourceSat,
00284 SourceSatDataMap& dataMap);
00285
00288 inline void synchronizeCSFlag(const SourceSatDataMap& dataMap,
00289 gnssRinex& gRin);
00290
00291
00294 inline void synchronizeCSFlag(const SourceSatDataMap& dataMap,
00295 gnssDataMap& gdsMap);
00296
00297
00299 inline void updateSourceSatDataMap(const gnssDataMap& gdsMap);
00300
00301
00302 bool estimatePosition;
00303 bool estimateTropsphere;
00304 bool estimateIonosphere;
00305
00307 StochasticModel* pCoordXStoModel;
00308 StochasticModel* pCoordYStoModel;
00309 StochasticModel* pCoordZStoModel;
00310
00312 StochasticModel* pClockStoModel;
00313
00315 StochasticModel* pSatClockStoModel;
00316
00318 StochasticModel* pTropStoModel;
00319
00321 StochasticModel* pIonoStoModel;
00322
00324 StochasticModel* pBiasStoModelL1;
00325
00327 StochasticModel* pBiasStoModelL2;
00328
00330 StochasticModel* pBiasStoModelLC;
00331
00333 StochasticModel* pBiasStoModelWL;
00334
00336 StochasticModel* pBiasStoModelWL2;
00337
00339 StochasticModel* pBiasStoModelWL3;
00340
00342 SourceSatDataMap sourceSatDataMap;
00343
00345 SatSourceMap refsatSourceMap;
00346
00348 SourceSatMap sourceRefsatMap;
00349
00350 private:
00351
00353 StochasticModel defaultStochasticModel;
00354 WhiteNoiseModel defaultWhiteNoiseModel;
00355 RandomWalkModel defaultTropModel;
00356 WhiteNoiseModel defaultIonoModel;
00357 PhaseAmbiguityModel defaultPhaseAmbiguityModel;
00358
00359 WhiteNoiseModel defaultXCoordinatesModel;
00360 WhiteNoiseModel defaultYCoordinatesModel;
00361 WhiteNoiseModel defaultZCoordinatesModel;
00362
00363 PhaseAmbiguityModel sm_ambL1;
00364 PhaseAmbiguityModel sm_ambL2;
00365 PhaseAmbiguityModel sm_ambLC;
00366 PhaseAmbiguityModel sm_ambWL;
00367 PhaseAmbiguityModel sm_ambWL2;
00368 PhaseAmbiguityModel sm_ambWL3;
00369 };
00370
00371
00372 inline void GeneralEquations::init()
00373 {
00374 defaultTropModel.setQprime(3.0e-8);
00375 defaultIonoModel.setSigma(100.0);
00376
00377 estimatePosition = true;
00378 estimateTropsphere = true;
00379 estimateIonosphere = true;
00380
00381 const double sigmaCoordXYZ = 0.1;
00382 defaultXCoordinatesModel.setSigma(sigmaCoordXYZ);
00383 defaultYCoordinatesModel.setSigma(sigmaCoordXYZ);
00384 defaultZCoordinatesModel.setSigma(sigmaCoordXYZ);
00385
00386 pCoordXStoModel = &defaultStochasticModel;
00387 pCoordYStoModel = &defaultStochasticModel;
00388 pCoordZStoModel = &defaultStochasticModel;
00389
00390 pClockStoModel = &defaultWhiteNoiseModel;
00391 pSatClockStoModel = &defaultWhiteNoiseModel;
00392
00393 pTropStoModel = &defaultTropModel;
00394 pIonoStoModel = &defaultIonoModel;
00395
00396 pBiasStoModelL1 = &sm_ambL1;
00397 pBiasStoModelL2 = &sm_ambL2;
00398
00399 pBiasStoModelLC = &sm_ambLC;
00400
00401 pBiasStoModelWL = &sm_ambWL;
00402 pBiasStoModelWL2 = &sm_ambWL2;
00403 pBiasStoModelWL3 = &sm_ambWL3;
00404
00405 }
00406
00407
00408
00409 inline void GeneralEquations::remarkCycleSlip(gnssRinex& gRin)
00410 {
00411 SourceSatDataMap dataMap = getSourceSatDataMap();
00412 resetCSFlag(refsatSourceMap,sourceRefsatMap,dataMap);
00413 synchronizeCSFlag(dataMap,gRin);
00414
00415 }
00416
00417
00419 inline void GeneralEquations::remarkCycleSlip(gnssDataMap& gdsMap)
00420 {
00421 SourceSatDataMap dataMap = getSourceSatDataMap();
00422 resetCSFlag(refsatSourceMap,sourceRefsatMap,dataMap);
00423 synchronizeCSFlag(dataMap,gdsMap);
00424
00425 }
00426
00427
00428
00429 inline void GeneralEquations::resetCSFlag(const SatSourceMap& satSource,
00430 const SourceSatMap& sourceSat,
00431 SourceSatDataMap& dataMap)
00432 {
00433 for(SatSourceMap::const_iterator it = satSource.begin();
00434 it!=satSource.end();
00435 ++it)
00436 {
00437 SatID sat(it->first);
00438 SourceID source(it->second);
00439
00440 int index = dataMap[source].indexOfSat(sat);
00441 if(index <0)
00442 {
00443 Exception e("The satellite not exist in the input GDS");
00444 GPSTK_THROW(e);
00445 }
00446
00447 bool refCS = dataMap[source].csflag[index];
00448
00449 if(refCS==false) continue;
00450
00451 for(SourceSatDataMap::iterator its = dataMap.begin();
00452 its!=dataMap.end();
00453 ++its)
00454 {
00455 int i = its->second.indexOfSat(sat);
00456 if(i>=0) its->second.csflag[i] = refCS;
00457 }
00458 }
00459
00460 for(SourceSatMap::const_iterator it = sourceSat.begin();
00461 it!=sourceSat.end();
00462 ++it)
00463 {
00464 SatID sat(it->second);
00465 SourceID source(it->first);
00466
00467 int index = dataMap[source].indexOfSat(sat);
00468 if(index <0)
00469 {
00470 Exception e("The satellite not exist in the input GDS");
00471 GPSTK_THROW(e);
00472 }
00473
00474 bool refCS = dataMap[source].csflag[index];
00475
00476 if(refCS==false) continue;
00477
00478 for(int i=0;i<dataMap[source].satellite.size();i++)
00479 {
00480 dataMap[source].csflag[i] = refCS;
00481 }
00482 }
00483
00484 }
00485
00486
00487
00488
00489 inline void GeneralEquations::synchronizeCSFlag(
00490 const SourceSatDataMap& dataMap,
00491 gnssRinex& gRin )
00492 {
00493 SourceID source = gRin.header.source;
00494
00495 SourceSatDataMap::const_iterator it = dataMap.find(source);
00496 if(it==dataMap.end()) return;
00497
00498 for(int i = 0; i< it->second.satellite.size();i++)
00499 {
00500 SatID sat(it->second.satellite[i]);
00501 double csValue = it->second.csflag[i]?1.0:0.0;
00502
00503 satTypeValueMap::iterator its = gRin.body.find(sat);
00504 if(its!=gRin.body.end())
00505 {
00506 gRin.body[sat][TypeID::CSL1] = csValue;
00507 gRin.body[sat][TypeID::CSL2] = csValue;
00508 }
00509
00510 }
00511
00512 }
00513
00514
00517 inline void GeneralEquations::synchronizeCSFlag(
00518 const SourceSatDataMap& dataMap,
00519 gnssDataMap& gdsMap)
00520 {
00521
00522 for(gnssDataMap::iterator it = gdsMap.begin();
00523 it != gdsMap.end();
00524 ++it )
00525 {
00526
00527 for(sourceDataMap::iterator sdmIter = it->second.begin();
00528 sdmIter != it->second.end();
00529 ++sdmIter)
00530 {
00531 SourceID source(sdmIter->first);
00532
00533
00534 for(satTypeValueMap::iterator stvmIter = sdmIter->second.begin();
00535 stvmIter != sdmIter->second.end();
00536 ++stvmIter )
00537 {
00538 SatID sat(stvmIter->first);
00539
00540 SourceSatDataMap::const_iterator its = dataMap.find(source);
00541 if(its!=dataMap.end())
00542 {
00543 int index = its->second.indexOfSat(sat);
00544 if(index>=0)
00545 {
00546 double csValue = its->second.csflag[index]?1.0:0.0;
00547
00548 stvmIter->second[TypeID::CSL1] = csValue;
00549 stvmIter->second[TypeID::CSL2] = csValue;
00550 }
00551 }
00552
00553 }
00554
00555 }
00556
00557 }
00558
00559 }
00560
00561
00562
00563 inline void GeneralEquations::updateSourceSatDataMap(
00564 const gnssDataMap& gdsMap)
00565 {
00566 SourceSatDataMap dataMap;
00567
00568
00569 for(gnssDataMap::const_iterator it = gdsMap.begin();
00570 it != gdsMap.end();
00571 ++it )
00572 {
00573
00574 sourceDataMap::const_iterator sdmIter;
00575 for(sdmIter=it->second.begin();
00576 sdmIter!=it->second.end();
00577 ++sdmIter)
00578 {
00579 SourceID source(sdmIter->first);
00580 SatData data;
00581
00582
00583 satTypeValueMap::const_iterator stvmIter;
00584 for( stvmIter = sdmIter->second.begin();
00585 stvmIter != sdmIter->second.end();
00586 ++stvmIter )
00587 {
00588 SatID sat(stvmIter->first);
00589
00590 typeValueMap::const_iterator itt1 =
00591 stvmIter->second.find(TypeID::elevation);
00592
00593 typeValueMap::const_iterator itt2 =
00594 stvmIter->second.find(TypeID::CSL1);
00595
00596 if( (itt1==stvmIter->second.end()) ||
00597 (itt2==stvmIter->second.end()) )
00598 {
00599 Exception e("The elevation should be exist but not.");
00600 GPSTK_THROW(e);
00601 }
00602
00603 data.addData(sat, itt1->second,
00604 (itt2->second>0.0)?true:false, false);
00605
00606 }
00607
00608 dataMap[source] = data;
00609 }
00610
00611 }
00612
00613 sourceSatDataMap = dataMap;
00614
00615 }
00616
00617
00618
00619 inline int GeneralEquations::SatData::indexOfSat(const SatID& sat) const
00620 {
00621 int index(-1);
00622
00623 for(int i=0;i<satellite.size();i++)
00624 {
00625 if(satellite[i]==sat)
00626 {
00627 index = i;
00628 break;
00629 }
00630 }
00631 return index;
00632
00633 }
00634
00635
00636
00637 inline int GeneralEquations::SatData::indexOfReferenceSat(double minElev)
00638 {
00639 map<SatID,int> satCS,satNoCS;
00640 for(int i=0;i<satellite.size();i++)
00641 {
00642 if(csflag[i]==true) satCS[satellite[i]]=i;
00643 else satNoCS[satellite[i]]=i;
00644 }
00645
00646 int index(-1);
00647
00648
00649 int indexMaxElev(-1);
00650 double maxElev(-90);
00651 for( map<SatID,int>::iterator it = satNoCS.begin();
00652 it != satNoCS.end();
00653 ++it)
00654 {
00655 if(lockflag[it->second]==true) continue;
00656
00657 if( (elevation[it->second]>=minElev)) return it->second;
00658
00659 if(elevation[it->second]>maxElev)
00660 {
00661 maxElev = elevation[it->second];
00662 indexMaxElev = it->second;
00663 }
00664 }
00665
00666 if(indexMaxElev>=0) return indexMaxElev;
00667
00668
00669 indexMaxElev = -1;
00670 maxElev = -90;
00671 for( map<SatID,int>::iterator it = satCS.begin();
00672 it != satCS.end();
00673 ++it)
00674 {
00675 if(lockflag[it->second]==true) continue;
00676
00677 if( (elevation[it->second]>=minElev)) return it->second;
00678
00679 if(elevation[it->second]>maxElev)
00680 {
00681 maxElev = elevation[it->second];
00682 indexMaxElev = it->second;
00683 }
00684 }
00685
00686 if(indexMaxElev>=0) return indexMaxElev;
00687
00688
00689
00690 Exception e("Failed to pick up any satellite as reference.");
00691 GPSTK_THROW(e);
00692
00693 return 0;
00694
00695 }
00696
00697
00698
00699 inline int GeneralEquations::SatData::indexOfReferenceSat(SatID oldSat,
00700 double minElev)
00701 {
00702 int index(-1);
00703 for(int i=0;i<satellite.size();i++)
00704 {
00705 if(satellite[i]==oldSat)
00706 {
00707 index = i;
00708 break;
00709 }
00710 }
00711
00712 if(index>-1)
00713 {
00714 if( elevation[index]>=minElev &&
00715 csflag[index]==false && lockflag[index]==false)
00716 {
00717 return index;
00718 }
00719 }
00720
00721 return indexOfReferenceSat(90.0);
00722
00723 }
00724
00725
00726 inline void GeneralEquations::dumpSourceSatData(ostream& s,
00727 SourceSatDataMap dataMap)
00728 {
00729 for(SourceSatDataMap::iterator it=dataMap.begin();
00730 it!=dataMap.end();
00731 ++it)
00732 {
00733 s << StringUtils::asString(it->first) << endl;
00734
00735 for(int i=0;i<it->second.satellite.size();i++)
00736 {
00737 s << setw(5)<< i << " "
00738 << StringUtils::asString(it->second.satellite[i])<<" "
00739 << it->second.csflag[i] <<" "
00740 << it->second.lockflag[i]<<" "
00741 << it->second.elevation[i]<<endl;
00742 }
00743 }
00744
00745 }
00746
00747
00748 EquationSystem GeneralEquations::getPPPEquations(const SourceID& source)
00749 {
00750 Variable dx(TypeID::dLat, pCoordXStoModel, true, false, 100.0);
00751 Variable dy(TypeID::dLon, pCoordYStoModel, true, false, 100.0);
00752 Variable dz(TypeID::dH, pCoordZStoModel, true, false, 100.0);
00753
00754 Variable cdt(TypeID::cdt,pClockStoModel,true,false,4e14,+1.0,true);
00755 Variable trop(TypeID::wetMap,pTropStoModel,true,false,0.25);
00756 Variable amb(TypeID::BLC,pBiasStoModelLC,true,true,4e14,1.0,true);
00757
00758
00759
00760 Variable prefitPC(TypeID::prefitC);
00761 Variable prefitLC(TypeID::prefitL);
00762
00763 Equation equPCRover( prefitPC );
00764 equPCRover.addVariable(dx);
00765 equPCRover.addVariable(dy);
00766 equPCRover.addVariable(dz);
00767 equPCRover.addVariable(cdt);
00768 equPCRover.addVariable(trop);
00769
00770 equPCRover.header.equationSource = source;
00771
00772
00773 Equation equLCRover( prefitLC );
00774 equLCRover.addVariable(dx);
00775 equLCRover.addVariable(dy);
00776 equLCRover.addVariable(dz);
00777 equLCRover.addVariable(cdt);
00778 equLCRover.addVariable(trop);
00779 equLCRover.addVariable(amb);
00780
00781 equLCRover.setWeight(10000.0);
00782 equLCRover.header.equationSource = source;
00783
00784
00785 EquationSystem system;
00786 system.addEquation(equPCRover);
00787 system.addEquation(equLCRover);
00788
00789 return system;
00790
00791 }
00792
00793 }
00794
00795
00796 #endif // GPSTK_GENERALEQUATIONS_HPP
00797