| 1 | /* -------------------------------------------------------------------------
|
|---|
| 2 | * BKG NTRIP Client
|
|---|
| 3 | * -------------------------------------------------------------------------
|
|---|
| 4 | *
|
|---|
| 5 | * Class: t_pppClient
|
|---|
| 6 | *
|
|---|
| 7 | * Purpose: PPP Client processing starts here
|
|---|
| 8 | *
|
|---|
| 9 | * Author: L. Mervart
|
|---|
| 10 | *
|
|---|
| 11 | * Created: 29-Jul-2014
|
|---|
| 12 | *
|
|---|
| 13 | * Changes:
|
|---|
| 14 | *
|
|---|
| 15 | * -----------------------------------------------------------------------*/
|
|---|
| 16 |
|
|---|
| 17 | #include <QThreadStorage>
|
|---|
| 18 |
|
|---|
| 19 | #include <iostream>
|
|---|
| 20 | #include <iomanip>
|
|---|
| 21 | #include <cmath>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <string.h>
|
|---|
| 24 | #include <stdexcept>
|
|---|
| 25 |
|
|---|
| 26 | #include "pppClient.h"
|
|---|
| 27 | #include "pppEphPool.h"
|
|---|
| 28 | #include "pppObsPool.h"
|
|---|
| 29 | #include "bncconst.h"
|
|---|
| 30 | #include "bncutils.h"
|
|---|
| 31 | #include "pppStation.h"
|
|---|
| 32 | #include "bncantex.h"
|
|---|
| 33 | #include "pppFilter.h"
|
|---|
| 34 |
|
|---|
| 35 | using namespace BNC_PPP;
|
|---|
| 36 | using namespace std;
|
|---|
| 37 |
|
|---|
| 38 | // Global variable holding thread-specific pointers
|
|---|
| 39 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 40 | QThreadStorage<t_pppClient*> CLIENTS;
|
|---|
| 41 |
|
|---|
| 42 | // Static function returning thread-specific pointer
|
|---|
| 43 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 44 | t_pppClient* t_pppClient::instance() {
|
|---|
| 45 | return CLIENTS.localData();
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | // Constructor
|
|---|
| 49 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 50 | t_pppClient::t_pppClient(const t_pppOptions* opt) {
|
|---|
| 51 | _output = 0;
|
|---|
| 52 | _opt = new t_pppOptions(*opt);
|
|---|
| 53 | _log = new ostringstream();
|
|---|
| 54 | _ephPool = new t_pppEphPool();
|
|---|
| 55 | _obsPool = new t_pppObsPool();
|
|---|
| 56 | _staRover = new t_pppStation();
|
|---|
| 57 | _filter = new t_pppFilter(_obsPool);
|
|---|
| 58 | _tides = new t_tides();
|
|---|
| 59 | _antex = 0;
|
|---|
| 60 | if (!_opt->_antexFileName.empty()) {
|
|---|
| 61 | _antex = new bncAntex(_opt->_antexFileName.c_str());
|
|---|
| 62 | }
|
|---|
| 63 | if (!_opt->_blqFileName.empty()) {
|
|---|
| 64 | if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
|
|---|
| 65 | //_tides->printAllBlqSets();
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | if (_opt->_refSatRequired) {
|
|---|
| 70 | for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
|
|---|
| 71 | char system = _opt->systems()[iSys];
|
|---|
| 72 | _obsPool->initRefSatMapElement(system);
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | _offGG = 0.0;
|
|---|
| 76 | CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | // Destructor
|
|---|
| 80 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 81 | t_pppClient::~t_pppClient() {
|
|---|
| 82 | delete _log;
|
|---|
| 83 | delete _opt;
|
|---|
| 84 | delete _filter;
|
|---|
| 85 | delete _ephPool;
|
|---|
| 86 | delete _obsPool;
|
|---|
| 87 | delete _staRover;
|
|---|
| 88 | if (_antex) {
|
|---|
| 89 | delete _antex;
|
|---|
| 90 | }
|
|---|
| 91 | delete _tides;
|
|---|
| 92 | clearObs();
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | //
|
|---|
| 96 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 97 | void t_pppClient::putEphemeris(const t_eph* eph) {
|
|---|
| 98 | const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
|
|---|
| 99 | const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
|
|---|
| 100 | const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
|
|---|
| 101 | const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
|
|---|
| 102 | if (ephGPS) {
|
|---|
| 103 | _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
|
|---|
| 104 | }
|
|---|
| 105 | else if (ephGlo) {
|
|---|
| 106 | _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
|
|---|
| 107 | }
|
|---|
| 108 | else if (ephGal) {
|
|---|
| 109 | _ephPool->putEphemeris(new t_ephGal(*ephGal));
|
|---|
| 110 | }
|
|---|
| 111 | else if (ephBDS) {
|
|---|
| 112 | _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | //
|
|---|
| 117 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 118 | void t_pppClient::putTec(const t_vTec* vTec) {
|
|---|
| 119 | _obsPool->putTec(new t_vTec(*vTec));
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | //
|
|---|
| 123 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 124 | void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
|
|---|
| 125 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
|---|
| 126 | _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | //
|
|---|
| 131 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 132 | void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
|
|---|
| 133 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
|---|
| 134 | _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | //
|
|---|
| 139 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 140 | void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
|
|---|
| 141 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
|---|
| 142 | _obsPool->putCodeBias(new t_satCodeBias(*biases[ii]));
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | //
|
|---|
| 147 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 148 | void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
|
|---|
| 149 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
|---|
| 150 | _obsPool->putPhaseBias(new t_satPhaseBias(*biases[ii]));
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | //
|
|---|
| 155 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 156 | t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
|
|---|
| 157 | vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
|
|---|
| 158 |
|
|---|
| 159 | // Default
|
|---|
| 160 | // -------
|
|---|
| 161 | epoTime.reset();
|
|---|
| 162 |
|
|---|
| 163 | // Create vector of valid observations
|
|---|
| 164 | // -----------------------------------
|
|---|
| 165 | for (unsigned ii = 0; ii < satObs.size(); ii++) {
|
|---|
| 166 | char system = satObs[ii]->_prn.system();
|
|---|
| 167 | if (_opt->useSystem(system)) {
|
|---|
| 168 | t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
|
|---|
| 169 | if (pppSatObs->isValid()) {
|
|---|
| 170 | obsVector.push_back(pppSatObs);
|
|---|
| 171 | }
|
|---|
| 172 | else {
|
|---|
| 173 | delete pppSatObs;
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | // (re)set reference satellites per system if required
|
|---|
| 179 | // ---------------------------------------------------
|
|---|
| 180 | if (_opt->_refSatRequired) {
|
|---|
| 181 | // reference satellite definition per system
|
|---|
| 182 | for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
|
|---|
| 183 | char system = _opt->systems()[iSys];
|
|---|
| 184 | bool refSatDefined = false;
|
|---|
| 185 | t_pppRefSat* refSat = _obsPool->getRefSatMapElement(system);
|
|---|
| 186 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 187 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 188 | // reference satellite is unchanged
|
|---|
| 189 | if (!_obsPool->refSatChangeRequired() && refSat->prn() == satObs->prn()) {
|
|---|
| 190 | refSatDefined = true;
|
|---|
| 191 | obsVector[ii]->setAsReference();
|
|---|
| 192 | refSat->setStatus(t_pppRefSat::unchanged);
|
|---|
| 193 | }
|
|---|
| 194 | // reference satellite has changed
|
|---|
| 195 | else if ( _obsPool->refSatChangeRequired() && refSat->prn() != satObs->prn()) {
|
|---|
| 196 | if (satObs->prn().system() == system) {
|
|---|
| 197 | refSatDefined = true;
|
|---|
| 198 | obsVector[ii]->setAsReference();
|
|---|
| 199 | refSat->setStatus(t_pppRefSat::changed);
|
|---|
| 200 | refSat->setPrn(satObs->prn());
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | if (refSatDefined) {
|
|---|
| 204 | break;
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | // reference satellite has to be initialized
|
|---|
| 208 | if (!refSatDefined) {
|
|---|
| 209 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 210 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 211 | if (satObs->prn().system() == system) {
|
|---|
| 212 | obsVector[ii]->setAsReference();
|
|---|
| 213 | refSat->setStatus(t_pppRefSat::initialized);
|
|---|
| 214 | refSat->setPrn(satObs->prn());
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 | _obsPool->setRefSatChangeRequired(false);
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | // Check whether data are synchronized, compute epoTime
|
|---|
| 223 | // ----------------------------------------------------
|
|---|
| 224 | const double MAXSYNC = 0.05; // synchronization limit
|
|---|
| 225 | double meanDt = 0.0;
|
|---|
| 226 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 227 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 228 | if (epoTime.undef()) {
|
|---|
| 229 | epoTime = satObs->time();
|
|---|
| 230 | }
|
|---|
| 231 | else {
|
|---|
| 232 | double dt = satObs->time() - epoTime;
|
|---|
| 233 | if (fabs(dt) > MAXSYNC) {
|
|---|
| 234 | LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
|
|---|
| 235 | return failure;
|
|---|
| 236 | }
|
|---|
| 237 | meanDt += dt;
|
|---|
| 238 | }
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | if (obsVector.size() > 0) {
|
|---|
| 242 | epoTime += meanDt / obsVector.size();
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | return success;
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | //
|
|---|
| 249 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 250 | bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
|
|---|
| 251 |
|
|---|
| 252 | bool pseudoObsIono = false;
|
|---|
| 253 |
|
|---|
| 254 | if (_opt->_pseudoObsIono) {
|
|---|
| 255 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 256 | while (it != obsVector.end()) {
|
|---|
| 257 | t_pppSatObs* satObs = *it;
|
|---|
| 258 | char system = satObs->prn().system();
|
|---|
| 259 | t_pppRefSat* refSat = _obsPool->getRefSatMapElement(system);
|
|---|
| 260 | double stecRef = refSat->stecValue();
|
|---|
| 261 | if (stecRef && !satObs->isReference()) {
|
|---|
| 262 | pseudoObsIono = true;
|
|---|
| 263 | satObs->setPseudoObsIono(t_frequency::G1, stecRef);
|
|---|
| 264 | }
|
|---|
| 265 | satObs->printObsMinusComputed();
|
|---|
| 266 | it++;
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | return pseudoObsIono;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | // Compute the Bancroft position, check for blunders
|
|---|
| 274 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 275 | t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
|
|---|
| 276 | vector<t_pppSatObs*>& obsVector,
|
|---|
| 277 | ColumnVector& xyzc, bool print) {
|
|---|
| 278 |
|
|---|
| 279 | t_lc::type tLC = t_lc::dummy;
|
|---|
| 280 |
|
|---|
| 281 | while (true) {
|
|---|
| 282 | Matrix BB(obsVector.size(), 4);
|
|---|
| 283 | int iObs = -1;
|
|---|
| 284 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 285 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 286 | if (tLC == t_lc::dummy) {
|
|---|
| 287 | if (satObs->isValid(t_lc::cIF)) {
|
|---|
| 288 | tLC = t_lc::cIF;
|
|---|
| 289 | }
|
|---|
| 290 | else if (satObs->isValid(t_lc::c1)) {
|
|---|
| 291 | tLC = t_lc::c1;
|
|---|
| 292 | }
|
|---|
| 293 | else if (satObs->isValid(t_lc::c2)) {
|
|---|
| 294 | tLC = t_lc::c2;
|
|---|
| 295 | }
|
|---|
| 296 | }
|
|---|
| 297 | if ( satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
|---|
| 298 | ++iObs;
|
|---|
| 299 | BB[iObs][0] = satObs->xc()[0];
|
|---|
| 300 | BB[iObs][1] = satObs->xc()[1];
|
|---|
| 301 | BB[iObs][2] = satObs->xc()[2];
|
|---|
| 302 | BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 | if (iObs + 1 < _opt->_minObs) {
|
|---|
| 306 | LOG << "t_pppClient::cmpBancroft not enough observations" << endl;
|
|---|
| 307 | return failure;
|
|---|
| 308 | }
|
|---|
| 309 | BB = BB.Rows(1,iObs+1);
|
|---|
| 310 | bancroft(BB, xyzc);
|
|---|
| 311 |
|
|---|
| 312 | xyzc[3] /= t_CST::c;
|
|---|
| 313 |
|
|---|
| 314 | // Check Blunders
|
|---|
| 315 | // --------------
|
|---|
| 316 | const double BLUNDER = 100.0;
|
|---|
| 317 | double maxRes = 0.0;
|
|---|
| 318 | unsigned maxResIndex = 0;
|
|---|
| 319 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 320 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 321 | if (satObs->isValid() &&
|
|---|
| 322 | satObs->prn().system() == 'G' &&
|
|---|
| 323 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
|---|
| 324 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
|---|
| 325 | double res = rr.NormFrobenius() - satObs->obsValue(tLC)
|
|---|
| 326 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
|---|
| 327 | if (std::isnan(res) || fabs(res) > maxRes) {
|
|---|
| 328 | std::isnan(res) ?
|
|---|
| 329 | maxRes = res :
|
|---|
| 330 | maxRes = fabs(res);
|
|---|
| 331 | maxResIndex = ii;
|
|---|
| 332 | }
|
|---|
| 333 | }
|
|---|
| 334 | }
|
|---|
| 335 | if (!std::isnan(maxRes) && maxRes < BLUNDER) {
|
|---|
| 336 | if (print) {
|
|---|
| 337 | LOG.setf(ios::fixed);
|
|---|
| 338 | LOG << string(epoTime) << " BANCROFT:" << ' '
|
|---|
| 339 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
|---|
| 340 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
|---|
| 341 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
|---|
| 342 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
|---|
| 343 | }
|
|---|
| 344 | break;
|
|---|
| 345 | }
|
|---|
| 346 | else {
|
|---|
| 347 | t_pppSatObs* satObs = obsVector.at(maxResIndex);
|
|---|
| 348 | LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
|
|---|
| 349 | << " " << maxRes << endl;
|
|---|
| 350 | delete satObs;
|
|---|
| 351 | obsVector.erase(obsVector.begin() + maxResIndex);
|
|---|
| 352 | }
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | return success;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | // Compute A Priori GPS-Glonass Offset
|
|---|
| 359 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 360 | double t_pppClient::cmpOffGG(vector<t_pppSatObs*>& obsVector) {
|
|---|
| 361 |
|
|---|
| 362 | t_lc::type tLC = t_lc::dummy;
|
|---|
| 363 | double offGG = 0.0;
|
|---|
| 364 |
|
|---|
| 365 | if (_opt->useSystem('R')) {
|
|---|
| 366 | while (obsVector.size() > 0) {
|
|---|
| 367 | offGG = 0.0;
|
|---|
| 368 | double maxRes = 0.0;
|
|---|
| 369 | int maxResIndex = -1;
|
|---|
| 370 | t_prn maxResPrn;
|
|---|
| 371 | unsigned nObs = 0;
|
|---|
| 372 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 373 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 374 | if (satObs->prn().system() == 'R') {
|
|---|
| 375 | if (tLC == t_lc::dummy) {
|
|---|
| 376 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
|---|
| 377 | }
|
|---|
| 378 | if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
|
|---|
| 379 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
|---|
| 380 | ++nObs;
|
|---|
| 381 | offGG += ll;
|
|---|
| 382 | if (fabs(ll) > fabs(maxRes)) {
|
|---|
| 383 | maxRes = ll;
|
|---|
| 384 | maxResIndex = ii;
|
|---|
| 385 | maxResPrn = satObs->prn();
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | if (nObs > 0) {
|
|---|
| 392 | offGG = offGG / nObs;
|
|---|
| 393 | }
|
|---|
| 394 | else {
|
|---|
| 395 | offGG = 0.0;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | if (fabs(maxRes) > 1000.0) {
|
|---|
| 399 | LOG << "t_pppClient::cmpOffGG outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
|---|
| 400 | delete obsVector.at(maxResIndex);
|
|---|
| 401 | obsVector.erase(obsVector.begin() + maxResIndex);
|
|---|
| 402 | }
|
|---|
| 403 | else {
|
|---|
| 404 | break;
|
|---|
| 405 | }
|
|---|
| 406 | }
|
|---|
| 407 | }
|
|---|
| 408 | return offGG;
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | //
|
|---|
| 412 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 413 | void t_pppClient::initOutput(t_output* output) {
|
|---|
| 414 | _output = output;
|
|---|
| 415 | _output->_numSat = 0;
|
|---|
| 416 | _output->_hDop = 0.0;
|
|---|
| 417 | _output->_error = false;
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | //
|
|---|
| 421 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 422 | void t_pppClient::clearObs() {
|
|---|
| 423 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
|---|
| 424 | delete _obsRover.at(ii);
|
|---|
| 425 | }
|
|---|
| 426 | _obsRover.clear();
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | //
|
|---|
| 430 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 431 | void t_pppClient::finish(t_irc irc) {
|
|---|
| 432 |
|
|---|
| 433 | clearObs();
|
|---|
| 434 |
|
|---|
| 435 | _output->_epoTime = _epoTimeRover;
|
|---|
| 436 |
|
|---|
| 437 | if (irc == success) {
|
|---|
| 438 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
|---|
| 439 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
|---|
| 440 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
|---|
| 441 |
|
|---|
| 442 | xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
|
|---|
| 443 |
|
|---|
| 444 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
|---|
| 445 |
|
|---|
| 446 | _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
|
|---|
| 447 | _output->_trp = _filter->trp();
|
|---|
| 448 | _output->_trpStdev = _filter->trpStdev();
|
|---|
| 449 |
|
|---|
| 450 | _output->_numSat = _filter->numSat();
|
|---|
| 451 | _output->_hDop = _filter->HDOP();
|
|---|
| 452 | _output->_error = false;
|
|---|
| 453 | }
|
|---|
| 454 | else {
|
|---|
| 455 | _output->_error = true;
|
|---|
| 456 | }
|
|---|
| 457 | _output->_log = _log->str();
|
|---|
| 458 | delete _log; _log = new ostringstream();
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | //
|
|---|
| 462 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 463 | t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
|
|---|
| 464 | vector<t_pppSatObs*>& obsVector) {
|
|---|
| 465 | bncTime time;
|
|---|
| 466 | time = _epoTimeRover;
|
|---|
| 467 | station->setName(_opt->_roverName);
|
|---|
| 468 | station->setAntName(_opt->_antNameRover);
|
|---|
| 469 | station->setEpochTime(time);
|
|---|
| 470 | if (_opt->xyzAprRoverSet()) {
|
|---|
| 471 | station->setXyzApr(_opt->_xyzAprRover);
|
|---|
| 472 | }
|
|---|
| 473 | else {
|
|---|
| 474 | station->setXyzApr(xyzc.Rows(1,3));
|
|---|
| 475 | }
|
|---|
| 476 | station->setNeuEcc(_opt->_neuEccRover);
|
|---|
| 477 |
|
|---|
| 478 | // Receiver Clock
|
|---|
| 479 | // --------------
|
|---|
| 480 | station->setDClk(xyzc[3]);
|
|---|
| 481 |
|
|---|
| 482 | // Tides
|
|---|
| 483 | // -----
|
|---|
| 484 | station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
|
|---|
| 485 | station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
|
|---|
| 486 |
|
|---|
| 487 | // Observation model
|
|---|
| 488 | // -----------------
|
|---|
| 489 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 490 | while (it != obsVector.end()) {
|
|---|
| 491 | t_pppSatObs* satObs = *it;
|
|---|
| 492 | t_irc modelSetup;
|
|---|
| 493 | if (satObs->isValid()) {
|
|---|
| 494 | modelSetup = satObs->cmpModel(station);
|
|---|
| 495 | }
|
|---|
| 496 | if (satObs->isValid() &&
|
|---|
| 497 | satObs->eleSat() >= _opt->_minEle &&
|
|---|
| 498 | modelSetup == success) {
|
|---|
| 499 | if (satObs->isReference() && _opt->_pseudoObsIono) {
|
|---|
| 500 | char system = satObs->prn().system();
|
|---|
| 501 | t_pppRefSat* refSat = _obsPool->getRefSatMapElement(system);
|
|---|
| 502 | refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
|
|---|
| 503 | }
|
|---|
| 504 | ++it;
|
|---|
| 505 | }
|
|---|
| 506 | else {
|
|---|
| 507 | delete satObs;
|
|---|
| 508 | it = obsVector.erase(it);
|
|---|
| 509 | }
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | return success;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | //
|
|---|
| 516 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 517 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
|---|
| 518 |
|
|---|
| 519 | try {
|
|---|
| 520 | initOutput(output);
|
|---|
| 521 | int num = 0;
|
|---|
| 522 | bool epochReProcessing = false;
|
|---|
| 523 |
|
|---|
| 524 | do {
|
|---|
| 525 | num++;
|
|---|
| 526 |
|
|---|
| 527 | // Prepare Observations of the Rover
|
|---|
| 528 | // ---------------------------------
|
|---|
| 529 | if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
|
|---|
| 530 | return finish(failure);
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | LOG << "\nPPP of Epoch ";
|
|---|
| 534 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
|---|
| 535 | LOG << "\n---------------------------------------------------------------\n";
|
|---|
| 536 |
|
|---|
| 537 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 538 | ColumnVector xyzc(4); xyzc = 0.0;
|
|---|
| 539 | bool print = (iter == 2);
|
|---|
| 540 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
|---|
| 541 | return finish(failure);
|
|---|
| 542 | }
|
|---|
| 543 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
|---|
| 544 | return finish(failure);
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | _offGG = cmpOffGG(_obsRover);
|
|---|
| 549 |
|
|---|
| 550 | // Prepare Pseudo Observations of the Rover
|
|---|
| 551 | // ----------------------------------------
|
|---|
| 552 | _pseudoObsIono = preparePseudoObs(_obsRover);
|
|---|
| 553 | if (int(_obsRover.size()) < _opt->_minObs) {
|
|---|
| 554 | LOG << "t_pppClient::processEpoch not enough observations" << endl;
|
|---|
| 555 | return finish(failure);
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | if (_opt->_refSatRequired) {
|
|---|
| 559 | LOG.setf(ios::fixed);
|
|---|
| 560 | QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
|
|---|
| 561 | while (it.hasNext()) {
|
|---|
| 562 | it.next();
|
|---|
| 563 | char sys = it.key();
|
|---|
| 564 | string prn = it.value()->prn().toString();
|
|---|
| 565 | LOG << string(_epoTimeRover) << " REFSAT " << sys << ": " << prn << endl;
|
|---|
| 566 | }
|
|---|
| 567 | }
|
|---|
| 568 |
|
|---|
| 569 | // Store last epoch of data
|
|---|
| 570 | // ------------------------
|
|---|
| 571 | //_obsRover.resize(2);
|
|---|
| 572 | _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
|
|---|
| 573 |
|
|---|
| 574 | // Process Epoch in Filter
|
|---|
| 575 | // -----------------------
|
|---|
| 576 | if (_filter->processEpoch(num) != success) {
|
|---|
| 577 | return finish(failure);
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | // Epoch re-processing required?
|
|---|
| 581 | // -----------------------------
|
|---|
| 582 | if (_obsPool->refSatChangeRequired()) {
|
|---|
| 583 | epochReProcessing = true;
|
|---|
| 584 | }
|
|---|
| 585 | else {
|
|---|
| 586 | epochReProcessing = false;
|
|---|
| 587 | }
|
|---|
| 588 | // Datum transformation required?
|
|---|
| 589 | // ------------------------------
|
|---|
| 590 | if (num > 1 && epochReProcessing) {
|
|---|
| 591 | _filter->datumTransformation();
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | } while (epochReProcessing);
|
|---|
| 595 | }
|
|---|
| 596 | catch (Exception& exc) {
|
|---|
| 597 | LOG << exc.what() << endl;
|
|---|
| 598 | return finish(failure);
|
|---|
| 599 | }
|
|---|
| 600 | catch (t_except msg) {
|
|---|
| 601 | LOG << msg.what() << endl;
|
|---|
| 602 | return finish(failure);
|
|---|
| 603 | }
|
|---|
| 604 | catch (const char* msg) {
|
|---|
| 605 | LOG << msg << endl;
|
|---|
| 606 | return finish(failure);
|
|---|
| 607 | }
|
|---|
| 608 | catch (...) {
|
|---|
| 609 | LOG << "unknown exception" << endl;
|
|---|
| 610 | return finish(failure);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | return finish(success);
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | //
|
|---|
| 617 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 618 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
|---|
| 619 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
|---|
| 620 | }
|
|---|
| 621 |
|
|---|
| 622 | //
|
|---|
| 623 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 624 | void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
|---|
| 625 |
|
|---|
| 626 | if (pos.Nrows() != 4) {
|
|---|
| 627 | pos.ReSize(4);
|
|---|
| 628 | }
|
|---|
| 629 | pos = 0.0;
|
|---|
| 630 |
|
|---|
| 631 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 632 | Matrix BB = BBpass;
|
|---|
| 633 | int mm = BB.Nrows();
|
|---|
| 634 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 635 | double xx = BB(ii,1);
|
|---|
| 636 | double yy = BB(ii,2);
|
|---|
| 637 | double traveltime = 0.072;
|
|---|
| 638 | if (iter > 1) {
|
|---|
| 639 | double zz = BB(ii,3);
|
|---|
| 640 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
|---|
| 641 | (yy-pos(2)) * (yy-pos(2)) +
|
|---|
| 642 | (zz-pos(3)) * (zz-pos(3)) );
|
|---|
| 643 | traveltime = rho / t_CST::c;
|
|---|
| 644 | }
|
|---|
| 645 | double angle = traveltime * t_CST::omega;
|
|---|
| 646 | double cosa = cos(angle);
|
|---|
| 647 | double sina = sin(angle);
|
|---|
| 648 | BB(ii,1) = cosa * xx + sina * yy;
|
|---|
| 649 | BB(ii,2) = -sina * xx + cosa * yy;
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | Matrix BBB;
|
|---|
| 653 | if (mm > 4) {
|
|---|
| 654 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
|---|
| 655 | BBB = hlp.i() * BB.t();
|
|---|
| 656 | }
|
|---|
| 657 | else {
|
|---|
| 658 | BBB = BB.i();
|
|---|
| 659 | }
|
|---|
| 660 | ColumnVector ee(mm); ee = 1.0;
|
|---|
| 661 | ColumnVector alpha(mm); alpha = 0.0;
|
|---|
| 662 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 663 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
|---|
| 664 | }
|
|---|
| 665 | ColumnVector BBBe = BBB * ee;
|
|---|
| 666 | ColumnVector BBBalpha = BBB * alpha;
|
|---|
| 667 | double aa = lorentz(BBBe, BBBe);
|
|---|
| 668 | double bb = lorentz(BBBe, BBBalpha)-1;
|
|---|
| 669 | double cc = lorentz(BBBalpha, BBBalpha);
|
|---|
| 670 | double root = sqrt(bb*bb-aa*cc);
|
|---|
| 671 |
|
|---|
| 672 | Matrix hlpPos(4,2);
|
|---|
| 673 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
|---|
| 674 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
|---|
| 675 |
|
|---|
| 676 | ColumnVector omc(2);
|
|---|
| 677 | for (int pp = 1; pp <= 2; pp++) {
|
|---|
| 678 | hlpPos(4,pp) = -hlpPos(4,pp);
|
|---|
| 679 | omc(pp) = BB(1,4) -
|
|---|
| 680 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
|---|
| 681 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
|---|
| 682 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
|---|
| 683 | hlpPos(4,pp);
|
|---|
| 684 | }
|
|---|
| 685 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
|---|
| 686 | pos = hlpPos.Column(2);
|
|---|
| 687 | }
|
|---|
| 688 | else {
|
|---|
| 689 | pos = hlpPos.Column(1);
|
|---|
| 690 | }
|
|---|
| 691 | }
|
|---|
| 692 | }
|
|---|
| 693 |
|
|---|
| 694 | //
|
|---|
| 695 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 696 | void t_pppClient::reset() {
|
|---|
| 697 |
|
|---|
| 698 | // to delete old orbit and clock corrections
|
|---|
| 699 | delete _ephPool;
|
|---|
| 700 | _ephPool = new t_pppEphPool();
|
|---|
| 701 |
|
|---|
| 702 | // to delete old code biases
|
|---|
| 703 | delete _obsPool;
|
|---|
| 704 | _obsPool = new t_pppObsPool();
|
|---|
| 705 |
|
|---|
| 706 | // to delete all parameters
|
|---|
| 707 | delete _filter;
|
|---|
| 708 | _filter = new t_pppFilter(_obsPool);
|
|---|
| 709 |
|
|---|
| 710 | }
|
|---|