[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 | int numBancroft = obsVector.size();
|
---|
[7237] | 258 |
|
---|
[10259] | 259 | while (_running) {
|
---|
[10256] | 260 | Matrix BB(numBancroft, 4);
|
---|
[7237] | 261 | int iObs = -1;
|
---|
| 262 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
| 263 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
[10356] | 264 | if (tLC == t_lc::dummy) {
|
---|
| 265 | if (satObs->isValid(t_lc::cIF)) {
|
---|
| 266 | tLC = t_lc::cIF;
|
---|
[7237] | 267 | }
|
---|
[10356] | 268 | else if (satObs->isValid(t_lc::c1)) {
|
---|
| 269 | tLC = t_lc::c1;
|
---|
[7237] | 270 | }
|
---|
[10356] | 271 | else if (satObs->isValid(t_lc::c2)) {
|
---|
| 272 | tLC = t_lc::c2;
|
---|
| 273 | }
|
---|
[7237] | 274 | }
|
---|
[10356] | 275 | if ( satObs->isValid(tLC) &&
|
---|
| 276 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
---|
| 277 | ++iObs;
|
---|
| 278 | BB[iObs][0] = satObs->xc()[0];
|
---|
| 279 | BB[iObs][1] = satObs->xc()[1];
|
---|
| 280 | BB[iObs][2] = satObs->xc()[2];
|
---|
| 281 | BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
|
---|
| 282 | }
|
---|
[7237] | 283 | }
|
---|
[8912] | 284 | if (iObs + 1 < _opt->_minObs) {
|
---|
[9943] | 285 | LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
|
---|
[7237] | 286 | return failure;
|
---|
| 287 | }
|
---|
| 288 | BB = BB.Rows(1,iObs+1);
|
---|
[9600] | 289 | if (bancroft(BB, xyzc) != success) {
|
---|
| 290 | return failure;
|
---|
| 291 | }
|
---|
[7237] | 292 |
|
---|
| 293 | xyzc[3] /= t_CST::c;
|
---|
| 294 |
|
---|
| 295 | // Check Blunders
|
---|
| 296 | // --------------
|
---|
[10259] | 297 | const double BLUNDER = 100.0;
|
---|
[7237] | 298 | double maxRes = 0.0;
|
---|
| 299 | unsigned maxResIndex = 0;
|
---|
| 300 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
| 301 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
[10356] | 302 | if (satObs->isValid() && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
---|
[7237] | 303 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
---|
[8905] | 304 | double res = rr.NormFrobenius() - satObs->obsValue(tLC)
|
---|
[8453] | 305 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
---|
[9600] | 306 | if (fabs(res) > maxRes) {
|
---|
| 307 | maxRes = fabs(res);
|
---|
[7237] | 308 | maxResIndex = ii;
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
[9600] | 312 | if (maxRes < BLUNDER) {
|
---|
[10034] | 313 | if (print) {
|
---|
[7237] | 314 | LOG.setf(ios::fixed);
|
---|
[9783] | 315 | LOG << "\nPPP of Epoch ";
|
---|
| 316 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
---|
| 317 | LOG << "\n---------------------------------------------------------------\n";
|
---|
[10356] | 318 | LOG << string(epoTime) << " BANCROFT " << ": "
|
---|
[7237] | 319 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
---|
| 320 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
---|
| 321 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
---|
| 322 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
---|
| 323 | }
|
---|
| 324 | break;
|
---|
| 325 | }
|
---|
| 326 | else {
|
---|
| 327 | t_pppSatObs* satObs = obsVector.at(maxResIndex);
|
---|
[10165] | 328 | LOG << "t_pppClient::cmpBancroft Outlier " << satObs->prn().toString()
|
---|
[7237] | 329 | << " " << maxRes << endl;
|
---|
| 330 | delete satObs;
|
---|
| 331 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | return success;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[10256] | 338 | // Compute A Priori Glonass Clock Offset
|
---|
| 339 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 340 | double t_pppClient::cmpOffGlo(vector<t_pppSatObs*>& obsVector) {
|
---|
| 341 |
|
---|
| 342 | t_lc::type tLC = t_lc::dummy;
|
---|
| 343 | double offGlo = 0.0;
|
---|
| 344 |
|
---|
| 345 | if (_opt->useSystem('R')) {
|
---|
| 346 | while (obsVector.size() > 0) {
|
---|
| 347 | offGlo = 0.0;
|
---|
| 348 | double maxRes = 0.0;
|
---|
| 349 | int maxResIndex = -1;
|
---|
[10319] | 350 | unsigned nObs = 0;
|
---|
[10256] | 351 | t_prn maxResPrn;
|
---|
| 352 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
| 353 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
| 354 | if (satObs->prn().system() == 'R') {
|
---|
| 355 | if (tLC == t_lc::dummy) {
|
---|
| 356 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
---|
| 357 | }
|
---|
| 358 | if (satObs->isValid(tLC) &&
|
---|
| 359 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
|
---|
| 360 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
| 361 | ++nObs;
|
---|
| 362 | offGlo += ll;
|
---|
| 363 | if (fabs(ll) > fabs(maxRes)) {
|
---|
| 364 | maxRes = ll;
|
---|
| 365 | maxResIndex = ii;
|
---|
| 366 | maxResPrn = satObs->prn();
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | if (nObs > 0) {
|
---|
| 373 | offGlo = offGlo / nObs;
|
---|
| 374 | }
|
---|
| 375 | else {
|
---|
| 376 | offGlo = 0.0;
|
---|
| 377 | }
|
---|
[10259] | 378 | if (fabs(maxRes) > 100.0) {
|
---|
| 379 | LOG << "t_pppClient::cmpOffGlo outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
---|
[10256] | 380 | delete obsVector.at(maxResIndex);
|
---|
| 381 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
| 382 | }
|
---|
| 383 | else {
|
---|
| 384 | break;
|
---|
| 385 | }
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
| 388 | return offGlo;
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | // Compute A Priori Galileo Clock Offset
|
---|
| 392 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 393 | double t_pppClient::cmpOffGal(vector<t_pppSatObs*>& obsVector) {
|
---|
| 394 |
|
---|
| 395 | t_lc::type tLC = t_lc::dummy;
|
---|
| 396 | double offGal = 0.0;
|
---|
| 397 |
|
---|
| 398 | if (_opt->useSystem('E')) {
|
---|
| 399 | while (obsVector.size() > 0) {
|
---|
| 400 | offGal = 0.0;
|
---|
| 401 | double maxRes = 0.0;
|
---|
| 402 | int maxResIndex = -1;
|
---|
[10319] | 403 | unsigned nObs = 0;
|
---|
[10256] | 404 | t_prn maxResPrn;
|
---|
| 405 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
| 406 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
| 407 | if (satObs->prn().system() == 'E') {
|
---|
| 408 | if (tLC == t_lc::dummy) {
|
---|
| 409 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
---|
| 410 | }
|
---|
| 411 | if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
|
---|
| 412 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
| 413 | ++nObs;
|
---|
| 414 | offGal += ll;
|
---|
| 415 | if (fabs(ll) > fabs(maxRes)) {
|
---|
| 416 | maxRes = ll;
|
---|
| 417 | maxResIndex = ii;
|
---|
| 418 | maxResPrn = satObs->prn();
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | if (nObs > 0) {
|
---|
| 425 | offGal = offGal / nObs;
|
---|
| 426 | }
|
---|
| 427 | else {
|
---|
| 428 | offGal = 0.0;
|
---|
| 429 | }
|
---|
| 430 |
|
---|
[10259] | 431 | if (fabs(maxRes) > 100.0) {
|
---|
| 432 | LOG << "t_pppClient::cmpOffGal outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
---|
[10256] | 433 | delete obsVector.at(maxResIndex);
|
---|
| 434 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
| 435 | }
|
---|
| 436 | else {
|
---|
| 437 | break;
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 | return offGal;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | // Compute A Priori BDS Clock Offset
|
---|
| 445 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 446 | double t_pppClient::cmpOffBds(vector<t_pppSatObs*>& obsVector) {
|
---|
| 447 |
|
---|
| 448 | t_lc::type tLC = t_lc::dummy;
|
---|
| 449 | double offBds = 0.0;
|
---|
| 450 |
|
---|
| 451 | if (_opt->useSystem('C')) {
|
---|
| 452 | while (obsVector.size() > 0) {
|
---|
| 453 | offBds = 0.0;
|
---|
| 454 | double maxRes = 0.0;
|
---|
| 455 | int maxResIndex = -1;
|
---|
[10319] | 456 | unsigned nObs = 0;
|
---|
[10256] | 457 | t_prn maxResPrn;
|
---|
| 458 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
| 459 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
| 460 | if (satObs->prn().system() == 'C') {
|
---|
| 461 | if (tLC == t_lc::dummy) {
|
---|
| 462 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
---|
| 463 | }
|
---|
| 464 | if (satObs->isValid(tLC) &&
|
---|
| 465 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
|
---|
| 466 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
| 467 | ++nObs;
|
---|
| 468 | offBds += ll;
|
---|
| 469 | if (fabs(ll) > fabs(maxRes)) {
|
---|
| 470 | maxRes = ll;
|
---|
| 471 | maxResIndex = ii;
|
---|
| 472 | maxResPrn = satObs->prn();
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | if (nObs > 0) {
|
---|
| 479 | offBds = offBds / nObs;
|
---|
| 480 | }
|
---|
| 481 | else {
|
---|
| 482 | offBds = 0.0;
|
---|
| 483 | }
|
---|
| 484 |
|
---|
[10259] | 485 | if (fabs(maxRes) > 100.0) {
|
---|
| 486 | LOG << "t_pppClient::cmpOffBDS outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
---|
[10256] | 487 | delete obsVector.at(maxResIndex);
|
---|
| 488 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
| 489 | }
|
---|
| 490 | else {
|
---|
| 491 | break;
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 | }
|
---|
| 495 | return offBds;
|
---|
| 496 | }
|
---|
| 497 |
|
---|
[7271] | 498 | //
|
---|
[7237] | 499 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 500 | void t_pppClient::initOutput(t_output* output) {
|
---|
| 501 | _output = output;
|
---|
| 502 | _output->_numSat = 0;
|
---|
[7927] | 503 | _output->_hDop = 0.0;
|
---|
[7237] | 504 | _output->_error = false;
|
---|
| 505 | }
|
---|
| 506 |
|
---|
[7271] | 507 | //
|
---|
[7237] | 508 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 509 | void t_pppClient::clearObs() {
|
---|
| 510 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
---|
| 511 | delete _obsRover.at(ii);
|
---|
| 512 | }
|
---|
| 513 | _obsRover.clear();
|
---|
| 514 | }
|
---|
| 515 |
|
---|
[7271] | 516 | //
|
---|
[7237] | 517 | //////////////////////////////////////////////////////////////////////////////
|
---|
[9585] | 518 | void t_pppClient::finish(t_irc irc, int ind) {
|
---|
[9783] | 519 | #ifdef BNC_DEBUG_PPP
|
---|
[9585] | 520 | LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
|
---|
[9783] | 521 | #endif
|
---|
[9585] | 522 |
|
---|
[7237] | 523 | clearObs();
|
---|
| 524 |
|
---|
| 525 | _output->_epoTime = _epoTimeRover;
|
---|
| 526 |
|
---|
| 527 | if (irc == success) {
|
---|
| 528 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
---|
| 529 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
---|
| 530 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
---|
| 531 |
|
---|
| 532 | xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
|
---|
| 533 |
|
---|
| 534 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
---|
| 535 |
|
---|
| 536 | _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
|
---|
| 537 | _output->_trp = _filter->trp();
|
---|
| 538 | _output->_trpStdev = _filter->trpStdev();
|
---|
| 539 |
|
---|
[9386] | 540 | _output->_numSat = _filter->numSat();
|
---|
| 541 | _output->_hDop = _filter->HDOP();
|
---|
[7237] | 542 | _output->_error = false;
|
---|
| 543 | }
|
---|
| 544 | else {
|
---|
| 545 | _output->_error = true;
|
---|
| 546 | }
|
---|
[10034] | 547 |
|
---|
[7237] | 548 | _output->_log = _log->str();
|
---|
| 549 | delete _log; _log = new ostringstream();
|
---|
[9545] | 550 |
|
---|
| 551 | return;
|
---|
[7237] | 552 | }
|
---|
| 553 |
|
---|
[7271] | 554 | //
|
---|
[7237] | 555 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 556 | t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
|
---|
| 557 | vector<t_pppSatObs*>& obsVector) {
|
---|
| 558 | bncTime time;
|
---|
| 559 | time = _epoTimeRover;
|
---|
[8912] | 560 | station->setName(_opt->_roverName);
|
---|
| 561 | station->setAntName(_opt->_antNameRover);
|
---|
[8905] | 562 | station->setEpochTime(time);
|
---|
[10034] | 563 |
|
---|
[8912] | 564 | if (_opt->xyzAprRoverSet()) {
|
---|
| 565 | station->setXyzApr(_opt->_xyzAprRover);
|
---|
[7237] | 566 | }
|
---|
| 567 | else {
|
---|
| 568 | station->setXyzApr(xyzc.Rows(1,3));
|
---|
| 569 | }
|
---|
[8912] | 570 | station->setNeuEcc(_opt->_neuEccRover);
|
---|
[7237] | 571 |
|
---|
| 572 | // Receiver Clock
|
---|
| 573 | // --------------
|
---|
| 574 | station->setDClk(xyzc[3]);
|
---|
| 575 |
|
---|
| 576 | // Tides
|
---|
| 577 | // -----
|
---|
[8905] | 578 | station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
|
---|
| 579 | station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
|
---|
[7271] | 580 |
|
---|
[7237] | 581 | // Observation model
|
---|
| 582 | // -----------------
|
---|
| 583 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
---|
| 584 | while (it != obsVector.end()) {
|
---|
| 585 | t_pppSatObs* satObs = *it;
|
---|
[7254] | 586 | t_irc modelSetup;
|
---|
[7237] | 587 | if (satObs->isValid()) {
|
---|
[7254] | 588 | modelSetup = satObs->cmpModel(station);
|
---|
[7237] | 589 | }
|
---|
[7254] | 590 | if (satObs->isValid() &&
|
---|
[8912] | 591 | satObs->eleSat() >= _opt->_minEle &&
|
---|
[7254] | 592 | modelSetup == success) {
|
---|
[7237] | 593 | ++it;
|
---|
| 594 | }
|
---|
| 595 | else {
|
---|
| 596 | delete satObs;
|
---|
| 597 | it = obsVector.erase(it);
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | return success;
|
---|
| 602 | }
|
---|
| 603 |
|
---|
[7271] | 604 | //
|
---|
[7237] | 605 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 606 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
---|
| 607 |
|
---|
| 608 | try {
|
---|
| 609 | initOutput(output);
|
---|
[10034] | 610 |
|
---|
| 611 | // Prepare Observations of the Rover
|
---|
| 612 | // ---------------------------------
|
---|
| 613 | if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
|
---|
| 614 | return finish(failure, 1);
|
---|
[10031] | 615 | }
|
---|
[9419] | 616 |
|
---|
[10034] | 617 | for (int iter = 1; iter <= 2; iter++) {
|
---|
| 618 | ColumnVector xyzc(4); xyzc = 0.0;
|
---|
| 619 | bool print = (iter == 2);
|
---|
| 620 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
---|
| 621 | return finish(failure, 2);
|
---|
[10031] | 622 | }
|
---|
[10034] | 623 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
---|
| 624 | return finish(failure, 3);
|
---|
[8956] | 625 | }
|
---|
[10034] | 626 | }
|
---|
| 627 | // use observations only if satellite code biases are available
|
---|
| 628 | /* ------------------------------------------------------------
|
---|
| 629 | if (!_opt->_corrMount.empty() {
|
---|
[10015] | 630 | useObsWithCodeBiasesOnly(_obsRover);
|
---|
[10034] | 631 | }*/
|
---|
[8905] | 632 |
|
---|
[10034] | 633 | if (int(_obsRover.size()) < _opt->_minObs) {
|
---|
| 634 | LOG << "t_pppClient::processEpoch not enough observations" << endl;
|
---|
| 635 | return finish(failure, 4);
|
---|
| 636 | }
|
---|
[10038] | 637 |
|
---|
[10256] | 638 | _offGlo = cmpOffGlo(_obsRover);
|
---|
| 639 | _offGal = cmpOffGal(_obsRover);
|
---|
| 640 | _offBds = cmpOffBds(_obsRover);
|
---|
| 641 |
|
---|
[10034] | 642 | // Prepare Pseudo Observations of the Rover
|
---|
| 643 | // ----------------------------------------
|
---|
| 644 | _pseudoObsIono = preparePseudoObs(_obsRover);
|
---|
[10018] | 645 |
|
---|
[10034] | 646 | // Store last epoch of data
|
---|
| 647 | // ------------------------
|
---|
| 648 | _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
|
---|
[7237] | 649 |
|
---|
[10034] | 650 | // Process Epoch in Filter
|
---|
| 651 | // -----------------------
|
---|
| 652 | if (_filter->processEpoch(_obsPool) != success) {
|
---|
[10220] | 653 | LOG << "t_pppFilter::processEpoch() != success" << endl;
|
---|
[10034] | 654 | return finish(failure, 5);
|
---|
| 655 | }
|
---|
[7237] | 656 | }
|
---|
| 657 | catch (Exception& exc) {
|
---|
| 658 | LOG << exc.what() << endl;
|
---|
[10034] | 659 | return finish(failure, 6);
|
---|
[7237] | 660 | }
|
---|
| 661 | catch (t_except msg) {
|
---|
| 662 | LOG << msg.what() << endl;
|
---|
[10034] | 663 | return finish(failure, 7);
|
---|
[7237] | 664 | }
|
---|
| 665 | catch (const char* msg) {
|
---|
| 666 | LOG << msg << endl;
|
---|
[10034] | 667 | return finish(failure, 8);
|
---|
[7237] | 668 | }
|
---|
| 669 | catch (...) {
|
---|
| 670 | LOG << "unknown exception" << endl;
|
---|
[10034] | 671 | return finish(failure, 9);
|
---|
[7237] | 672 | }
|
---|
[10034] | 673 | return finish(success, 0);
|
---|
[7237] | 674 | }
|
---|
| 675 |
|
---|
[7271] | 676 | //
|
---|
[7237] | 677 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 678 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
---|
| 679 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
---|
| 680 | }
|
---|
| 681 |
|
---|
[7271] | 682 | //
|
---|
[7237] | 683 | ////////////////////////////////////////////////////////////////////////////
|
---|
[9600] | 684 | t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
---|
[7237] | 685 |
|
---|
| 686 | if (pos.Nrows() != 4) {
|
---|
| 687 | pos.ReSize(4);
|
---|
| 688 | }
|
---|
| 689 | pos = 0.0;
|
---|
| 690 |
|
---|
| 691 | for (int iter = 1; iter <= 2; iter++) {
|
---|
| 692 | Matrix BB = BBpass;
|
---|
| 693 | int mm = BB.Nrows();
|
---|
| 694 | for (int ii = 1; ii <= mm; ii++) {
|
---|
| 695 | double xx = BB(ii,1);
|
---|
| 696 | double yy = BB(ii,2);
|
---|
| 697 | double traveltime = 0.072;
|
---|
| 698 | if (iter > 1) {
|
---|
| 699 | double zz = BB(ii,3);
|
---|
[7271] | 700 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
---|
| 701 | (yy-pos(2)) * (yy-pos(2)) +
|
---|
[7237] | 702 | (zz-pos(3)) * (zz-pos(3)) );
|
---|
| 703 | traveltime = rho / t_CST::c;
|
---|
| 704 | }
|
---|
| 705 | double angle = traveltime * t_CST::omega;
|
---|
| 706 | double cosa = cos(angle);
|
---|
| 707 | double sina = sin(angle);
|
---|
| 708 | BB(ii,1) = cosa * xx + sina * yy;
|
---|
| 709 | BB(ii,2) = -sina * xx + cosa * yy;
|
---|
| 710 | }
|
---|
[7271] | 711 |
|
---|
[7237] | 712 | Matrix BBB;
|
---|
| 713 | if (mm > 4) {
|
---|
| 714 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
---|
| 715 | BBB = hlp.i() * BB.t();
|
---|
| 716 | }
|
---|
| 717 | else {
|
---|
| 718 | BBB = BB.i();
|
---|
| 719 | }
|
---|
| 720 | ColumnVector ee(mm); ee = 1.0;
|
---|
| 721 | ColumnVector alpha(mm); alpha = 0.0;
|
---|
| 722 | for (int ii = 1; ii <= mm; ii++) {
|
---|
[7271] | 723 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
---|
[7237] | 724 | }
|
---|
| 725 | ColumnVector BBBe = BBB * ee;
|
---|
| 726 | ColumnVector BBBalpha = BBB * alpha;
|
---|
| 727 | double aa = lorentz(BBBe, BBBe);
|
---|
| 728 | double bb = lorentz(BBBe, BBBalpha)-1;
|
---|
| 729 | double cc = lorentz(BBBalpha, BBBalpha);
|
---|
| 730 | double root = sqrt(bb*bb-aa*cc);
|
---|
| 731 |
|
---|
[7271] | 732 | Matrix hlpPos(4,2);
|
---|
[7237] | 733 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
---|
| 734 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
---|
| 735 |
|
---|
| 736 | ColumnVector omc(2);
|
---|
| 737 | for (int pp = 1; pp <= 2; pp++) {
|
---|
| 738 | hlpPos(4,pp) = -hlpPos(4,pp);
|
---|
[7271] | 739 | omc(pp) = BB(1,4) -
|
---|
[7237] | 740 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
---|
| 741 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
---|
[7271] | 742 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
---|
[7237] | 743 | hlpPos(4,pp);
|
---|
| 744 | }
|
---|
| 745 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
---|
| 746 | pos = hlpPos.Column(2);
|
---|
| 747 | }
|
---|
| 748 | else {
|
---|
| 749 | pos = hlpPos.Column(1);
|
---|
| 750 | }
|
---|
| 751 | }
|
---|
[9600] | 752 | if (pos.size() != 4 ||
|
---|
| 753 | std::isnan(pos(1)) ||
|
---|
| 754 | std::isnan(pos(2)) ||
|
---|
| 755 | std::isnan(pos(3)) ||
|
---|
| 756 | std::isnan(pos(4))) {
|
---|
| 757 | return failure;
|
---|
| 758 | }
|
---|
| 759 |
|
---|
| 760 | return success;
|
---|
[7237] | 761 | }
|
---|
| 762 |
|
---|
[7972] | 763 | //
|
---|
| 764 | //////////////////////////////////////////////////////////////////////////////
|
---|
[10256] | 765 | void t_pppClient::reset() {
|
---|
[9490] | 766 |
|
---|
[7972] | 767 | // to delete old orbit and clock corrections
|
---|
| 768 | delete _ephPool;
|
---|
| 769 | _ephPool = new t_pppEphPool();
|
---|
| 770 |
|
---|
| 771 | // to delete old code biases
|
---|
| 772 | delete _obsPool;
|
---|
| 773 | _obsPool = new t_pppObsPool();
|
---|
[8905] | 774 |
|
---|
| 775 | // to delete all parameters
|
---|
| 776 | delete _filter;
|
---|
[10034] | 777 | _filter = new t_pppFilter();
|
---|
[8905] | 778 |
|
---|
[7996] | 779 | }
|
---|