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