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

Last change on this file since 10373 was 10373, checked in by stuerze, 17 months 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: 24.4 KB
Line 
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 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <QThreadStorage>
18
19#include <iostream>
20#include <iomanip>
21#include <cmath>
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 _running = true;
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();
58 _filter = new t_pppFilter();
59 _tides = new t_tides();
60 _antex = 0;
61 if (!_opt->_antexFileName.empty()) {
62 _antex = new bncAntex(_opt->_antexFileName.c_str());
63 }
64 if (!_opt->_blqFileName.empty()) {
65 if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
66 //_tides->printAllBlqSets();
67 }
68 }
69 _offGps = 0.0;
70 _offGlo = 0.0;
71 _offGal = 0.0;
72 _offBds = 0.0;
73 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
74}
75
76// Destructor
77//////////////////////////////////////////////////////////////////////////////
78t_pppClient::~t_pppClient() {
79 _running = false;
80 delete _log;
81 delete _opt;
82 delete _ephPool;
83 delete _obsPool;
84 delete _staRover;
85 if (_antex) {
86 delete _antex;
87 }
88 delete _filter;
89 delete _tides;
90 clearObs();
91}
92
93//
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);
99 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
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 }
109 else if (ephBDS) {
110 _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
111 }
112}
113
114//
115//////////////////////////////////////////////////////////////////////////////
116void t_pppClient::putTec(const t_vTec* vTec) {
117 _obsPool->putTec(new t_vTec(*vTec));
118}
119
120//
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
128//
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
136//
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//////////////////////////////////////////////////////////////////////////////
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//////////////////////////////////////////////////////////////////////////////
154t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
155 vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
156
157 // Default
158 // -------
159 epoTime.reset();
160 clearObs();
161
162 // Create vector of valid observations
163 // -----------------------------------
164 for (unsigned ii = 0; ii < satObs.size(); ii++) {
165 char sys = satObs[ii]->_prn.system();
166 if (_opt->useSystem(sys)) {
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
203//
204//////////////////////////////////////////////////////////////////////////////
205bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
206
207 bool pseudoObsIono = false;
208
209 if (_opt->_pseudoObsIono) {
210 vector<t_pppSatObs*>::iterator it = obsVector.begin();
211 while (it != obsVector.end()) {
212 t_pppSatObs* satObs = *it;
213 pseudoObsIono = satObs->setPseudoObsIono(t_frequency::G1);
214 it++;
215 }
216 }
217/*
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*/
225 return pseudoObsIono;
226}
227
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;
236 if (pppSatObs->getCodeBias(pppSatObs->fType1()) &&
237 pppSatObs->getCodeBias(pppSatObs->fType2())) {
238 codeBiasesAvailable = true;
239 }
240 if (codeBiasesAvailable) {
241 ++it;
242 }
243 else {
244 it = obsVector.erase(it);
245 delete pppSatObs;
246 }
247 }
248 return;
249}
250
251
252// Compute the Bancroft position, check for blunders
253//////////////////////////////////////////////////////////////////////////////
254t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
255 vector<t_pppSatObs*>& obsVector,
256 ColumnVector& xyzc, bool print) {
257 t_lc::type tLC = t_lc::dummy;
258 char sysBancroft = 'G';
259 int numBancroft = obsVector.size();
260
261 _usedSystems['G'] = _usedSystems['R'] = _usedSystems['E'] = _usedSystems['C'] = 0;
262 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
263 const t_pppSatObs* satObs = obsVector[jj];
264 char sys = satObs->prn().system();
265 _usedSystems[sys]++;
266 }
267
268 if ((numBancroft = _usedSystems.value('G')) >= _opt->_minObs) {
269 sysBancroft = 'G';
270 }
271 else if ((numBancroft = _usedSystems.value('E')) >= _opt->_minObs) {
272 sysBancroft = 'E';
273 }
274 else if ((numBancroft = _usedSystems.value('C')) >= _opt->_minObs) {
275 sysBancroft = 'C';
276 }
277 else if ((numBancroft = _usedSystems.value('R')) >= _opt->_minObs) {
278 sysBancroft = 'R';
279 }
280 else {
281 LOG << "t_pppClient::cmpBancroft not enough observations: " << endl;
282 return failure;
283 }
284
285 while (_running) {
286 Matrix BB(numBancroft, 4);
287 int iObs = -1;
288 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
289 const t_pppSatObs* satObs = obsVector.at(ii);
290 if (satObs->prn().system() == sysBancroft) {
291 if (tLC == t_lc::dummy) {
292 if (satObs->isValid(t_lc::cIF)) {
293 tLC = t_lc::cIF;
294 }
295 else if (satObs->isValid(t_lc::c1)) {
296 tLC = t_lc::c1;
297 }
298 else if (satObs->isValid(t_lc::c2)) {
299 tLC = t_lc::c2;
300 }
301 }
302 if ( satObs->isValid(tLC) &&
303 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
304 ++iObs;
305 BB[iObs][0] = satObs->xc()[0];
306 BB[iObs][1] = satObs->xc()[1];
307 BB[iObs][2] = satObs->xc()[2];
308 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
309 }
310 }
311 }
312 if (iObs + 1 < _opt->_minObs) {
313 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
314 return failure;
315 }
316 BB = BB.Rows(1,iObs+1);
317 if (bancroft(BB, xyzc) != success) {
318 return failure;
319 }
320
321 xyzc[3] /= t_CST::c;
322
323 // Check Blunders
324 // --------------
325 const double BLUNDER = 100.0;
326 double maxRes = 0.0;
327 unsigned maxResIndex = 0;
328 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
329 const t_pppSatObs* satObs = obsVector.at(ii);
330 char sys = satObs->prn().system();
331 if (satObs->isValid() && sys == sysBancroft &&
332 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
333 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
334 double res = rr.NormFrobenius() - satObs->obsValue(tLC)
335 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
336 if (fabs(res) > maxRes) {
337 maxRes = fabs(res);
338 maxResIndex = ii;
339 }
340 }
341 }
342 if (maxRes < BLUNDER) {
343 if (print) {
344 LOG.setf(ios::fixed);
345 LOG << "\nPPP of Epoch ";
346 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
347 LOG << "\n---------------------------------------------------------------\n";
348 LOG << string(epoTime) << " BANCROFT " << sysBancroft << ": "
349 << setw(14) << setprecision(3) << xyzc[0] << ' '
350 << setw(14) << setprecision(3) << xyzc[1] << ' '
351 << setw(14) << setprecision(3) << xyzc[2] << ' '
352 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
353 }
354 break;
355 }
356 else {
357 t_pppSatObs* satObs = obsVector.at(maxResIndex);
358 LOG << "t_pppClient::cmpBancroft Outlier " << satObs->prn().toString()
359 << " " << maxRes << endl;
360 delete satObs;
361 obsVector.erase(obsVector.begin() + maxResIndex);
362 }
363 }
364
365 return success;
366}
367// Compute A Priori Gps Clock Offset
368//////////////////////////////////////////////////////////////////////////////
369double t_pppClient::cmpOffGps(vector<t_pppSatObs*>& obsVector) {
370
371 t_lc::type tLC = t_lc::dummy;
372 double offGps = 0.0;
373
374 if (_opt->useSystem('G')) {
375 while (obsVector.size() > 0) {
376 offGps = 0.0;
377 double maxRes = 0.0;
378 int maxResIndex = -1;
379 unsigned nObs = 0;
380 t_prn maxResPrn;
381 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
382 const t_pppSatObs* satObs = obsVector.at(ii);
383 if (satObs->prn().system() == 'G') {
384 if (tLC == t_lc::dummy) {
385 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
386 }
387 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
388 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
389 ++nObs;
390 offGps += ll;
391 if (fabs(ll) > fabs(maxRes)) {
392 maxRes = ll;
393 maxResIndex = ii;
394 maxResPrn = satObs->prn();
395 }
396 }
397 }
398 }
399
400 if (nObs > 0) {
401 offGps = offGps / nObs;
402 }
403 else {
404 offGps = 0.0;
405 }
406
407 if (fabs(maxRes) > 100.0) {
408 LOG << "t_pppClient::cmpOffGps outlier " << maxResPrn.toString() << " " << maxRes << endl;
409 delete obsVector.at(maxResIndex);
410 obsVector.erase(obsVector.begin() + maxResIndex);
411 }
412 else {
413 break;
414 }
415 }
416 }
417 return offGps;
418}
419
420// Compute A Priori Glonass Clock Offset
421//////////////////////////////////////////////////////////////////////////////
422double t_pppClient::cmpOffGlo(vector<t_pppSatObs*>& obsVector) {
423
424 t_lc::type tLC = t_lc::dummy;
425 double offGlo = 0.0;
426
427 if (_opt->useSystem('R')) {
428 while (obsVector.size() > 0) {
429 offGlo = 0.0;
430 double maxRes = 0.0;
431 int maxResIndex = -1;
432 unsigned nObs = 0;
433 t_prn maxResPrn;
434 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
435 const t_pppSatObs* satObs = obsVector.at(ii);
436 if (satObs->prn().system() == 'R') {
437 if (tLC == t_lc::dummy) {
438 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
439 }
440 if (satObs->isValid(tLC) &&
441 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
442 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
443 ++nObs;
444 offGlo += ll;
445 if (fabs(ll) > fabs(maxRes)) {
446 maxRes = ll;
447 maxResIndex = ii;
448 maxResPrn = satObs->prn();
449 }
450 }
451 }
452 }
453
454 if (nObs > 0) {
455 offGlo = offGlo / nObs;
456 }
457 else {
458 offGlo = 0.0;
459 }
460 if (fabs(maxRes) > 100.0) {
461 LOG << "t_pppClient::cmpOffGlo outlier " << maxResPrn.toString() << " " << maxRes << endl;
462 delete obsVector.at(maxResIndex);
463 obsVector.erase(obsVector.begin() + maxResIndex);
464 }
465 else {
466 break;
467 }
468 }
469 }
470 return offGlo;
471}
472
473// Compute A Priori Galileo Clock Offset
474//////////////////////////////////////////////////////////////////////////////
475double t_pppClient::cmpOffGal(vector<t_pppSatObs*>& obsVector) {
476
477 t_lc::type tLC = t_lc::dummy;
478 double offGal = 0.0;
479
480 if (_opt->useSystem('E')) {
481 while (obsVector.size() > 0) {
482 offGal = 0.0;
483 double maxRes = 0.0;
484 int maxResIndex = -1;
485 unsigned nObs = 0;
486 t_prn maxResPrn;
487 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
488 const t_pppSatObs* satObs = obsVector.at(ii);
489 if (satObs->prn().system() == 'E') {
490 if (tLC == t_lc::dummy) {
491 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
492 }
493 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
494 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
495 ++nObs;
496 offGal += ll;
497 if (fabs(ll) > fabs(maxRes)) {
498 maxRes = ll;
499 maxResIndex = ii;
500 maxResPrn = satObs->prn();
501 }
502 }
503 }
504 }
505
506 if (nObs > 0) {
507 offGal = offGal / nObs;
508 }
509 else {
510 offGal = 0.0;
511 }
512
513 if (fabs(maxRes) > 100.0) {
514 LOG << "t_pppClient::cmpOffGal outlier " << maxResPrn.toString() << " " << maxRes << endl;
515 delete obsVector.at(maxResIndex);
516 obsVector.erase(obsVector.begin() + maxResIndex);
517 }
518 else {
519 break;
520 }
521 }
522 }
523 return offGal;
524}
525
526// Compute A Priori BDS Clock Offset
527//////////////////////////////////////////////////////////////////////////////
528double t_pppClient::cmpOffBds(vector<t_pppSatObs*>& obsVector) {
529
530 t_lc::type tLC = t_lc::dummy;
531 double offBds = 0.0;
532
533 if (_opt->useSystem('C')) {
534 while (obsVector.size() > 0) {
535 offBds = 0.0;
536 double maxRes = 0.0;
537 int maxResIndex = -1;
538 unsigned nObs = 0;
539 t_prn maxResPrn;
540 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
541 const t_pppSatObs* satObs = obsVector.at(ii);
542 if (satObs->prn().system() == 'C') {
543 if (tLC == t_lc::dummy) {
544 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
545 }
546 if (satObs->isValid(tLC) &&
547 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
548 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
549 ++nObs;
550 offBds += ll;
551 if (fabs(ll) > fabs(maxRes)) {
552 maxRes = ll;
553 maxResIndex = ii;
554 maxResPrn = satObs->prn();
555 }
556 }
557 }
558 }
559
560 if (nObs > 0) {
561 offBds = offBds / nObs;
562 }
563 else {
564 offBds = 0.0;
565 }
566
567 if (fabs(maxRes) > 100.0) {
568 LOG << "t_pppClient::cmpOffBDS outlier " << maxResPrn.toString() << " " << maxRes << endl;
569 delete obsVector.at(maxResIndex);
570 obsVector.erase(obsVector.begin() + maxResIndex);
571 }
572 else {
573 break;
574 }
575 }
576 }
577 return offBds;
578}
579
580//
581//////////////////////////////////////////////////////////////////////////////
582void t_pppClient::initOutput(t_output* output) {
583 _output = output;
584 _output->_numSat = 0;
585 _output->_hDop = 0.0;
586 _output->_error = false;
587}
588
589//
590//////////////////////////////////////////////////////////////////////////////
591void t_pppClient::clearObs() {
592 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
593 delete _obsRover.at(ii);
594 }
595 _obsRover.clear();
596}
597
598//
599//////////////////////////////////////////////////////////////////////////////
600void t_pppClient::finish(t_irc irc, int ind) {
601#ifdef BNC_DEBUG_PPP
602 LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
603#endif
604
605 clearObs();
606
607 _output->_epoTime = _epoTimeRover;
608
609 if (irc == success) {
610 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
611 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
612 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
613
614 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
615
616 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
617
618 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
619 _output->_trp = _filter->trp();
620 _output->_trpStdev = _filter->trpStdev();
621
622 _output->_numSat = _filter->numSat();
623 _output->_hDop = _filter->HDOP();
624 _output->_error = false;
625 }
626 else {
627 _output->_error = true;
628 }
629
630 _output->_log = _log->str();
631 delete _log; _log = new ostringstream();
632
633 return;
634}
635
636//
637//////////////////////////////////////////////////////////////////////////////
638t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
639 vector<t_pppSatObs*>& obsVector) {
640 bncTime time;
641 time = _epoTimeRover;
642 station->setName(_opt->_roverName);
643 station->setAntName(_opt->_antNameRover);
644 station->setEpochTime(time);
645
646 if (_opt->xyzAprRoverSet()) {
647 station->setXyzApr(_opt->_xyzAprRover);
648 }
649 else {
650 station->setXyzApr(xyzc.Rows(1,3));
651 }
652 station->setNeuEcc(_opt->_neuEccRover);
653
654 // Receiver Clock
655 // --------------
656 station->setDClk(xyzc[3]);
657
658 // Tides
659 // -----
660 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
661 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
662
663 // Observation model
664 // -----------------
665 vector<t_pppSatObs*>::iterator it = obsVector.begin();
666 while (it != obsVector.end()) {
667 t_pppSatObs* satObs = *it;
668 t_irc modelSetup;
669 if (satObs->isValid()) {
670 modelSetup = satObs->cmpModel(station);
671 }
672 if (satObs->isValid() &&
673 satObs->eleSat() >= _opt->_minEle &&
674 modelSetup == success) {
675 ++it;
676 }
677 else {
678 delete satObs;
679 it = obsVector.erase(it);
680 }
681 }
682
683 return success;
684}
685
686//
687//////////////////////////////////////////////////////////////////////////////
688void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
689
690 try {
691 initOutput(output);
692
693 // Prepare Observations of the Rover
694 // ---------------------------------
695 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
696 return finish(failure, 1);
697 }
698
699 for (int iter = 1; iter <= 2; iter++) {
700 ColumnVector xyzc(4); xyzc = 0.0;
701 bool print = (iter == 2);
702 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
703 return finish(failure, 2);
704 }
705 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
706 return finish(failure, 3);
707 }
708 }
709 // use observations only if satellite code biases are available
710 /* ------------------------------------------------------------
711 if (!_opt->_corrMount.empty() {
712 useObsWithCodeBiasesOnly(_obsRover);
713 }*/
714
715 if (int(_obsRover.size()) < _opt->_minObs) {
716 LOG << "t_pppClient::processEpoch not enough observations" << endl;
717 return finish(failure, 4);
718 }
719
720 _offGps = cmpOffGps(_obsRover);
721 _offGlo = cmpOffGlo(_obsRover);
722 _offGal = cmpOffGal(_obsRover);
723 _offBds = cmpOffBds(_obsRover);
724
725 // Prepare Pseudo Observations of the Rover
726 // ----------------------------------------
727 _pseudoObsIono = preparePseudoObs(_obsRover);
728
729 // Store last epoch of data
730 // ------------------------
731 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
732
733 // Process Epoch in Filter
734 // -----------------------
735 if (_filter->processEpoch(_obsPool) != success) {
736 LOG << "t_pppFilter::processEpoch() != success" << endl;
737 return finish(failure, 5);
738 }
739 }
740 catch (Exception& exc) {
741 LOG << exc.what() << endl;
742 return finish(failure, 6);
743 }
744 catch (t_except msg) {
745 LOG << msg.what() << endl;
746 return finish(failure, 7);
747 }
748 catch (const char* msg) {
749 LOG << msg << endl;
750 return finish(failure, 8);
751 }
752 catch (...) {
753 LOG << "unknown exception" << endl;
754 return finish(failure, 9);
755 }
756 return finish(success, 0);
757}
758
759//
760////////////////////////////////////////////////////////////////////////////
761double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
762 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
763}
764
765//
766////////////////////////////////////////////////////////////////////////////
767t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
768
769 if (pos.Nrows() != 4) {
770 pos.ReSize(4);
771 }
772 pos = 0.0;
773
774 for (int iter = 1; iter <= 2; iter++) {
775 Matrix BB = BBpass;
776 int mm = BB.Nrows();
777 for (int ii = 1; ii <= mm; ii++) {
778 double xx = BB(ii,1);
779 double yy = BB(ii,2);
780 double traveltime = 0.072;
781 if (iter > 1) {
782 double zz = BB(ii,3);
783 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
784 (yy-pos(2)) * (yy-pos(2)) +
785 (zz-pos(3)) * (zz-pos(3)) );
786 traveltime = rho / t_CST::c;
787 }
788 double angle = traveltime * t_CST::omega;
789 double cosa = cos(angle);
790 double sina = sin(angle);
791 BB(ii,1) = cosa * xx + sina * yy;
792 BB(ii,2) = -sina * xx + cosa * yy;
793 }
794
795 Matrix BBB;
796 if (mm > 4) {
797 SymmetricMatrix hlp; hlp << BB.t() * BB;
798 BBB = hlp.i() * BB.t();
799 }
800 else {
801 BBB = BB.i();
802 }
803 ColumnVector ee(mm); ee = 1.0;
804 ColumnVector alpha(mm); alpha = 0.0;
805 for (int ii = 1; ii <= mm; ii++) {
806 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
807 }
808 ColumnVector BBBe = BBB * ee;
809 ColumnVector BBBalpha = BBB * alpha;
810 double aa = lorentz(BBBe, BBBe);
811 double bb = lorentz(BBBe, BBBalpha)-1;
812 double cc = lorentz(BBBalpha, BBBalpha);
813 double root = sqrt(bb*bb-aa*cc);
814
815 Matrix hlpPos(4,2);
816 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
817 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
818
819 ColumnVector omc(2);
820 for (int pp = 1; pp <= 2; pp++) {
821 hlpPos(4,pp) = -hlpPos(4,pp);
822 omc(pp) = BB(1,4) -
823 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
824 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
825 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
826 hlpPos(4,pp);
827 }
828 if ( fabs(omc(1)) > fabs(omc(2)) ) {
829 pos = hlpPos.Column(2);
830 }
831 else {
832 pos = hlpPos.Column(1);
833 }
834 }
835 if (pos.size() != 4 ||
836 std::isnan(pos(1)) ||
837 std::isnan(pos(2)) ||
838 std::isnan(pos(3)) ||
839 std::isnan(pos(4))) {
840 return failure;
841 }
842
843 return success;
844}
845
846//
847//////////////////////////////////////////////////////////////////////////////
848void t_pppClient::reset() {
849
850 // to delete old orbit and clock corrections
851 delete _ephPool;
852 _ephPool = new t_pppEphPool();
853
854 // to delete old code biases
855 delete _obsPool;
856 _obsPool = new t_pppObsPool();
857
858 // to delete all parameters
859 delete _filter;
860 _filter = new t_pppFilter();
861
862}
Note: See TracBrowser for help on using the repository browser.