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