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