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