source: ntrip/trunk/BNC/src/PPP/pppClient.cpp@ 9560

Last change on this file since 9560 was 9560, checked in by stuerze, 2 years ago

update regarding PPP

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 28.3 KB
RevLine 
[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
35using namespace BNC_PPP;
36using namespace std;
37
38// Global variable holding thread-specific pointers
39//////////////////////////////////////////////////////////////////////////////
40QThreadStorage<t_pppClient*> CLIENTS;
41
42// Static function returning thread-specific pointer
43//////////////////////////////////////////////////////////////////////////////
44t_pppClient* t_pppClient::instance() {
45 return CLIENTS.localData();
46}
47
48// Constructor
49//////////////////////////////////////////////////////////////////////////////
50t_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++) {
[9508]71 char sys = _opt->systems()[iSys];
72 _refSatMap[sys] = new t_pppRefSat();
[8905]73 }
[7972]74 }
[9419]75
[9288]76 _offGR = 0.0;
77 _offGE = 0.0;
78 _offGC = 0.0;
[7237]79 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
80}
81
82// Destructor
83//////////////////////////////////////////////////////////////////////////////
84t_pppClient::~t_pppClient() {
85 delete _log;
86 delete _opt;
[8905]87 delete _filter;
[7237]88 delete _ephPool;
89 delete _obsPool;
90 delete _staRover;
[7866]91 if (_antex) {
92 delete _antex;
93 }
[7237]94 delete _tides;
95 clearObs();
[9508]96 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
97 while (it.hasNext()) {
98 it.next();
99 delete it.value();
100 }
101 _refSatMap.clear();
[7237]102}
103
[7271]104//
[7237]105//////////////////////////////////////////////////////////////////////////////
106void t_pppClient::putEphemeris(const t_eph* eph) {
107 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
108 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
109 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
[7271]110 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
[7237]111 if (ephGPS) {
112 _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
113 }
114 else if (ephGlo) {
115 _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
116 }
117 else if (ephGal) {
118 _ephPool->putEphemeris(new t_ephGal(*ephGal));
119 }
[7271]120 else if (ephBDS) {
121 _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
122 }
[7237]123}
124
125//
126//////////////////////////////////////////////////////////////////////////////
127void t_pppClient::putTec(const t_vTec* vTec) {
[7248]128 _obsPool->putTec(new t_vTec(*vTec));
[7237]129}
130
[7271]131//
[7237]132//////////////////////////////////////////////////////////////////////////////
133void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
134 for (unsigned ii = 0; ii < corr.size(); ii++) {
135 _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
136 }
137}
138
[7271]139//
[7237]140//////////////////////////////////////////////////////////////////////////////
141void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
142 for (unsigned ii = 0; ii < corr.size(); ii++) {
143 _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
144 }
145}
146
[7271]147//
[7237]148//////////////////////////////////////////////////////////////////////////////
149void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
150 for (unsigned ii = 0; ii < biases.size(); ii++) {
151 _obsPool->putCodeBias(new t_satCodeBias(*biases[ii]));
152 }
153}
154
155//
156//////////////////////////////////////////////////////////////////////////////
[7288]157void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
158 for (unsigned ii = 0; ii < biases.size(); ii++) {
159 _obsPool->putPhaseBias(new t_satPhaseBias(*biases[ii]));
160 }
161}
162
163//
164//////////////////////////////////////////////////////////////////////////////
[7237]165t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
166 vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
[8905]167
[7271]168 // Default
[7237]169 // -------
170 epoTime.reset();
[8956]171 clearObs();
[7237]172
173 // Create vector of valid observations
174 // -----------------------------------
175 for (unsigned ii = 0; ii < satObs.size(); ii++) {
176 char system = satObs[ii]->_prn.system();
[8912]177 if (_opt->useSystem(system)) {
[7237]178 t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
179 if (pppSatObs->isValid()) {
180 obsVector.push_back(pppSatObs);
181 }
182 else {
183 delete pppSatObs;
184 }
185 }
186 }
187
188 // Check whether data are synchronized, compute epoTime
189 // ----------------------------------------------------
190 const double MAXSYNC = 0.05; // synchronization limit
191 double meanDt = 0.0;
192 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
193 const t_pppSatObs* satObs = obsVector.at(ii);
194 if (epoTime.undef()) {
195 epoTime = satObs->time();
196 }
197 else {
198 double dt = satObs->time() - epoTime;
199 if (fabs(dt) > MAXSYNC) {
200 LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
201 return failure;
202 }
203 meanDt += dt;
204 }
205 }
206
207 if (obsVector.size() > 0) {
208 epoTime += meanDt / obsVector.size();
209 }
210
211 return success;
212}
213
[8905]214//
215//////////////////////////////////////////////////////////////////////////////
216bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
217
218 bool pseudoObsIono = false;
219
[8912]220 if (_opt->_pseudoObsIono) {
[8905]221 vector<t_pppSatObs*>::iterator it = obsVector.begin();
222 while (it != obsVector.end()) {
223 t_pppSatObs* satObs = *it;
[9508]224 char sys = satObs->prn().system();
225 t_pppRefSat* refSat = _refSatMap[sys];
[8905]226 double stecRef = refSat->stecValue();
227 if (stecRef && !satObs->isReference()) {
228 pseudoObsIono = true;
229 satObs->setPseudoObsIono(t_frequency::G1, stecRef);
230 }
231 it++;
232 }
233 }
[9538]234
[8961]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
[9560]246//
247//////////////////////////////////////////////////////////////////////////////
248void t_pppClient::useObsWithCodeBiasesOnly(std::vector<t_pppSatObs*>& obsVector) {
249
250 vector<t_pppSatObs*>::iterator it = obsVector.begin();
251 while (it != obsVector.end()) {
252 t_pppSatObs* pppSatObs = *it;
253 char sys = pppSatObs->prn().system();
254 bool codeBiasesAvailable = false;
255 t_frequency::type fType1 = t_lc::toFreq(sys,t_lc::c1);
256 t_frequency::type fType2 = t_lc::toFreq(sys,t_lc::c2);
257 if (pppSatObs->getCodeBias(fType1) &&
258 pppSatObs->getCodeBias(fType2)) {
259 codeBiasesAvailable = true;
260 }
261 if (codeBiasesAvailable) {
262 ++it;
263 }
264 else {
265 it = obsVector.erase(it);
266 delete pppSatObs;
267 }
268 }
269
270}
271
272
[7237]273// Compute the Bancroft position, check for blunders
274//////////////////////////////////////////////////////////////////////////////
[7271]275t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
[7237]276 vector<t_pppSatObs*>& obsVector,
277 ColumnVector& xyzc, bool print) {
278
279 t_lc::type tLC = t_lc::dummy;
280
281 while (true) {
282 Matrix BB(obsVector.size(), 4);
283 int iObs = -1;
284 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
285 const t_pppSatObs* satObs = obsVector.at(ii);
[8034]286 if (tLC == t_lc::dummy) {
287 if (satObs->isValid(t_lc::cIF)) {
288 tLC = t_lc::cIF;
[7237]289 }
[8034]290 else if (satObs->isValid(t_lc::c1)) {
291 tLC = t_lc::c1;
[7237]292 }
[8445]293 else if (satObs->isValid(t_lc::c2)) {
[8034]294 tLC = t_lc::c2;
295 }
[7237]296 }
[8912]297 if ( satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
[8034]298 ++iObs;
299 BB[iObs][0] = satObs->xc()[0];
300 BB[iObs][1] = satObs->xc()[1];
301 BB[iObs][2] = satObs->xc()[2];
302 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
303 }
[7237]304 }
[8912]305 if (iObs + 1 < _opt->_minObs) {
[9545]306 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
[7237]307 return failure;
308 }
309 BB = BB.Rows(1,iObs+1);
310 bancroft(BB, xyzc);
311
312 xyzc[3] /= t_CST::c;
313
314 // Check Blunders
315 // --------------
316 const double BLUNDER = 100.0;
317 double maxRes = 0.0;
318 unsigned maxResIndex = 0;
319 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
320 const t_pppSatObs* satObs = obsVector.at(ii);
[8905]321 if (satObs->isValid() &&
322 satObs->prn().system() == 'G' &&
[8912]323 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
[7237]324 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
[8905]325 double res = rr.NormFrobenius() - satObs->obsValue(tLC)
[8453]326 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
327 if (std::isnan(res) || fabs(res) > maxRes) {
328 std::isnan(res) ?
329 maxRes = res :
[7237]330 maxRes = fabs(res);
331 maxResIndex = ii;
332 }
333 }
334 }
[8453]335 if (!std::isnan(maxRes) && maxRes < BLUNDER) {
[9386]336 if (print && _numEpoProcessing == 1) {
[7237]337 LOG.setf(ios::fixed);
338 LOG << string(epoTime) << " BANCROFT:" << ' '
339 << setw(14) << setprecision(3) << xyzc[0] << ' '
340 << setw(14) << setprecision(3) << xyzc[1] << ' '
341 << setw(14) << setprecision(3) << xyzc[2] << ' '
342 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
343 }
344 break;
345 }
346 else {
347 t_pppSatObs* satObs = obsVector.at(maxResIndex);
348 LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
349 << " " << maxRes << endl;
350 delete satObs;
351 obsVector.erase(obsVector.begin() + maxResIndex);
352 }
353 }
354
355 return success;
356}
357
358// Compute A Priori GPS-Glonass Offset
359//////////////////////////////////////////////////////////////////////////////
[9288]360double t_pppClient::cmpOffGR(vector<t_pppSatObs*>& obsVector) {
[7237]361
362 t_lc::type tLC = t_lc::dummy;
[9288]363 double offGR = 0.0;
[7237]364
[8912]365 if (_opt->useSystem('R')) {
[7237]366 while (obsVector.size() > 0) {
[9288]367 offGR = 0.0;
[7237]368 double maxRes = 0.0;
369 int maxResIndex = -1;
370 t_prn maxResPrn;
371 unsigned nObs = 0;
372 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[7888]373 const t_pppSatObs* satObs = obsVector.at(ii);
[7237]374 if (satObs->prn().system() == 'R') {
375 if (tLC == t_lc::dummy) {
376 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
377 }
[8912]378 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
[7237]379 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
380 ++nObs;
[9288]381 offGR += ll;
[7237]382 if (fabs(ll) > fabs(maxRes)) {
383 maxRes = ll;
384 maxResIndex = ii;
385 maxResPrn = satObs->prn();
386 }
387 }
388 }
389 }
390
391 if (nObs > 0) {
[9288]392 offGR = offGR / nObs;
[7237]393 }
394 else {
[9288]395 offGR = 0.0;
[7237]396 }
[9386]397 if (fabs(maxRes) > OPT->_aprSigOGC) {
[9288]398 LOG << "t_pppClient::cmpOffGR outlier " << maxResPrn.toString() << " " << maxRes << endl;
[7904]399 delete obsVector.at(maxResIndex);
[7237]400 obsVector.erase(obsVector.begin() + maxResIndex);
401 }
402 else {
403 break;
404 }
405 }
406 }
[9288]407 return offGR;
[7237]408}
409
[9288]410// Compute A Priori GPS-Galileo Offset
411//////////////////////////////////////////////////////////////////////////////
412double t_pppClient::cmpOffGE(vector<t_pppSatObs*>& obsVector) {
413
414 t_lc::type tLC = t_lc::dummy;
415 double offGE = 0.0;
416
417 if (_opt->useSystem('E')) {
418 while (obsVector.size() > 0) {
419 offGE = 0.0;
420 double maxRes = 0.0;
421 int maxResIndex = -1;
422 t_prn maxResPrn;
423 unsigned nObs = 0;
424 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
425 const t_pppSatObs* satObs = obsVector.at(ii);
426 if (satObs->prn().system() == 'E') {
427 if (tLC == t_lc::dummy) {
428 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
429 }
430 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
431 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
432 ++nObs;
433 offGE += ll;
434 if (fabs(ll) > fabs(maxRes)) {
435 maxRes = ll;
436 maxResIndex = ii;
437 maxResPrn = satObs->prn();
438 }
439 }
440 }
441 }
442
443 if (nObs > 0) {
444 offGE = offGE / nObs;
445 }
446 else {
447 offGE = 0.0;
448 }
449
[9386]450 if (fabs(maxRes) > OPT->_aprSigOGE) {
[9288]451 LOG << "t_pppClient::cmpOffGE outlier " << maxResPrn.toString() << " " << maxRes << endl;
452 delete obsVector.at(maxResIndex);
453 obsVector.erase(obsVector.begin() + maxResIndex);
454 }
455 else {
456 break;
457 }
458 }
459 }
460 return offGE;
461}
462
[8993]463// Compute A Priori GPS-BDS Offset
464//////////////////////////////////////////////////////////////////////////////
[9288]465double t_pppClient::cmpOffGC(vector<t_pppSatObs*>& obsVector) {
[8993]466
467 t_lc::type tLC = t_lc::dummy;
[9288]468 double offGC = 0.0;
[8993]469
470 if (_opt->useSystem('C')) {
471 while (obsVector.size() > 0) {
[9288]472 offGC = 0.0;
[8993]473 double maxRes = 0.0;
474 int maxResIndex = -1;
475 t_prn maxResPrn;
476 unsigned nObs = 0;
477 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
478 const t_pppSatObs* satObs = obsVector.at(ii);
479 if (satObs->prn().system() == 'C') {
480 if (tLC == t_lc::dummy) {
481 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
482 }
483 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
484 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
485 ++nObs;
[9288]486 offGC += ll;
[8993]487 if (fabs(ll) > fabs(maxRes)) {
488 maxRes = ll;
489 maxResIndex = ii;
490 maxResPrn = satObs->prn();
491 }
492 }
493 }
494 }
495
496 if (nObs > 0) {
[9288]497 offGC = offGC / nObs;
[8993]498 }
499 else {
[9288]500 offGC = 0.0;
[8993]501 }
502
[9386]503 if (fabs(maxRes) > OPT->_aprSigOGC) {
[9288]504 LOG << "t_pppClient::cmpOffGC outlier " << maxResPrn.toString() << " " << maxRes << endl;
[8993]505 delete obsVector.at(maxResIndex);
506 obsVector.erase(obsVector.begin() + maxResIndex);
507 }
508 else {
509 break;
510 }
511 }
512 }
[9288]513 return offGC;
[8993]514}
515
[7271]516//
[7237]517//////////////////////////////////////////////////////////////////////////////
518void t_pppClient::initOutput(t_output* output) {
519 _output = output;
520 _output->_numSat = 0;
[7927]521 _output->_hDop = 0.0;
[7237]522 _output->_error = false;
523}
524
[7271]525//
[7237]526//////////////////////////////////////////////////////////////////////////////
527void t_pppClient::clearObs() {
528 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
529 delete _obsRover.at(ii);
530 }
531 _obsRover.clear();
532}
533
[7271]534//
[7237]535//////////////////////////////////////////////////////////////////////////////
[9548]536void t_pppClient::finish(t_irc irc, int ind) { //LOG << "t_pppClient::finish(" << irc << ") " << ind << endl;
[7237]537
538 clearObs();
539
540 _output->_epoTime = _epoTimeRover;
541
542 if (irc == success) {
543 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
544 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
545 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
546
547 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
548
549 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
550
551 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
552 _output->_trp = _filter->trp();
553 _output->_trpStdev = _filter->trpStdev();
554
[9386]555 _output->_numSat = _filter->numSat();
556 _output->_hDop = _filter->HDOP();
[7237]557 _output->_error = false;
558 }
559 else {
560 _output->_error = true;
561 }
562 _output->_log = _log->str();
563 delete _log; _log = new ostringstream();
[9545]564
565 return;
[7237]566}
567
[7271]568//
[7237]569//////////////////////////////////////////////////////////////////////////////
570t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
571 vector<t_pppSatObs*>& obsVector) {
572 bncTime time;
573 time = _epoTimeRover;
[8912]574 station->setName(_opt->_roverName);
575 station->setAntName(_opt->_antNameRover);
[8905]576 station->setEpochTime(time);
[8912]577 if (_opt->xyzAprRoverSet()) {
578 station->setXyzApr(_opt->_xyzAprRover);
[7237]579 }
580 else {
581 station->setXyzApr(xyzc.Rows(1,3));
582 }
[8912]583 station->setNeuEcc(_opt->_neuEccRover);
[7237]584
585 // Receiver Clock
586 // --------------
587 station->setDClk(xyzc[3]);
588
589 // Tides
590 // -----
[8905]591 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
592 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
[7271]593
[7237]594 // Observation model
595 // -----------------
596 vector<t_pppSatObs*>::iterator it = obsVector.begin();
597 while (it != obsVector.end()) {
598 t_pppSatObs* satObs = *it;
[7254]599 t_irc modelSetup;
[7237]600 if (satObs->isValid()) {
[7254]601 modelSetup = satObs->cmpModel(station);
[7237]602 }
[7254]603 if (satObs->isValid() &&
[8912]604 satObs->eleSat() >= _opt->_minEle &&
[7254]605 modelSetup == success) {
[7237]606 ++it;
607 }
608 else {
609 delete satObs;
610 it = obsVector.erase(it);
611 }
612 }
613
614 return success;
615}
616
[7271]617//
[7237]618//////////////////////////////////////////////////////////////////////////////
619void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
620
621 try {
622 initOutput(output);
[8912]623 bool epochReProcessing = false;
[9386]624 _numEpoProcessing = 0;
[9419]625 _historicalRefSats.clear();
626
[8905]627 do {
[9386]628 _numEpoProcessing++;
[9419]629#ifdef BNC_DEBUG_PPP
630 LOG << "_numEpoProcessing " << _numEpoProcessing << endl;
631#endif
[9386]632 if (_obsPool->refSatChanged()) {
[9508]633 if(_filter->datumTransformation(_refSatMap) != success) {
634 LOG << "t_pppFilter::datumTransformation() != success" << endl;
[9548]635 reset();
[9545]636 return finish(failure,1);
[9386]637 }
638 else {
[9508]639 LOG << "t_pppFilter::datumTransformation() == success" << endl;
[9527]640 _filter->rememberState(1);
[9386]641 }
[8956]642 }
[8905]643 // Prepare Observations of the Rover
644 // ---------------------------------
645 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
[9545]646 return finish(failure,2);
[7237]647 }
[8905]648
[9386]649 if (_numEpoProcessing == 1) {
650 LOG << "\nPPP of Epoch ";
651 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
652 LOG << "\n---------------------------------------------------------------\n";
653 }
654
[8905]655 for (int iter = 1; iter <= 2; iter++) {
656 ColumnVector xyzc(4); xyzc = 0.0;
657 bool print = (iter == 2);
658 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
[9545]659 return finish(failure,3);
[8905]660 }
661 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
[9545]662 return finish(failure,4);
[8905]663 }
664 }
665
[8912]666 if (_opt->_refSatRequired) {
[9386]667 if (handleRefSatellites(_obsRover) != success) {
[9545]668 return finish(failure,6);
[8905]669 }
[9508]670 if (_obsPool->refSatChanged()) {
671 LOG << "t_pppFilter: refSatChanged()" << endl;
[9527]672 epochReProcessing = true;
673 continue;
[9386]674 }
[8905]675 }
[7237]676
[9560]677 // Check if obs have code biases
678 // -----------------------------
679 if (OPT->_obsModelType == OPT->DCMcodeBias ||
680 OPT->_obsModelType == OPT->DCMphaseBias) {
681 useObsWithCodeBiasesOnly(_obsRover);
682 }
683
684 if (int(_obsRover.size()) < _opt->_minObs) {
685 LOG << "t_pppClient::processEpoch not enough observations" << endl;
686 return finish(failure,5);
687 }
688
[8956]689 // Prepare Pseudo Observations of the Rover
690 // ----------------------------------------
691 _pseudoObsIono = preparePseudoObs(_obsRover);
692
[8905]693 // Store last epoch of data
694 // ------------------------
[9508]695 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono, _refSatMap);
[7904]696
[8905]697 // Process Epoch in Filter
698 // -----------------------
[9386]699 if (_filter->processEpoch() != success) {
[9545]700 LOG << "filter->processEpoch() != success" << endl;
701 return finish(failure,7);
[8905]702 }
[8912]703
704 // Epoch re-processing required?
705 // -----------------------------
[9395]706 if (_obsPool->refSatChangeRequired() && //SLIP
707 _opt->_obsModelType != t_pppOptions::UncombPPP) {
[9545]708 LOG << "pppClient: _obsPool->refSatChangeRequired() " << endl;
[8912]709 epochReProcessing = true;
[8956]710 _obsPool->deleteLastEpoch();
[9527]711 _filter->restoreState(0);
[9386]712 setHistoricalRefSats();
[8912]713 }
714 else {
715 epochReProcessing = false;
[9537]716 if (OPT->_obsModelType == OPT->DCMcodeBias ||
717 OPT->_obsModelType == OPT->DCMphaseBias) {
718 _filter->rememberState(0);
719 }
[8912]720 }
721 } while (epochReProcessing);
[9431]722
[7237]723 }
724 catch (Exception& exc) {
725 LOG << exc.what() << endl;
[9545]726 return finish(failure,8);
[7237]727 }
728 catch (t_except msg) {
729 LOG << msg.what() << endl;
[9545]730 return finish(failure,9);
[7237]731 }
732 catch (const char* msg) {
733 LOG << msg << endl;
[9545]734 return finish(failure,10);
[7237]735 }
736 catch (...) {
737 LOG << "unknown exception" << endl;
[9545]738 return finish(failure,11);
[7237]739 }
[9545]740 return finish(success,12);
[7237]741}
742
[7271]743//
[7237]744////////////////////////////////////////////////////////////////////////////
745double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
746 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
747}
748
[7271]749//
[7237]750////////////////////////////////////////////////////////////////////////////
751void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
752
753 if (pos.Nrows() != 4) {
754 pos.ReSize(4);
755 }
756 pos = 0.0;
757
758 for (int iter = 1; iter <= 2; iter++) {
759 Matrix BB = BBpass;
760 int mm = BB.Nrows();
761 for (int ii = 1; ii <= mm; ii++) {
762 double xx = BB(ii,1);
763 double yy = BB(ii,2);
764 double traveltime = 0.072;
765 if (iter > 1) {
766 double zz = BB(ii,3);
[7271]767 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
768 (yy-pos(2)) * (yy-pos(2)) +
[7237]769 (zz-pos(3)) * (zz-pos(3)) );
770 traveltime = rho / t_CST::c;
771 }
772 double angle = traveltime * t_CST::omega;
773 double cosa = cos(angle);
774 double sina = sin(angle);
775 BB(ii,1) = cosa * xx + sina * yy;
776 BB(ii,2) = -sina * xx + cosa * yy;
777 }
[7271]778
[7237]779 Matrix BBB;
780 if (mm > 4) {
781 SymmetricMatrix hlp; hlp << BB.t() * BB;
782 BBB = hlp.i() * BB.t();
783 }
784 else {
785 BBB = BB.i();
786 }
787 ColumnVector ee(mm); ee = 1.0;
788 ColumnVector alpha(mm); alpha = 0.0;
789 for (int ii = 1; ii <= mm; ii++) {
[7271]790 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
[7237]791 }
792 ColumnVector BBBe = BBB * ee;
793 ColumnVector BBBalpha = BBB * alpha;
794 double aa = lorentz(BBBe, BBBe);
795 double bb = lorentz(BBBe, BBBalpha)-1;
796 double cc = lorentz(BBBalpha, BBBalpha);
797 double root = sqrt(bb*bb-aa*cc);
798
[7271]799 Matrix hlpPos(4,2);
[7237]800 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
801 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
802
803 ColumnVector omc(2);
804 for (int pp = 1; pp <= 2; pp++) {
805 hlpPos(4,pp) = -hlpPos(4,pp);
[7271]806 omc(pp) = BB(1,4) -
[7237]807 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
808 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
[7271]809 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
[7237]810 hlpPos(4,pp);
811 }
812 if ( fabs(omc(1)) > fabs(omc(2)) ) {
813 pos = hlpPos.Column(2);
814 }
815 else {
816 pos = hlpPos.Column(1);
817 }
818 }
819}
820
[7972]821//
822//////////////////////////////////////////////////////////////////////////////
[8956]823void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
824 // reference satellite definition per system
825 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
[9490]826 t_irc refSatReDefinition = success;
[9386]827 char sys = _opt->systems()[iSys];
[8956]828 bool refSatDefined = false;
[9508]829 t_pppRefSat* refSat = _refSatMap[sys];
[8956]830 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
831 t_pppSatObs* satObs = obsVector.at(ii);
[9386]832 if (satObs->eleSat() < _opt->_minEle) {
833 continue;
834 }
[8956]835 // reference satellite is unchanged
[9395]836 // ================================
[9508]837 if ( !_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) {
[8956]838 refSatDefined = true;
839 obsVector[ii]->setAsReference();
840 }
841 // reference satellite has changed
[9395]842 // ===============================
843 else if ( _obsPool->refSatChangeRequired(sys) && refSat->prn() != satObs->prn()) {
[9386]844 if (satObs->prn().system() == sys) {
[9395]845 if (!_historicalRefSats[sys].contains(satObs->prn())) {
846 refSatDefined = true;
847 obsVector[ii]->setAsReference();
848 refSat->setPrn(satObs->prn());
849 }
850 else if ( _historicalRefSats[sys].contains(satObs->prn())) {
851 refSatReDefinition = failure;
852 }
[8956]853 }
854 }
855 if (refSatDefined) {
856 if (OPT->_pseudoObsIono) {
857 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
858 }
859 break;
860 }
861 }
[9490]862
[9398]863 // all available satellites were already tried to use
[9395]864 if ((!refSatDefined) && (refSatReDefinition == failure)) {
865 refSat->setPrn(t_prn(sys, 99));
[9398]866 _obsPool->setRefSatChangeRequired(sys, false);
867 return;
[9395]868 }
869
[8956]870 // reference satellite has to be initialized
[9395]871 // =========================================
[8956]872 if (!refSatDefined) {
873 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
874 t_pppSatObs* satObs = obsVector.at(ii);
875 if (satObs->eleSat() < _opt->_minEle) {
876 continue;
877 }
[9395]878 if (satObs->prn().system() == sys) {
[8956]879 obsVector[ii]->setAsReference();
880 refSat->setPrn(satObs->prn());
881 if (OPT->_pseudoObsIono) {
882 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
883 }
884 refSatDefined = true;
885 break;
886 }
887 }
888 }
[9395]889
[9398]890 // no observations for that system
891 // ===============================
892 if (!refSatDefined) {
[9386]893 refSat->setPrn(t_prn());
894 }
[9398]895 _obsPool->setRefSatChangeRequired(sys, false); // done or impossible
[8956]896 }
[9398]897
898 return;
[9386]899}
[8956]900
[9386]901//
902//////////////////////////////////////////////////////////////////////////////
903t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
904
905 // set refSats in current epoch
906 // ============================
907 setRefSatellites(obsVector); // current epoch
908 LOG.setf(ios::fixed);
[9508]909 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
910 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
[9527]911
[9508]912 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
[9386]913 while (it.hasNext()) {
914 it.next();
915 char sys = it.key();
916 t_prn prn = it.value()->prn();
[9508]917 t_prn refSatLastEpochPrn = t_prn();
918 if (epoch) {
919 refSatLastEpochPrn = refSatMapLastEpoch[sys]->prn();
920 }
[9395]921 if (prn.number() == 0) { // no obs for that system available
922 continue;
923 }
924 else if (prn.number() == 99) { // refSat re-definition not possible
[9490]925 LOG << " => refSat re-definition impossible: " << sys << endl;
[9386]926 return failure;
927 }
[9432]928 QString str;
[9508]929 if (prn == refSatLastEpochPrn || refSatLastEpochPrn == t_prn() ) {
[9386]930 _obsPool->setRefSatChanged(sys, false);
931 str = " SET ";
932 }
933 else {
934 _obsPool->setRefSatChanged(sys, true);
935 str = " RESET ";
936 }
937 LOG << string(_epoTimeRover) << str.toStdString() << " REFSAT " << sys << ": " << prn.toString() << endl;
938 }
939 return success;
[8956]940}
941
[9386]942void t_pppClient::setHistoricalRefSats() {
[9508]943 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
[9386]944 while (it.hasNext()) {
945 it.next();
946 t_prn prn = it.value()->prn();
947 char sys = prn.system();
[9548]948 if (_obsPool->refSatChangeRequired(sys)) {
[9386]949 _historicalRefSats[sys].append(prn);
950 }
[9508]951 }
952}
[9386]953
[8956]954//
955//////////////////////////////////////////////////////////////////////////////
[9548]956void t_pppClient::reset() {LOG << "t_pppClient::reset()" << endl;
[7972]957
958 // to delete old orbit and clock corrections
959 delete _ephPool;
960 _ephPool = new t_pppEphPool();
961
962 // to delete old code biases
963 delete _obsPool;
964 _obsPool = new t_pppObsPool();
[8905]965
966 // to delete all parameters
967 delete _filter;
968 _filter = new t_pppFilter(_obsPool);
969
[7996]970}
Note: See TracBrowser for help on using the repository browser.