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