Changeset 5740 in ntrip


Ignore:
Timestamp:
Aug 2, 2014, 4:22:22 PM (8 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC/src/PPP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/PPP/pppClient.cpp

    r5734 r5740  
     1
     2// Part of BNC, a utility for retrieving decoding and
     3// converting GNSS data streams from NTRIP broadcasters.
     4//
     5// Copyright (C) 2007
     6// German Federal Agency for Cartography and Geodesy (BKG)
     7// http://www.bkg.bund.de
     8// Czech Technical University Prague, Department of Geodesy
     9// http://www.fsv.cvut.cz
     10//
     11// Email: euref-ip@bkg.bund.de
     12//
     13// This program is free software; you can redistribute it and/or
     14// modify it under the terms of the GNU General Public License
     15// as published by the Free Software Foundation, version 2.
     16//
     17// This program is distributed in the hope that it will be useful,
     18// but WITHOUT ANY WARRANTY; without even the implied warranty of
     19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     20// GNU General Public License for more details.
     21//
     22// You should have received a copy of the GNU General Public License
     23// along with this program; if not, write to the Free Software
     24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     25
     26/* -------------------------------------------------------------------------
     27 * BKG NTRIP Client
     28 * -------------------------------------------------------------------------
     29 *
     30 * Class:      t_pppClient
     31 *
     32 * Purpose:    PPP Client processing starts here
     33 *
     34 * Author:     L. Mervart
     35 *
     36 * Created:    29-Jul-2014
     37 *
     38 * Changes:   
     39 *
     40 * -----------------------------------------------------------------------*/
     41
    142
    243#include <iostream>
     
    1051#include "obspool.h"
    1152#include "satbias.h"
    12 #include "genconst.h"
    13 #include "utils.h"
     53#include "bncconst.h"
     54#include "bncutils.h"
    1455#include "station.h"
    15 #include "tides.h"
    16 #include "antex.h"
     56#include "bnctides.h"
     57#include "bncantex.h"
    1758#include "filter.h"
    1859
     
    3374  _ephPool  = new t_ephPool();
    3475  _obsPool  = new t_obsPool();
    35   _staRover = new t_station(e_rover);
    36   _staBase  = new t_station(e_base);
     76  _staRover = new t_station();
    3777  _filter   = new t_filter();
    3878}
     
    4686  delete _obsPool;
    4787  delete _staRover;
    48   delete _staBase;
    4988  delete _antex;
    5089  delete _filter;
     
    5493//
    5594//////////////////////////////////////////////////////////////////////////////
    56 void t_pppClient::setOptions(const t_pppOpt* opt) {
     95void t_pppClient::setOptions(const t_options* opt) {
    5796  delete _opt;
    58   _opt = new t_options(opt);
     97  _opt = new t_options(*opt);
    5998
    6099  delete _antex; _antex = 0;
    61   if (!_opt->antexFileName().empty()) {
    62     _antex = new t_antex(_opt->antexFileName());
    63   }
    64 
    65   _opt->print();
     100  if (!_opt->_antexFile.empty()) {
     101    _antex = new bncAntex(_opt->_antexFile.c_str());
     102  }
    66103}
    67104
     
    80117//
    81118//////////////////////////////////////////////////////////////////////////////
    82 void t_pppClient::putOrbCorrections(int numCorr, const t_pppOrbCorr* corr) {
     119void t_pppClient::putOrbCorrections(int numCorr, const t_orbCorr* corr) {
    83120  for (int ii = 0; ii < numCorr; ii++) {
    84121    _ephPool->putOrbCorrection(new t_orbCorr(corr[ii]));
     
    88125//
    89126//////////////////////////////////////////////////////////////////////////////
    90 void t_pppClient::putClkCorrections(int numCorr, const t_pppClkCorr* corr) {
     127void t_pppClient::putClkCorrections(int numCorr, const t_clkCorr* corr) {
    91128  for (int ii = 0; ii < numCorr; ii++) {
    92129    _ephPool->putClkCorrection(new t_clkCorr(corr[ii]));
     
    96133//
    97134//////////////////////////////////////////////////////////////////////////////
    98 void t_pppClient::putBiases(int numBiases, const t_pppSatBiases* biases) {
     135void t_pppClient::putBiases(int numBiases, const t_satBiases* biases) {
    99136  for (int ii = 0; ii < numBiases; ii++) {
    100137    _obsPool->putBiases(new t_satBias(biases[ii]));
     
    104141//
    105142//////////////////////////////////////////////////////////////////////////////
    106 t_irc::irc t_pppClient::prepareObs(int numSat, const t_pppSatObs* satObs,
    107                                  vector<t_satObs*>& obsVector, t_time& epoTime) {
     143t_irc t_pppClient::prepareObs(int numSat, const t_pppSatObs* satObs,
     144                                 vector<t_satObs*>& obsVector, bncTime& epoTime) {
    108145  // Default
    109146  // -------
     
    114151  int numValidGPS = 0;
    115152  for (int ii = 0; ii < numSat; ii++) {
    116     char system = satObs[ii]._satellite._system;
     153    char system = satObs[ii]._prn.system();
    117154    if (system == 'G' || (system == 'R' && OPT->useGlonass())) {
    118155      t_satObs* satObs = new t_satObs(satObs[ii]);
     
    142179      if (fabs(dt) > MAXSYNC) {
    143180        LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
    144         return t_irc::failure;
     181        return failure;
    145182      }
    146183      meanDt += dt;
     
    149186  epoTime += meanDt / obsVector.size();
    150187
    151   return t_irc::success;
     188  return success;
    152189}
    153190
    154191// Compute the Bancroft position, check for blunders
    155192//////////////////////////////////////////////////////////////////////////////
    156 t_irc::irc t_pppClient::cmpBancroft(const t_time& epoTime,
     193t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
    157194                                  vector<t_satObs*>& obsVector,
    158195                                  ColumnVector& xyzc, bool print) {
     
    166203      const t_satObs* satObs = obsVector.at(ii);
    167204      if ( satObs->isValid() && satObs->prn().system() == 'G' &&
    168            (!satObs->modelSet() || satObs->eleSat() >= OPT->minEle()) ) {
     205           (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
    169206        ++iObs;   
    170207        BB[iObs][0] = satObs->xc()[0];
     
    174211      }
    175212    }
    176     if (iObs + 1 < OPT->minobs()) {
     213    if (iObs + 1 < OPT->_minObs) {
    177214      LOG << "t_pppClient::cmpBancroft not enough observations" << endl;
    178       return t_irc::failure;
     215      return failure;
    179216    }
    180217    BB = BB.Rows(1,iObs+1);
    181218    bancroft(BB, xyzc);
    182219
    183     xyzc[3] /= t_genConst::c;
     220    xyzc[3] /= t_CST::c;
    184221
    185222    // Check Blunders
     
    191228      const t_satObs* satObs = obsVector.at(ii);
    192229      if ( satObs->isValid() && satObs->prn().system() == 'G' &&
    193            (!satObs->modelSet() || satObs->eleSat() >= OPT->minEle()) ) {
     230           (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
    194231        ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
    195232        double res = rr.norm_Frobenius() - satObs->obsValue(tLC)
    196           - (satObs->xc()[3] - xyzc[3]) * t_genConst::c;
     233          - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
    197234        if (fabs(res) > maxRes) {
    198235          maxRes      = fabs(res);
     
    208245            << setw(14) << setprecision(3) << xyzc[1] << ' '
    209246            << setw(14) << setprecision(3) << xyzc[2] << ' '
    210             << setw(14) << setprecision(3) << xyzc[3] * t_genConst::c << endl << endl;
     247            << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
    211248      }
    212249      break;
     
    221258  }
    222259
    223   return t_irc::success;
     260  return success;
    224261}
    225262
     
    239276        t_satObs* satObs = obsVector.at(ii);
    240277        if ( !satObs->outlier() && satObs->isValid() && satObs->prn().system() == 'R' &&
    241              (!satObs->modelSet() || satObs->eleSat() >= OPT->minEle()) ) {
     278             (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
    242279          ++nObs;
    243280          double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
     
    270307void t_pppClient::initOutput(t_pppOutput* output) {
    271308  _output = output;
    272   _output->_epoTime._mjd = 0;
    273   _output->_epoTime._sec = 0.0;
    274   _output->_numSat       = 0;
    275   _output->_pDop         = 0.0;
    276   _output->_ambFixRate   = 0.0;
    277   _output->_log          = 0;
    278   _output->_error        = false;
     309  _output->_numSat = 0;
     310  _output->_pDop   = 0.0;
     311  _output->_error  = false;
    279312}
    280313
     
    286319  }
    287320  _obsRover.clear();
    288   for (unsigned ii = 0; ii < _obsBase.size(); ii++) {
    289     delete _obsBase.at(ii);
    290   }
    291   _obsBase.clear();
    292 }
    293 
    294 //
    295 //////////////////////////////////////////////////////////////////////////////
    296 void t_pppClient::finish(t_irc::irc irc) {
     321}
     322
     323//
     324//////////////////////////////////////////////////////////////////////////////
     325void t_pppClient::finish(t_irc irc) {
    297326
    298327  clearObs();
    299328
    300   _output->_epoTime._mjd = _epoTimeRover.mjd();
    301   _output->_epoTime._sec = _epoTimeRover.daysec();
    302 
    303   if (irc == t_irc::success) {
     329  _output->_epoTime = _epoTimeRover;
     330
     331  if (irc == success) {
    304332    _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
    305333    _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
     
    308336    _output->_numSat     = _filter->numSat();
    309337    _output->_pDop       = _filter->PDOP();
    310     _output->_ambFixRate = _filter->ambFixRate();
    311338    _output->_error = false;
    312339  }
     
    314341    _output->_error = true;
    315342  }
    316   if (OPT->logLevel() > 0) {
    317     _output->_log = strdup(_log->str().c_str());
    318   }
     343  _output->_log = _log->str();
    319344  delete _log; _log = new ostringstream();
    320345}
     
    322347//
    323348//////////////////////////////////////////////////////////////////////////////
    324 t_irc::irc t_pppClient::cmpModel(t_station* station, const ColumnVector& xyzc,
     349t_irc t_pppClient::cmpModel(t_station* station, const ColumnVector& xyzc,
    325350                               vector<t_satObs*>& obsVector) {
    326351
    327   t_time time;
    328   if (station->roverBase() == e_rover) {
    329     time = _epoTimeRover;
    330     station->setName(OPT->roverName());
    331     station->setAntName(OPT->antNameRover());
    332     if (OPT->xyzAprRoverSet()) {
    333       station->setXyzApr(OPT->xyzAprRover());
    334     }
    335     else {
    336       station->setXyzApr(xyzc.Rows(1,3));
    337     }
    338     station->setNeuEcc(OPT->neuEccRover());
     352  bncTime time;
     353  time = _epoTimeRover;
     354  station->setName(OPT->_roverName);
     355  station->setAntName(OPT->_antNameRover);
     356  if (OPT->xyzAprRoverSet()) {
     357    station->setXyzApr(OPT->_xyzAprRover);
    339358  }
    340359  else {
    341     time = _epoTimeBase;
    342     station->setName(OPT->baseName());
    343     station->setAntName(OPT->antNameBase());
    344     station->setXyzApr(OPT->xyzAprBase());
    345     station->setNeuEcc(OPT->neuEccBase());
    346   }
     360    station->setXyzApr(xyzc.Rows(1,3));
     361  }
     362  station->setNeuEcc(OPT->_neuEccRover);
    347363
    348364  // Receiver Clock
     
    356372  // Tides
    357373  // -----
    358   station->setTideDspl(t_tides::displacement(time, station->xyzApr()));
     374  ColumnVector hlp = station->xyzApr();
     375  tides(time, hlp);
     376  station->setTideDspl(hlp - station->xyzApr());
    359377 
    360378  // Observation model
     
    364382    t_satObs* satObs = *it;
    365383    satObs->cmpModel(station);
    366     if (satObs->isValid() && satObs->eleSat() >= OPT->minEle()) {
     384    if (satObs->isValid() && satObs->eleSat() >= OPT->_minEle) {
    367385      ++it;
    368386    }
     
    373391  }
    374392
    375   return t_irc::success;
    376 }
    377 
    378 //
    379 //////////////////////////////////////////////////////////////////////////////
    380 t_irc::irc t_pppClient::createDifferences() {
    381 
    382   vector<t_satObs*>::iterator it = _obsRover.begin();
    383   while (it != _obsRover.end()) {
    384     t_satObs* obsR = *it;
    385     t_satObs* obsB = 0;
    386     for (unsigned ii = 0; ii < _obsBase.size(); ii++) {
    387       if (_obsBase[ii]->prn() == obsR->prn()) {
    388         obsB = _obsBase[ii];
    389         break;
    390       }
    391     }
    392     if (obsB) {
    393       obsR->createDifference(obsB);
    394       ++it;
    395     }
    396     else {
    397       delete obsR;
    398       it = _obsRover.erase(it);
    399     }
    400   }
    401 
    402   return t_irc::success;
     393  return success;
    403394}
    404395
     
    414405    // ---------------------------------   
    415406    if (prepareObs(numSatRover, satObsRover, _obsRover,
    416                     _epoTimeRover) != t_irc::success) {
    417       return finish(t_irc::failure);
     407                    _epoTimeRover) != success) {
     408      return finish(failure);
    418409    }
    419410
     
    425416      ColumnVector xyzc(4); xyzc = 0.0;
    426417      bool print = (iter == 2);
    427       if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != t_irc::success) {
    428         return finish(t_irc::failure);
    429       }
    430       if (cmpModel(_staRover, xyzc, _obsRover) != t_irc::success) {
    431         return finish(t_irc::failure);
     418      if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
     419        return finish(failure);
     420      }
     421      if (cmpModel(_staRover, xyzc, _obsRover) != success) {
     422        return finish(failure);
    432423      }
    433424    }
    434425
    435426    _offGG = cmpOffGG(_obsRover);
    436 
    437     // Prepare Observations of the Base
    438     // --------------------------------   
    439     if (OPT->isDifferential()) {
    440       if (prepareObs(numSatBase, satObsBase, _obsBase,
    441                      _epoTimeBase) != t_irc::success) {
    442         return finish(t_irc::failure);
    443       }
    444       ColumnVector xyzc(4); xyzc = 0.0;
    445       if (cmpModel(_staBase, xyzc, _obsBase) != t_irc::success) {
    446         return finish(t_irc::failure);
    447       }
    448       if (cmpBancroft(_epoTimeBase, _obsBase, xyzc, true) != t_irc::success) {
    449         return finish(t_irc::failure);
    450       }
    451       _staBase->setDClk(xyzc[3]);
    452 
    453       _offGG -= cmpOffGG(_obsBase);
    454 
    455       // Create single-differences of observations
    456       // -----------------------------------------
    457       if (createDifferences() != t_irc::success) {
    458         return finish(t_irc::failure);
    459       }
    460       for (unsigned ii = 0; ii < _obsBase.size(); ii++) {
    461         delete _obsBase[ii];
    462       }
    463       _obsBase.clear();
    464     }
    465427
    466428    // Store last epoch of data
     
    470432    // Process Epoch in Filter
    471433    // -----------------------
    472     if (_filter->processEpoch(_obsPool) != t_irc::success) {
    473       return finish(t_irc::failure);
     434    if (_filter->processEpoch(_obsPool) != success) {
     435      return finish(failure);
    474436    }
    475437  }
    476438  catch (Exception& exc) {
    477439    LOG << exc.what() << endl;
    478     return finish(t_irc::failure);
     440    return finish(failure);
    479441  }
    480442  catch (string& msg) {
    481443    LOG << "Exception: " << msg << endl;
    482     return finish(t_irc::failure);
     444    return finish(failure);
    483445  }
    484446  catch (logic_error exc) {
    485447    LOG << exc.what() << endl;
    486     return finish(t_irc::failure);
     448    return finish(failure);
    487449  }
    488450  catch (const char* msg) {
    489451    LOG << msg << endl;
    490     return finish(t_irc::failure);
     452    return finish(failure);
    491453  }
    492454  catch (...) {
    493455    LOG << "unknown exception" << endl;
    494     return finish(t_irc::failure);
    495   }
    496 
    497   return finish(t_irc::success);
    498 }
     456    return finish(failure);
     457  }
     458
     459  return finish(success);
     460}
     461
     462//
     463////////////////////////////////////////////////////////////////////////////
     464double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
     465  return aa[0]*bb[0] +  aa[1]*bb[1] +  aa[2]*bb[2] -  aa[3]*bb[3];
     466}
     467
     468//
     469////////////////////////////////////////////////////////////////////////////
     470void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
     471
     472  if (pos.Nrows() != 4) {
     473    pos.ReSize(4);
     474  }
     475  pos = 0.0;
     476
     477  for (int iter = 1; iter <= 2; iter++) {
     478    Matrix BB = BBpass;
     479    int mm = BB.Nrows();
     480    for (int ii = 1; ii <= mm; ii++) {
     481      double xx = BB(ii,1);
     482      double yy = BB(ii,2);
     483      double traveltime = 0.072;
     484      if (iter > 1) {
     485        double zz  = BB(ii,3);
     486        double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
     487                           (yy-pos(2)) * (yy-pos(2)) +
     488                           (zz-pos(3)) * (zz-pos(3)) );
     489        traveltime = rho / t_CST::c;
     490      }
     491      double angle = traveltime * t_CST::omega;
     492      double cosa  = cos(angle);
     493      double sina  = sin(angle);
     494      BB(ii,1) =  cosa * xx + sina * yy;
     495      BB(ii,2) = -sina * xx + cosa * yy;
     496    }
     497   
     498    Matrix BBB;
     499    if (mm > 4) {
     500      SymmetricMatrix hlp; hlp << BB.t() * BB;
     501      BBB = hlp.i() * BB.t();
     502    }
     503    else {
     504      BBB = BB.i();
     505    }
     506    ColumnVector ee(mm); ee = 1.0;
     507    ColumnVector alpha(mm); alpha = 0.0;
     508    for (int ii = 1; ii <= mm; ii++) {
     509      alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
     510    }
     511    ColumnVector BBBe     = BBB * ee;
     512    ColumnVector BBBalpha = BBB * alpha;
     513    double aa = lorentz(BBBe, BBBe);
     514    double bb = lorentz(BBBe, BBBalpha)-1;
     515    double cc = lorentz(BBBalpha, BBBalpha);
     516    double root = sqrt(bb*bb-aa*cc);
     517
     518    Matrix hlpPos(4,2);
     519    hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
     520    hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
     521
     522    ColumnVector omc(2);
     523    for (int pp = 1; pp <= 2; pp++) {
     524      hlpPos(4,pp)      = -hlpPos(4,pp);
     525      omc(pp) = BB(1,4) -
     526                sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
     527                      (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
     528                      (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
     529                hlpPos(4,pp);
     530    }
     531    if ( fabs(omc(1)) > fabs(omc(2)) ) {
     532      pos = hlpPos.Column(2);
     533    }
     534    else {
     535      pos = hlpPos.Column(1);
     536    }
     537  }
     538}
     539
  • trunk/BNC/src/PPP/pppClient.h

    r5734 r5740  
    44#include <sstream>
    55#include <vector>
    6 #include "RTCM3/ephemeris.h"
     6#include "ppp.h"
     7#include "ephemeris.h"
     8#include "options.h"
     9
     10class bncAntex;
    711
    812namespace BNC {
     
    1216class t_satObs;
    1317class t_station;
    14 class t_antex;
    1518class t_filter;
    1619
     
    1922  t_pppClient();                                                     
    2023  ~t_pppClient();                                                     
    21   void setOptions(const t_pppOpt* opt);                         
     24  void setOptions(const t_options* opt);                         
    2225  void putGPSEphemeris(const t_ephGPS* eph);                 
    2326  void putGloEphemeris(const t_ephGlo* eph);                 
    24   void putOrbCorrections(int numCorr, const t_pppOrbCorr* corr);
    25   void putClkCorrections(int numCorr, const t_pppClkCorr* corr);
    26   void putBiases(int numBiases, const t_pppSatBiases* biases);   
     27  void putOrbCorrections(int numCorr, const t_orbCorr* corr);
     28  void putClkCorrections(int numCorr, const t_clkCorr* corr);
     29  void putBiases(int numBiases, const t_satBiases* biases);   
    2730  void processEpoch(int numSatRover, const t_pppSatObs* satObsRover,
    2831                    t_pppOutput* output);                       
    2932  const t_ephPool* ephPool() const {return _ephPool;}
    3033  const t_obsPool* obsPool() const {return _obsPool;}
    31   const t_antex*   antex() const {return _antex;}
     34  const bncAntex*  antex() const {return _antex;}
    3235  const t_station* staRover() const {return _staRover;}
    3336  double offGG() const {return _offGG;}
     37  static void bancroft(const Matrix& BBpass, ColumnVector& pos);
    3438
    3539  std::ostringstream* _log;
     
    3842 private:
    3943  void initOutput(t_pppOutput* output);
    40   void finish(t_irc::irc irc);
     44  void finish(t_irc irc);
    4145  void clearObs();
    42   t_irc::irc prepareObs(int numSat, const t_pppSatObs* satObs,
    43                         std::vector<t_satObs*>& obsVector, t_time& epoTime);
    44   t_irc::irc cmpModel(t_station* station, const ColumnVector& xyzc,
     46  t_irc prepareObs(int numSat, const t_pppSatObs* satObs,
     47                        std::vector<t_satObs*>& obsVector, bncTime& epoTime);
     48  t_irc cmpModel(t_station* station, const ColumnVector& xyzc,
    4549                      std::vector<t_satObs*>& obsVector);
    46   t_irc::irc cmpBancroft(const t_time& epoTime,
     50  t_irc cmpBancroft(const bncTime& epoTime,
    4751                         std::vector<t_satObs*>& obsVector,
    4852                         ColumnVector& xyzc, bool print);
    49   t_irc::irc createDifferences();
    5053  double cmpOffGG(std::vector<t_satObs*>& obsVector);
    5154
     
    5356  t_ephPool*             _ephPool;
    5457  t_obsPool*             _obsPool;
    55   t_time                 _epoTimeRover;
    56   t_time                 _epoTimeBase;
     58  bncTime                _epoTimeRover;
    5759  t_station*             _staRover;
    58   t_station*             _staBase;
    59   t_antex*               _antex;
     60  bncAntex*              _antex;
    6061  t_filter*              _filter;
    6162  double                 _offGG;
    6263  std::vector<t_satObs*> _obsRover;
    63   std::vector<t_satObs*> _obsBase;
    6464
    6565};
Note: See TracChangeset for help on using the changeset viewer.