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