| 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 | clearObs();
|
|---|
| 163 |
|
|---|
| 164 | // Create vector of valid observations
|
|---|
| 165 | // -----------------------------------
|
|---|
| 166 | for (unsigned ii = 0; ii < satObs.size(); ii++) {
|
|---|
| 167 | char system = satObs[ii]->_prn.system();
|
|---|
| 168 | if (_opt->useSystem(system)) {
|
|---|
| 169 | t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
|
|---|
| 170 | if (pppSatObs->isValid()) {
|
|---|
| 171 | obsVector.push_back(pppSatObs);
|
|---|
| 172 | }
|
|---|
| 173 | else {
|
|---|
| 174 | delete pppSatObs;
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | // Check whether data are synchronized, compute epoTime
|
|---|
| 180 | // ----------------------------------------------------
|
|---|
| 181 | const double MAXSYNC = 0.05; // synchronization limit
|
|---|
| 182 | double meanDt = 0.0;
|
|---|
| 183 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 184 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 185 | if (epoTime.undef()) {
|
|---|
| 186 | epoTime = satObs->time();
|
|---|
| 187 | }
|
|---|
| 188 | else {
|
|---|
| 189 | double dt = satObs->time() - epoTime;
|
|---|
| 190 | if (fabs(dt) > MAXSYNC) {
|
|---|
| 191 | LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
|
|---|
| 192 | return failure;
|
|---|
| 193 | }
|
|---|
| 194 | meanDt += dt;
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | if (obsVector.size() > 0) {
|
|---|
| 199 | epoTime += meanDt / obsVector.size();
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | return success;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | //
|
|---|
| 206 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 207 | bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
|
|---|
| 208 |
|
|---|
| 209 | bool pseudoObsIono = false;
|
|---|
| 210 |
|
|---|
| 211 | if (_opt->_pseudoObsIono) {
|
|---|
| 212 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 213 | while (it != obsVector.end()) {
|
|---|
| 214 | t_pppSatObs* satObs = *it;
|
|---|
| 215 | char system = satObs->prn().system();
|
|---|
| 216 | t_pppRefSat* refSat = _obsPool->getRefSatMapElement(system);
|
|---|
| 217 | double stecRef = refSat->stecValue();
|
|---|
| 218 | if (stecRef && !satObs->isReference()) {
|
|---|
| 219 | pseudoObsIono = true;
|
|---|
| 220 | satObs->setPseudoObsIono(t_frequency::G1, stecRef);
|
|---|
| 221 | }
|
|---|
| 222 | satObs->printObsMinusComputed();
|
|---|
| 223 | it++;
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | return pseudoObsIono;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // Compute the Bancroft position, check for blunders
|
|---|
| 231 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 232 | t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
|
|---|
| 233 | vector<t_pppSatObs*>& obsVector,
|
|---|
| 234 | ColumnVector& xyzc, bool print) {
|
|---|
| 235 |
|
|---|
| 236 | t_lc::type tLC = t_lc::dummy;
|
|---|
| 237 |
|
|---|
| 238 | while (true) {
|
|---|
| 239 | Matrix BB(obsVector.size(), 4);
|
|---|
| 240 | int iObs = -1;
|
|---|
| 241 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 242 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 243 | if (tLC == t_lc::dummy) {
|
|---|
| 244 | if (satObs->isValid(t_lc::cIF)) {
|
|---|
| 245 | tLC = t_lc::cIF;
|
|---|
| 246 | }
|
|---|
| 247 | else if (satObs->isValid(t_lc::c1)) {
|
|---|
| 248 | tLC = t_lc::c1;
|
|---|
| 249 | }
|
|---|
| 250 | else if (satObs->isValid(t_lc::c2)) {
|
|---|
| 251 | tLC = t_lc::c2;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 | if ( satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
|---|
| 255 | ++iObs;
|
|---|
| 256 | BB[iObs][0] = satObs->xc()[0];
|
|---|
| 257 | BB[iObs][1] = satObs->xc()[1];
|
|---|
| 258 | BB[iObs][2] = satObs->xc()[2];
|
|---|
| 259 | BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
|
|---|
| 260 | }
|
|---|
| 261 | }
|
|---|
| 262 | if (iObs + 1 < _opt->_minObs) {
|
|---|
| 263 | LOG << "t_pppClient::cmpBancroft not enough observations" << endl;
|
|---|
| 264 | return failure;
|
|---|
| 265 | }
|
|---|
| 266 | BB = BB.Rows(1,iObs+1);
|
|---|
| 267 | bancroft(BB, xyzc);
|
|---|
| 268 |
|
|---|
| 269 | xyzc[3] /= t_CST::c;
|
|---|
| 270 |
|
|---|
| 271 | // Check Blunders
|
|---|
| 272 | // --------------
|
|---|
| 273 | const double BLUNDER = 100.0;
|
|---|
| 274 | double maxRes = 0.0;
|
|---|
| 275 | unsigned maxResIndex = 0;
|
|---|
| 276 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 277 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 278 | if (satObs->isValid() &&
|
|---|
| 279 | satObs->prn().system() == 'G' &&
|
|---|
| 280 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
|---|
| 281 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
|---|
| 282 | double res = rr.NormFrobenius() - satObs->obsValue(tLC)
|
|---|
| 283 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
|---|
| 284 | if (std::isnan(res) || fabs(res) > maxRes) {
|
|---|
| 285 | std::isnan(res) ?
|
|---|
| 286 | maxRes = res :
|
|---|
| 287 | maxRes = fabs(res);
|
|---|
| 288 | maxResIndex = ii;
|
|---|
| 289 | }
|
|---|
| 290 | }
|
|---|
| 291 | }
|
|---|
| 292 | if (!std::isnan(maxRes) && maxRes < BLUNDER) {
|
|---|
| 293 | if (print) {
|
|---|
| 294 | LOG.setf(ios::fixed);
|
|---|
| 295 | LOG << string(epoTime) << " BANCROFT:" << ' '
|
|---|
| 296 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
|---|
| 297 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
|---|
| 298 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
|---|
| 299 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
|---|
| 300 | }
|
|---|
| 301 | break;
|
|---|
| 302 | }
|
|---|
| 303 | else {
|
|---|
| 304 | t_pppSatObs* satObs = obsVector.at(maxResIndex);
|
|---|
| 305 | LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
|
|---|
| 306 | << " " << maxRes << endl;
|
|---|
| 307 | delete satObs;
|
|---|
| 308 | obsVector.erase(obsVector.begin() + maxResIndex);
|
|---|
| 309 | }
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | return success;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | // Compute A Priori GPS-Glonass Offset
|
|---|
| 316 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 317 | double t_pppClient::cmpOffGG(vector<t_pppSatObs*>& obsVector) {
|
|---|
| 318 |
|
|---|
| 319 | t_lc::type tLC = t_lc::dummy;
|
|---|
| 320 | double offGG = 0.0;
|
|---|
| 321 |
|
|---|
| 322 | if (_opt->useSystem('R')) {
|
|---|
| 323 | while (obsVector.size() > 0) {
|
|---|
| 324 | offGG = 0.0;
|
|---|
| 325 | double maxRes = 0.0;
|
|---|
| 326 | int maxResIndex = -1;
|
|---|
| 327 | t_prn maxResPrn;
|
|---|
| 328 | unsigned nObs = 0;
|
|---|
| 329 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 330 | const t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 331 | if (satObs->prn().system() == 'R') {
|
|---|
| 332 | if (tLC == t_lc::dummy) {
|
|---|
| 333 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
|---|
| 334 | }
|
|---|
| 335 | if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
|
|---|
| 336 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
|---|
| 337 | ++nObs;
|
|---|
| 338 | offGG += ll;
|
|---|
| 339 | if (fabs(ll) > fabs(maxRes)) {
|
|---|
| 340 | maxRes = ll;
|
|---|
| 341 | maxResIndex = ii;
|
|---|
| 342 | maxResPrn = satObs->prn();
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 | }
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | if (nObs > 0) {
|
|---|
| 349 | offGG = offGG / nObs;
|
|---|
| 350 | }
|
|---|
| 351 | else {
|
|---|
| 352 | offGG = 0.0;
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | if (fabs(maxRes) > 1000.0) {
|
|---|
| 356 | LOG << "t_pppClient::cmpOffGG outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
|---|
| 357 | delete obsVector.at(maxResIndex);
|
|---|
| 358 | obsVector.erase(obsVector.begin() + maxResIndex);
|
|---|
| 359 | }
|
|---|
| 360 | else {
|
|---|
| 361 | break;
|
|---|
| 362 | }
|
|---|
| 363 | }
|
|---|
| 364 | }
|
|---|
| 365 | return offGG;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | //
|
|---|
| 369 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 370 | void t_pppClient::initOutput(t_output* output) {
|
|---|
| 371 | _output = output;
|
|---|
| 372 | _output->_numSat = 0;
|
|---|
| 373 | _output->_hDop = 0.0;
|
|---|
| 374 | _output->_error = false;
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | //
|
|---|
| 378 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 379 | void t_pppClient::clearObs() {
|
|---|
| 380 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
|---|
| 381 | delete _obsRover.at(ii);
|
|---|
| 382 | }
|
|---|
| 383 | _obsRover.clear();
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | //
|
|---|
| 387 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 388 | void t_pppClient::finish(t_irc irc) {
|
|---|
| 389 |
|
|---|
| 390 | clearObs();
|
|---|
| 391 |
|
|---|
| 392 | _output->_epoTime = _epoTimeRover;
|
|---|
| 393 |
|
|---|
| 394 | if (irc == success) {
|
|---|
| 395 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
|---|
| 396 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
|---|
| 397 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
|---|
| 398 |
|
|---|
| 399 | xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
|
|---|
| 400 |
|
|---|
| 401 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
|---|
| 402 |
|
|---|
| 403 | _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
|
|---|
| 404 | _output->_trp = _filter->trp();
|
|---|
| 405 | _output->_trpStdev = _filter->trpStdev();
|
|---|
| 406 |
|
|---|
| 407 | _output->_numSat = _filter->numSat();
|
|---|
| 408 | _output->_hDop = _filter->HDOP();
|
|---|
| 409 | _output->_error = false;
|
|---|
| 410 | }
|
|---|
| 411 | else {
|
|---|
| 412 | _output->_error = true;
|
|---|
| 413 | }
|
|---|
| 414 | _output->_log = _log->str();
|
|---|
| 415 | delete _log; _log = new ostringstream();
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | //
|
|---|
| 419 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 420 | t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
|
|---|
| 421 | vector<t_pppSatObs*>& obsVector) {
|
|---|
| 422 | bncTime time;
|
|---|
| 423 | time = _epoTimeRover;
|
|---|
| 424 | station->setName(_opt->_roverName);
|
|---|
| 425 | station->setAntName(_opt->_antNameRover);
|
|---|
| 426 | station->setEpochTime(time);
|
|---|
| 427 | if (_opt->xyzAprRoverSet()) {
|
|---|
| 428 | station->setXyzApr(_opt->_xyzAprRover);
|
|---|
| 429 | }
|
|---|
| 430 | else {
|
|---|
| 431 | station->setXyzApr(xyzc.Rows(1,3));
|
|---|
| 432 | }
|
|---|
| 433 | station->setNeuEcc(_opt->_neuEccRover);
|
|---|
| 434 |
|
|---|
| 435 | // Receiver Clock
|
|---|
| 436 | // --------------
|
|---|
| 437 | station->setDClk(xyzc[3]);
|
|---|
| 438 |
|
|---|
| 439 | // Tides
|
|---|
| 440 | // -----
|
|---|
| 441 | station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
|
|---|
| 442 | station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
|
|---|
| 443 |
|
|---|
| 444 | // Observation model
|
|---|
| 445 | // -----------------
|
|---|
| 446 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
|---|
| 447 | while (it != obsVector.end()) {
|
|---|
| 448 | t_pppSatObs* satObs = *it;
|
|---|
| 449 | t_irc modelSetup;
|
|---|
| 450 | if (satObs->isValid()) {
|
|---|
| 451 | modelSetup = satObs->cmpModel(station);
|
|---|
| 452 | }
|
|---|
| 453 | if (satObs->isValid() &&
|
|---|
| 454 | satObs->eleSat() >= _opt->_minEle &&
|
|---|
| 455 | modelSetup == success) {
|
|---|
| 456 | ++it;
|
|---|
| 457 | }
|
|---|
| 458 | else {
|
|---|
| 459 | delete satObs;
|
|---|
| 460 | it = obsVector.erase(it);
|
|---|
| 461 | }
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | return success;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | //
|
|---|
| 468 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 469 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
|---|
| 470 |
|
|---|
| 471 | _historicalRefSats.clear();
|
|---|
| 472 | try {
|
|---|
| 473 | initOutput(output);
|
|---|
| 474 | int num = 0;
|
|---|
| 475 | bool epochReProcessing = false;
|
|---|
| 476 |
|
|---|
| 477 | do {
|
|---|
| 478 | num++;
|
|---|
| 479 | if (num == 1) {
|
|---|
| 480 | LOG << "\nPPP of Epoch ";
|
|---|
| 481 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
|---|
| 482 | LOG << "\n---------------------------------------------------------------\n";
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | // Prepare Observations of the Rover
|
|---|
| 486 | // ---------------------------------
|
|---|
| 487 | if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
|
|---|
| 488 | return finish(failure);
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 492 | ColumnVector xyzc(4); xyzc = 0.0;
|
|---|
| 493 | bool print = (iter == 2);
|
|---|
| 494 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
|---|
| 495 | return finish(failure);
|
|---|
| 496 | }
|
|---|
| 497 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
|---|
| 498 | return finish(failure);
|
|---|
| 499 | }
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | _offGG = cmpOffGG(_obsRover);
|
|---|
| 503 |
|
|---|
| 504 | if (_opt->_refSatRequired) {
|
|---|
| 505 | setRefSatellites(_obsRover);
|
|---|
| 506 | LOG.setf(ios::fixed);
|
|---|
| 507 | QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
|
|---|
| 508 | while (it.hasNext()) {
|
|---|
| 509 | it.next();
|
|---|
| 510 | char sys = it.key();
|
|---|
| 511 | string prn = it.value()->prn().toString();
|
|---|
| 512 | if (num == 1) {
|
|---|
| 513 | LOG << "set ";
|
|---|
| 514 | }
|
|---|
| 515 | else {
|
|---|
| 516 | LOG << "reset ";
|
|---|
| 517 | }
|
|---|
| 518 | LOG << string(_epoTimeRover) << " REFSAT " << sys << ": " << prn << endl;
|
|---|
| 519 | }
|
|---|
| 520 | }
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 | // Prepare Pseudo Observations of the Rover
|
|---|
| 524 | // ----------------------------------------
|
|---|
| 525 | _pseudoObsIono = preparePseudoObs(_obsRover);
|
|---|
| 526 |
|
|---|
| 527 | if (int(_obsRover.size()) < _opt->_minObs) {
|
|---|
| 528 | LOG << "t_pppClient::processEpoch not enough observations" << endl;
|
|---|
| 529 | return finish(failure);
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 | // Store last epoch of data
|
|---|
| 534 | // ------------------------
|
|---|
| 535 | _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
|
|---|
| 536 | _obsPool->setHistoricalRefSatList(_historicalRefSats);
|
|---|
| 537 |
|
|---|
| 538 | // Process Epoch in Filter
|
|---|
| 539 | // -----------------------
|
|---|
| 540 | if (_filter->processEpoch(num) != success) {
|
|---|
| 541 | return finish(failure);
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | // Epoch re-processing required?
|
|---|
| 545 | // -----------------------------
|
|---|
| 546 | if (_obsPool->refSatChangeRequired()) {
|
|---|
| 547 | epochReProcessing = true;
|
|---|
| 548 | _obsPool->deleteLastEpoch();
|
|---|
| 549 | QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
|
|---|
| 550 | while (it.hasNext()) {
|
|---|
| 551 | it.next();
|
|---|
| 552 | _historicalRefSats.append(it.value()->prn());
|
|---|
| 553 | }
|
|---|
| 554 | }
|
|---|
| 555 | else {
|
|---|
| 556 | epochReProcessing = false;
|
|---|
| 557 |
|
|---|
| 558 | }
|
|---|
| 559 | } while (epochReProcessing);
|
|---|
| 560 | }
|
|---|
| 561 | catch (Exception& exc) {
|
|---|
| 562 | LOG << exc.what() << endl;
|
|---|
| 563 | return finish(failure);
|
|---|
| 564 | }
|
|---|
| 565 | catch (t_except msg) {
|
|---|
| 566 | LOG << msg.what() << endl;
|
|---|
| 567 | return finish(failure);
|
|---|
| 568 | }
|
|---|
| 569 | catch (const char* msg) {
|
|---|
| 570 | LOG << msg << endl;
|
|---|
| 571 | return finish(failure);
|
|---|
| 572 | }
|
|---|
| 573 | catch (...) {
|
|---|
| 574 | LOG << "unknown exception" << endl;
|
|---|
| 575 | return finish(failure);
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | return finish(success);
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | //
|
|---|
| 582 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 583 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
|---|
| 584 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | //
|
|---|
| 588 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 589 | void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
|---|
| 590 |
|
|---|
| 591 | if (pos.Nrows() != 4) {
|
|---|
| 592 | pos.ReSize(4);
|
|---|
| 593 | }
|
|---|
| 594 | pos = 0.0;
|
|---|
| 595 |
|
|---|
| 596 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 597 | Matrix BB = BBpass;
|
|---|
| 598 | int mm = BB.Nrows();
|
|---|
| 599 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 600 | double xx = BB(ii,1);
|
|---|
| 601 | double yy = BB(ii,2);
|
|---|
| 602 | double traveltime = 0.072;
|
|---|
| 603 | if (iter > 1) {
|
|---|
| 604 | double zz = BB(ii,3);
|
|---|
| 605 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
|---|
| 606 | (yy-pos(2)) * (yy-pos(2)) +
|
|---|
| 607 | (zz-pos(3)) * (zz-pos(3)) );
|
|---|
| 608 | traveltime = rho / t_CST::c;
|
|---|
| 609 | }
|
|---|
| 610 | double angle = traveltime * t_CST::omega;
|
|---|
| 611 | double cosa = cos(angle);
|
|---|
| 612 | double sina = sin(angle);
|
|---|
| 613 | BB(ii,1) = cosa * xx + sina * yy;
|
|---|
| 614 | BB(ii,2) = -sina * xx + cosa * yy;
|
|---|
| 615 | }
|
|---|
| 616 |
|
|---|
| 617 | Matrix BBB;
|
|---|
| 618 | if (mm > 4) {
|
|---|
| 619 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
|---|
| 620 | BBB = hlp.i() * BB.t();
|
|---|
| 621 | }
|
|---|
| 622 | else {
|
|---|
| 623 | BBB = BB.i();
|
|---|
| 624 | }
|
|---|
| 625 | ColumnVector ee(mm); ee = 1.0;
|
|---|
| 626 | ColumnVector alpha(mm); alpha = 0.0;
|
|---|
| 627 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 628 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
|---|
| 629 | }
|
|---|
| 630 | ColumnVector BBBe = BBB * ee;
|
|---|
| 631 | ColumnVector BBBalpha = BBB * alpha;
|
|---|
| 632 | double aa = lorentz(BBBe, BBBe);
|
|---|
| 633 | double bb = lorentz(BBBe, BBBalpha)-1;
|
|---|
| 634 | double cc = lorentz(BBBalpha, BBBalpha);
|
|---|
| 635 | double root = sqrt(bb*bb-aa*cc);
|
|---|
| 636 |
|
|---|
| 637 | Matrix hlpPos(4,2);
|
|---|
| 638 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
|---|
| 639 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
|---|
| 640 |
|
|---|
| 641 | ColumnVector omc(2);
|
|---|
| 642 | for (int pp = 1; pp <= 2; pp++) {
|
|---|
| 643 | hlpPos(4,pp) = -hlpPos(4,pp);
|
|---|
| 644 | omc(pp) = BB(1,4) -
|
|---|
| 645 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
|---|
| 646 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
|---|
| 647 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
|---|
| 648 | hlpPos(4,pp);
|
|---|
| 649 | }
|
|---|
| 650 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
|---|
| 651 | pos = hlpPos.Column(2);
|
|---|
| 652 | }
|
|---|
| 653 | else {
|
|---|
| 654 | pos = hlpPos.Column(1);
|
|---|
| 655 | }
|
|---|
| 656 | }
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | //
|
|---|
| 660 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 661 | void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
|
|---|
| 662 |
|
|---|
| 663 | // reference satellite definition per system
|
|---|
| 664 | for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
|
|---|
| 665 | char system = _opt->systems()[iSys];
|
|---|
| 666 | bool refSatDefined = false;
|
|---|
| 667 | t_pppRefSat* refSat = _obsPool->getRefSatMapElement(system);
|
|---|
| 668 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 669 | t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 670 | if (satObs->eleSat() < _opt->_minEle) {continue;}
|
|---|
| 671 | // reference satellite is unchanged
|
|---|
| 672 | if (!_obsPool->refSatChangeRequired() && refSat->prn() == satObs->prn()) {
|
|---|
| 673 | refSatDefined = true;
|
|---|
| 674 | obsVector[ii]->setAsReference();
|
|---|
| 675 | }
|
|---|
| 676 | // reference satellite has changed
|
|---|
| 677 | else if ( _obsPool->refSatChangeRequired() && refSat->prn() != satObs->prn() && !_historicalRefSats.contains(satObs->prn())) {
|
|---|
| 678 | if (satObs->prn().system() == system) {
|
|---|
| 679 | refSatDefined = true;
|
|---|
| 680 | obsVector[ii]->setAsReference();
|
|---|
| 681 | refSat->setPrn(satObs->prn());
|
|---|
| 682 | }
|
|---|
| 683 | }
|
|---|
| 684 | if (refSatDefined) {
|
|---|
| 685 | if (OPT->_pseudoObsIono) {
|
|---|
| 686 | refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
|
|---|
| 687 | }
|
|---|
| 688 | break;
|
|---|
| 689 | }
|
|---|
| 690 | }
|
|---|
| 691 | // reference satellite has to be initialized
|
|---|
| 692 | if (!refSatDefined) {
|
|---|
| 693 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 694 | t_pppSatObs* satObs = obsVector.at(ii);
|
|---|
| 695 | if (satObs->eleSat() < _opt->_minEle) {
|
|---|
| 696 | continue;
|
|---|
| 697 | }
|
|---|
| 698 | if (satObs->prn().system() == system) {
|
|---|
| 699 | obsVector[ii]->setAsReference();
|
|---|
| 700 | refSat->setPrn(satObs->prn());
|
|---|
| 701 | if (OPT->_pseudoObsIono) {
|
|---|
| 702 | refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
|
|---|
| 703 | }
|
|---|
| 704 | refSatDefined = true;
|
|---|
| 705 | break;
|
|---|
| 706 | }
|
|---|
| 707 | }
|
|---|
| 708 | }
|
|---|
| 709 | }
|
|---|
| 710 | _obsPool->setRefSatChangeRequired(false);
|
|---|
| 711 |
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | //
|
|---|
| 715 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 716 | void t_pppClient::reset() {
|
|---|
| 717 |
|
|---|
| 718 | // to delete old orbit and clock corrections
|
|---|
| 719 | delete _ephPool;
|
|---|
| 720 | _ephPool = new t_pppEphPool();
|
|---|
| 721 |
|
|---|
| 722 | // to delete old code biases
|
|---|
| 723 | delete _obsPool;
|
|---|
| 724 | _obsPool = new t_pppObsPool();
|
|---|
| 725 |
|
|---|
| 726 | // to delete all parameters
|
|---|
| 727 | delete _filter;
|
|---|
| 728 | _filter = new t_pppFilter(_obsPool);
|
|---|
| 729 |
|
|---|
| 730 | }
|
|---|