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