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