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

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

update regarding PPP: pseudo obs tropo completely removed

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 27.1 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
[7237]246// Compute the Bancroft position, check for blunders
247//////////////////////////////////////////////////////////////////////////////
[7271]248t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
[7237]249 vector<t_pppSatObs*>& obsVector,
250 ColumnVector& xyzc, bool print) {
251
252 t_lc::type tLC = t_lc::dummy;
253
254 while (true) {
255 Matrix BB(obsVector.size(), 4);
256 int iObs = -1;
257 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
258 const t_pppSatObs* satObs = obsVector.at(ii);
[8034]259 if (tLC == t_lc::dummy) {
260 if (satObs->isValid(t_lc::cIF)) {
261 tLC = t_lc::cIF;
[7237]262 }
[8034]263 else if (satObs->isValid(t_lc::c1)) {
264 tLC = t_lc::c1;
[7237]265 }
[8445]266 else if (satObs->isValid(t_lc::c2)) {
[8034]267 tLC = t_lc::c2;
268 }
[7237]269 }
[8912]270 if ( satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
[8034]271 ++iObs;
272 BB[iObs][0] = satObs->xc()[0];
273 BB[iObs][1] = satObs->xc()[1];
274 BB[iObs][2] = satObs->xc()[2];
275 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
276 }
[7237]277 }
[8912]278 if (iObs + 1 < _opt->_minObs) {
[7237]279 LOG << "t_pppClient::cmpBancroft not enough observations" << endl;
280 return failure;
281 }
282 BB = BB.Rows(1,iObs+1);
283 bancroft(BB, xyzc);
284
285 xyzc[3] /= t_CST::c;
286
287 // Check Blunders
288 // --------------
289 const double BLUNDER = 100.0;
290 double maxRes = 0.0;
291 unsigned maxResIndex = 0;
292 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
293 const t_pppSatObs* satObs = obsVector.at(ii);
[8905]294 if (satObs->isValid() &&
295 satObs->prn().system() == 'G' &&
[8912]296 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
[7237]297 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
[8905]298 double res = rr.NormFrobenius() - satObs->obsValue(tLC)
[8453]299 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
300 if (std::isnan(res) || fabs(res) > maxRes) {
301 std::isnan(res) ?
302 maxRes = res :
[7237]303 maxRes = fabs(res);
304 maxResIndex = ii;
305 }
306 }
307 }
[8453]308 if (!std::isnan(maxRes) && maxRes < BLUNDER) {
[9386]309 if (print && _numEpoProcessing == 1) {
[7237]310 LOG.setf(ios::fixed);
311 LOG << string(epoTime) << " BANCROFT:" << ' '
312 << setw(14) << setprecision(3) << xyzc[0] << ' '
313 << setw(14) << setprecision(3) << xyzc[1] << ' '
314 << setw(14) << setprecision(3) << xyzc[2] << ' '
315 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
316 }
317 break;
318 }
319 else {
320 t_pppSatObs* satObs = obsVector.at(maxResIndex);
321 LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
322 << " " << maxRes << endl;
323 delete satObs;
324 obsVector.erase(obsVector.begin() + maxResIndex);
325 }
326 }
327
328 return success;
329}
330
331// Compute A Priori GPS-Glonass Offset
332//////////////////////////////////////////////////////////////////////////////
[9288]333double t_pppClient::cmpOffGR(vector<t_pppSatObs*>& obsVector) {
[7237]334
335 t_lc::type tLC = t_lc::dummy;
[9288]336 double offGR = 0.0;
[7237]337
[8912]338 if (_opt->useSystem('R')) {
[7237]339 while (obsVector.size() > 0) {
[9288]340 offGR = 0.0;
[7237]341 double maxRes = 0.0;
342 int maxResIndex = -1;
343 t_prn maxResPrn;
344 unsigned nObs = 0;
345 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[7888]346 const t_pppSatObs* satObs = obsVector.at(ii);
[7237]347 if (satObs->prn().system() == 'R') {
348 if (tLC == t_lc::dummy) {
349 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
350 }
[8912]351 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
[7237]352 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
353 ++nObs;
[9288]354 offGR += ll;
[7237]355 if (fabs(ll) > fabs(maxRes)) {
356 maxRes = ll;
357 maxResIndex = ii;
358 maxResPrn = satObs->prn();
359 }
360 }
361 }
362 }
363
364 if (nObs > 0) {
[9288]365 offGR = offGR / nObs;
[7237]366 }
367 else {
[9288]368 offGR = 0.0;
[7237]369 }
[9386]370 if (fabs(maxRes) > OPT->_aprSigOGC) {
[9288]371 LOG << "t_pppClient::cmpOffGR outlier " << maxResPrn.toString() << " " << maxRes << endl;
[7904]372 delete obsVector.at(maxResIndex);
[7237]373 obsVector.erase(obsVector.begin() + maxResIndex);
374 }
375 else {
376 break;
377 }
378 }
379 }
[9288]380 return offGR;
[7237]381}
382
[9288]383// Compute A Priori GPS-Galileo Offset
384//////////////////////////////////////////////////////////////////////////////
385double t_pppClient::cmpOffGE(vector<t_pppSatObs*>& obsVector) {
386
387 t_lc::type tLC = t_lc::dummy;
388 double offGE = 0.0;
389
390 if (_opt->useSystem('E')) {
391 while (obsVector.size() > 0) {
392 offGE = 0.0;
393 double maxRes = 0.0;
394 int maxResIndex = -1;
395 t_prn maxResPrn;
396 unsigned nObs = 0;
397 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
398 const t_pppSatObs* satObs = obsVector.at(ii);
399 if (satObs->prn().system() == 'E') {
400 if (tLC == t_lc::dummy) {
401 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
402 }
403 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
404 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
405 ++nObs;
406 offGE += ll;
407 if (fabs(ll) > fabs(maxRes)) {
408 maxRes = ll;
409 maxResIndex = ii;
410 maxResPrn = satObs->prn();
411 }
412 }
413 }
414 }
415
416 if (nObs > 0) {
417 offGE = offGE / nObs;
418 }
419 else {
420 offGE = 0.0;
421 }
422
[9386]423 if (fabs(maxRes) > OPT->_aprSigOGE) {
[9288]424 LOG << "t_pppClient::cmpOffGE outlier " << maxResPrn.toString() << " " << maxRes << endl;
425 delete obsVector.at(maxResIndex);
426 obsVector.erase(obsVector.begin() + maxResIndex);
427 }
428 else {
429 break;
430 }
431 }
432 }
433 return offGE;
434}
435
[8993]436// Compute A Priori GPS-BDS Offset
437//////////////////////////////////////////////////////////////////////////////
[9288]438double t_pppClient::cmpOffGC(vector<t_pppSatObs*>& obsVector) {
[8993]439
440 t_lc::type tLC = t_lc::dummy;
[9288]441 double offGC = 0.0;
[8993]442
443 if (_opt->useSystem('C')) {
444 while (obsVector.size() > 0) {
[9288]445 offGC = 0.0;
[8993]446 double maxRes = 0.0;
447 int maxResIndex = -1;
448 t_prn maxResPrn;
449 unsigned nObs = 0;
450 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
451 const t_pppSatObs* satObs = obsVector.at(ii);
452 if (satObs->prn().system() == 'C') {
453 if (tLC == t_lc::dummy) {
454 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
455 }
456 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
457 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
458 ++nObs;
[9288]459 offGC += ll;
[8993]460 if (fabs(ll) > fabs(maxRes)) {
461 maxRes = ll;
462 maxResIndex = ii;
463 maxResPrn = satObs->prn();
464 }
465 }
466 }
467 }
468
469 if (nObs > 0) {
[9288]470 offGC = offGC / nObs;
[8993]471 }
472 else {
[9288]473 offGC = 0.0;
[8993]474 }
475
[9386]476 if (fabs(maxRes) > OPT->_aprSigOGC) {
[9288]477 LOG << "t_pppClient::cmpOffGC outlier " << maxResPrn.toString() << " " << maxRes << endl;
[8993]478 delete obsVector.at(maxResIndex);
479 obsVector.erase(obsVector.begin() + maxResIndex);
480 }
481 else {
482 break;
483 }
484 }
485 }
[9288]486 return offGC;
[8993]487}
488
[7271]489//
[7237]490//////////////////////////////////////////////////////////////////////////////
491void t_pppClient::initOutput(t_output* output) {
492 _output = output;
493 _output->_numSat = 0;
[7927]494 _output->_hDop = 0.0;
[7237]495 _output->_error = false;
496}
497
[7271]498//
[7237]499//////////////////////////////////////////////////////////////////////////////
500void t_pppClient::clearObs() {
501 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
502 delete _obsRover.at(ii);
503 }
504 _obsRover.clear();
505}
506
[7271]507//
[7237]508//////////////////////////////////////////////////////////////////////////////
509void t_pppClient::finish(t_irc irc) {
510
511 clearObs();
512
513 _output->_epoTime = _epoTimeRover;
514
515 if (irc == success) {
516 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
517 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
518 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
519
520 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
521
522 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
523
524 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
525 _output->_trp = _filter->trp();
526 _output->_trpStdev = _filter->trpStdev();
527
[9386]528 _output->_numSat = _filter->numSat();
529 _output->_hDop = _filter->HDOP();
[7237]530 _output->_error = false;
531 }
532 else {
533 _output->_error = true;
534 }
535 _output->_log = _log->str();
536 delete _log; _log = new ostringstream();
537}
538
[7271]539//
[7237]540//////////////////////////////////////////////////////////////////////////////
541t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
542 vector<t_pppSatObs*>& obsVector) {
543 bncTime time;
544 time = _epoTimeRover;
[8912]545 station->setName(_opt->_roverName);
546 station->setAntName(_opt->_antNameRover);
[8905]547 station->setEpochTime(time);
[8912]548 if (_opt->xyzAprRoverSet()) {
549 station->setXyzApr(_opt->_xyzAprRover);
[7237]550 }
551 else {
552 station->setXyzApr(xyzc.Rows(1,3));
553 }
[8912]554 station->setNeuEcc(_opt->_neuEccRover);
[7237]555
556 // Receiver Clock
557 // --------------
558 station->setDClk(xyzc[3]);
559
560 // Tides
561 // -----
[8905]562 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
563 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
[7271]564
[7237]565 // Observation model
566 // -----------------
567 vector<t_pppSatObs*>::iterator it = obsVector.begin();
568 while (it != obsVector.end()) {
569 t_pppSatObs* satObs = *it;
[7254]570 t_irc modelSetup;
[7237]571 if (satObs->isValid()) {
[7254]572 modelSetup = satObs->cmpModel(station);
[7237]573 }
[7254]574 if (satObs->isValid() &&
[8912]575 satObs->eleSat() >= _opt->_minEle &&
[7254]576 modelSetup == success) {
[7237]577 ++it;
578 }
579 else {
580 delete satObs;
581 it = obsVector.erase(it);
582 }
583 }
584
585 return success;
586}
587
[7271]588//
[7237]589//////////////////////////////////////////////////////////////////////////////
590void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
591
592 try {
593 initOutput(output);
[8912]594 bool epochReProcessing = false;
[9386]595 _numEpoProcessing = 0;
[9419]596 _historicalRefSats.clear();
597
[8905]598 do {
[9386]599 _numEpoProcessing++;
[9419]600#ifdef BNC_DEBUG_PPP
601 LOG << "_numEpoProcessing " << _numEpoProcessing << endl;
602#endif
[9386]603 if (_obsPool->refSatChanged()) {
[9508]604 if(_filter->datumTransformation(_refSatMap) != success) {
605 LOG << "t_pppFilter::datumTransformation() != success" << endl;
[9386]606 return finish(failure);
607 }
608 else {
[9508]609 LOG << "t_pppFilter::datumTransformation() == success" << endl;
[9527]610 _filter->rememberState(1);
[9386]611 }
[8956]612 }
[8905]613 // Prepare Observations of the Rover
614 // ---------------------------------
615 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
[7237]616 return finish(failure);
617 }
[8905]618
[9386]619 if (_numEpoProcessing == 1) {
620 LOG << "\nPPP of Epoch ";
621 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
622 LOG << "\n---------------------------------------------------------------\n";
623 }
624
[8905]625 for (int iter = 1; iter <= 2; iter++) {
626 ColumnVector xyzc(4); xyzc = 0.0;
627 bool print = (iter == 2);
628 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
629 return finish(failure);
630 }
631 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
632 return finish(failure);
633 }
634 }
635
[8912]636 if (_opt->_refSatRequired) {
[9386]637 if (handleRefSatellites(_obsRover) != success) {
638 return finish(failure);
[8905]639 }
[9508]640 if (_obsPool->refSatChanged()) {
641 LOG << "t_pppFilter: refSatChanged()" << endl;
[9527]642 epochReProcessing = true;
643 continue;
[9386]644 }
[8905]645 }
[7237]646
[9386]647 _offGR = cmpOffGR(_obsRover);
648 _offGE = cmpOffGE(_obsRover);
649 _offGC = cmpOffGC(_obsRover);
[8956]650
651 // Prepare Pseudo Observations of the Rover
652 // ----------------------------------------
653 _pseudoObsIono = preparePseudoObs(_obsRover);
654
655 if (int(_obsRover.size()) < _opt->_minObs) {
656 LOG << "t_pppClient::processEpoch not enough observations" << endl;
657 return finish(failure);
658 }
659
[8905]660 // Store last epoch of data
661 // ------------------------
[9508]662 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono, _refSatMap);
[7904]663
[8905]664 // Process Epoch in Filter
665 // -----------------------
[9386]666 if (_filter->processEpoch() != success) {
[8905]667 return finish(failure);
668 }
[8912]669
670 // Epoch re-processing required?
671 // -----------------------------
[9395]672 if (_obsPool->refSatChangeRequired() && //SLIP
673 _opt->_obsModelType != t_pppOptions::UncombPPP) {
[8912]674 epochReProcessing = true;
[8956]675 _obsPool->deleteLastEpoch();
[9527]676 _filter->restoreState(0);
[9386]677 setHistoricalRefSats();
[8912]678 }
679 else {
680 epochReProcessing = false;
[9537]681 if (OPT->_obsModelType == OPT->DCMcodeBias ||
682 OPT->_obsModelType == OPT->DCMphaseBias) {
683 _filter->rememberState(0);
684 }
[8912]685 }
686 } while (epochReProcessing);
[9431]687
[7237]688 }
689 catch (Exception& exc) {
690 LOG << exc.what() << endl;
691 return finish(failure);
692 }
693 catch (t_except msg) {
694 LOG << msg.what() << endl;
695 return finish(failure);
696 }
697 catch (const char* msg) {
698 LOG << msg << endl;
699 return finish(failure);
700 }
701 catch (...) {
702 LOG << "unknown exception" << endl;
703 return finish(failure);
704 }
705
706 return finish(success);
707}
708
[7271]709//
[7237]710////////////////////////////////////////////////////////////////////////////
711double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
712 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
713}
714
[7271]715//
[7237]716////////////////////////////////////////////////////////////////////////////
717void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
718
719 if (pos.Nrows() != 4) {
720 pos.ReSize(4);
721 }
722 pos = 0.0;
723
724 for (int iter = 1; iter <= 2; iter++) {
725 Matrix BB = BBpass;
726 int mm = BB.Nrows();
727 for (int ii = 1; ii <= mm; ii++) {
728 double xx = BB(ii,1);
729 double yy = BB(ii,2);
730 double traveltime = 0.072;
731 if (iter > 1) {
732 double zz = BB(ii,3);
[7271]733 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
734 (yy-pos(2)) * (yy-pos(2)) +
[7237]735 (zz-pos(3)) * (zz-pos(3)) );
736 traveltime = rho / t_CST::c;
737 }
738 double angle = traveltime * t_CST::omega;
739 double cosa = cos(angle);
740 double sina = sin(angle);
741 BB(ii,1) = cosa * xx + sina * yy;
742 BB(ii,2) = -sina * xx + cosa * yy;
743 }
[7271]744
[7237]745 Matrix BBB;
746 if (mm > 4) {
747 SymmetricMatrix hlp; hlp << BB.t() * BB;
748 BBB = hlp.i() * BB.t();
749 }
750 else {
751 BBB = BB.i();
752 }
753 ColumnVector ee(mm); ee = 1.0;
754 ColumnVector alpha(mm); alpha = 0.0;
755 for (int ii = 1; ii <= mm; ii++) {
[7271]756 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
[7237]757 }
758 ColumnVector BBBe = BBB * ee;
759 ColumnVector BBBalpha = BBB * alpha;
760 double aa = lorentz(BBBe, BBBe);
761 double bb = lorentz(BBBe, BBBalpha)-1;
762 double cc = lorentz(BBBalpha, BBBalpha);
763 double root = sqrt(bb*bb-aa*cc);
764
[7271]765 Matrix hlpPos(4,2);
[7237]766 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
767 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
768
769 ColumnVector omc(2);
770 for (int pp = 1; pp <= 2; pp++) {
771 hlpPos(4,pp) = -hlpPos(4,pp);
[7271]772 omc(pp) = BB(1,4) -
[7237]773 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
774 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
[7271]775 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
[7237]776 hlpPos(4,pp);
777 }
778 if ( fabs(omc(1)) > fabs(omc(2)) ) {
779 pos = hlpPos.Column(2);
780 }
781 else {
782 pos = hlpPos.Column(1);
783 }
784 }
785}
786
[7972]787//
788//////////////////////////////////////////////////////////////////////////////
[8956]789void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
790 // reference satellite definition per system
791 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
[9490]792 t_irc refSatReDefinition = success;
[9386]793 char sys = _opt->systems()[iSys];
[8956]794 bool refSatDefined = false;
[9508]795 t_pppRefSat* refSat = _refSatMap[sys];
[8956]796 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
797 t_pppSatObs* satObs = obsVector.at(ii);
[9386]798 if (satObs->eleSat() < _opt->_minEle) {
799 continue;
800 }
[8956]801 // reference satellite is unchanged
[9395]802 // ================================
[9508]803 if ( !_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) {
[8956]804 refSatDefined = true;
805 obsVector[ii]->setAsReference();
806 }
807 // reference satellite has changed
[9395]808 // ===============================
809 else if ( _obsPool->refSatChangeRequired(sys) && refSat->prn() != satObs->prn()) {
[9386]810 if (satObs->prn().system() == sys) {
[9395]811 if (!_historicalRefSats[sys].contains(satObs->prn())) {
812 refSatDefined = true;
813 obsVector[ii]->setAsReference();
814 refSat->setPrn(satObs->prn());
815 }
816 else if ( _historicalRefSats[sys].contains(satObs->prn())) {
817 refSatReDefinition = failure;
818 }
[8956]819 }
820 }
821 if (refSatDefined) {
822 if (OPT->_pseudoObsIono) {
823 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
824 }
825 break;
826 }
827 }
[9490]828
[9398]829 // all available satellites were already tried to use
[9395]830 if ((!refSatDefined) && (refSatReDefinition == failure)) {
831 refSat->setPrn(t_prn(sys, 99));
[9398]832 _obsPool->setRefSatChangeRequired(sys, false);
833 return;
[9395]834 }
835
[8956]836 // reference satellite has to be initialized
[9395]837 // =========================================
[8956]838 if (!refSatDefined) {
839 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
840 t_pppSatObs* satObs = obsVector.at(ii);
841 if (satObs->eleSat() < _opt->_minEle) {
842 continue;
843 }
[9395]844 if (satObs->prn().system() == sys) {
[8956]845 obsVector[ii]->setAsReference();
846 refSat->setPrn(satObs->prn());
847 if (OPT->_pseudoObsIono) {
848 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
849 }
850 refSatDefined = true;
851 break;
852 }
853 }
854 }
[9395]855
[9398]856 // no observations for that system
857 // ===============================
858 if (!refSatDefined) {
[9386]859 refSat->setPrn(t_prn());
860 }
[9398]861 _obsPool->setRefSatChangeRequired(sys, false); // done or impossible
[8956]862 }
[9398]863
864 return;
[9386]865}
[8956]866
[9386]867//
868//////////////////////////////////////////////////////////////////////////////
869t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
870
871 // set refSats in current epoch
872 // ============================
873 setRefSatellites(obsVector); // current epoch
874 LOG.setf(ios::fixed);
[9508]875 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
876 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
[9527]877
[9508]878 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
[9386]879 while (it.hasNext()) {
880 it.next();
881 char sys = it.key();
882 t_prn prn = it.value()->prn();
[9508]883 t_prn refSatLastEpochPrn = t_prn();
884 if (epoch) {
885 refSatLastEpochPrn = refSatMapLastEpoch[sys]->prn();
886 }
[9395]887 if (prn.number() == 0) { // no obs for that system available
888 continue;
889 }
890 else if (prn.number() == 99) { // refSat re-definition not possible
[9490]891 LOG << " => refSat re-definition impossible: " << sys << endl;
[9386]892 return failure;
893 }
[9432]894 QString str;
[9508]895 if (prn == refSatLastEpochPrn || refSatLastEpochPrn == t_prn() ) {
[9386]896 _obsPool->setRefSatChanged(sys, false);
897 str = " SET ";
898 }
899 else {
900 _obsPool->setRefSatChanged(sys, true);
901 str = " RESET ";
902 }
903 LOG << string(_epoTimeRover) << str.toStdString() << " REFSAT " << sys << ": " << prn.toString() << endl;
904 }
905 return success;
[8956]906}
907
[9386]908void t_pppClient::setHistoricalRefSats() {
[9508]909 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
[9386]910 while (it.hasNext()) {
911 it.next();
912 t_prn prn = it.value()->prn();
913 char sys = prn.system();
914 if (_obsPool->refSatChangeRequired(sys)){
915 _historicalRefSats[sys].append(prn);
916 }
[9508]917 }
918}
[9386]919
[8956]920//
921//////////////////////////////////////////////////////////////////////////////
[7972]922void t_pppClient::reset() {
923
924 // to delete old orbit and clock corrections
925 delete _ephPool;
926 _ephPool = new t_pppEphPool();
927
928 // to delete old code biases
929 delete _obsPool;
930 _obsPool = new t_pppObsPool();
[8905]931
932 // to delete all parameters
933 delete _filter;
934 _filter = new t_pppFilter(_obsPool);
935
[7996]936}
Note: See TracBrowser for help on using the repository browser.