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

Last change on this file since 10576 was 10576, checked in by stuerze, 46 hours ago

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