source: ntrip/trunk/BNC/bncmodel.cpp@ 3378

Last change on this file since 3378 was 3378, checked in by mervart, 13 years ago
File size: 46.3 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncParam, bncModel
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <cmath>
43#include <newmatio.h>
44#include <sstream>
45
46#include "bncmodel.h"
47#include "bncapp.h"
48#include "bncpppclient.h"
49#include "bancroft.h"
50#include "bncutils.h"
51#include "bncsettings.h"
52#include "bnctides.h"
53#include "bncantex.h"
54#include "bnccomb.h"
55
56using namespace std;
57
58const unsigned MINOBS = 5;
59const double MINELE_GPS = 10.0 * M_PI / 180.0;
60const double MINELE_GLO = 10.0 * M_PI / 180.0;
61const double MINELE_GAL = 10.0 * M_PI / 180.0;
62const double MAXRES_CODE_GPS = 10.0;
63const double MAXRES_PHASE_GPS = 0.04;
64const double MAXRES_PHASE_GLO = 0.04;
65const double MAXRES_CODE_GAL = 10.0;
66const double MAXRES_PHASE_GAL = 0.04;
67
68// Constructor
69////////////////////////////////////////////////////////////////////////////
70bncParam::bncParam(bncParam::parType typeIn, int indexIn,
71 const QString& prnIn) {
72 type = typeIn;
73 index = indexIn;
74 prn = prnIn;
75 index_old = 0;
76 xx = 0.0;
77 numEpo = 0;
78}
79
80// Destructor
81////////////////////////////////////////////////////////////////////////////
82bncParam::~bncParam() {
83}
84
85// Partial
86////////////////////////////////////////////////////////////////////////////
87double bncParam::partial(t_satData* satData, bool phase) {
88
89 Tracer tracer("bncParam::partial");
90
91 // Coordinates
92 // -----------
93 if (type == CRD_X) {
94 return (xx - satData->xx(1)) / satData->rho;
95 }
96 else if (type == CRD_Y) {
97 return (xx - satData->xx(2)) / satData->rho;
98 }
99 else if (type == CRD_Z) {
100 return (xx - satData->xx(3)) / satData->rho;
101 }
102
103 // Receiver Clocks
104 // ---------------
105 else if (type == RECCLK) {
106 return 1.0;
107 }
108
109 // Troposphere
110 // -----------
111 else if (type == TROPO) {
112 return 1.0 / sin(satData->eleSat);
113 }
114
115 // Galileo Offset
116 // --------------
117 else if (type == GALILEO_OFFSET) {
118 if (satData->prn[0] == 'E') {
119 return 1.0;
120 }
121 else {
122 return 0.0;
123 }
124 }
125
126 // Ambiguities
127 // -----------
128 else if (type == AMB_L3) {
129 if (phase && satData->prn == prn) {
130 return 1.0;
131 }
132 else {
133 return 0.0;
134 }
135 }
136
137 // Default return
138 // --------------
139 return 0.0;
140}
141
142// Constructor
143////////////////////////////////////////////////////////////////////////////
144bncModel::bncModel(QByteArray staID) {
145
146 _staID = staID;
147
148 connect(this, SIGNAL(newMessage(QByteArray,bool)),
149 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
150
151 bncSettings settings;
152
153 // Observation Sigmas
154 // ------------------
155 _sigP3 = 5.0;
156 if (!settings.value("pppSigmaCode").toString().isEmpty()) {
157 _sigP3 = settings.value("pppSigmaCode").toDouble();
158 }
159 _sigL3 = 0.02;
160 if (!settings.value("pppSigmaPhase").toString().isEmpty()) {
161 _sigL3 = settings.value("pppSigmaPhase").toDouble();
162 }
163
164 // Parameter Sigmas
165 // ----------------
166 _sigCrd0 = 100.0;
167 if (!settings.value("pppSigCrd0").toString().isEmpty()) {
168 _sigCrd0 = settings.value("pppSigCrd0").toDouble();
169 }
170 _sigCrdP = 100.0;
171 if (!settings.value("pppSigCrdP").toString().isEmpty()) {
172 _sigCrdP = settings.value("pppSigCrdP").toDouble();
173 }
174 _sigTrp0 = 0.1;
175 if (!settings.value("pppSigTrp0").toString().isEmpty()) {
176 _sigTrp0 = settings.value("pppSigTrp0").toDouble();
177 }
178 _sigTrpP = 1e-6;
179 if (!settings.value("pppSigTrpP").toString().isEmpty()) {
180 _sigTrpP = settings.value("pppSigTrpP").toDouble();
181 }
182 _sigClk0 = 1000.0;
183 _sigAmb0 = 1000.0;
184 _sigGalileoOffset0 = 1000.0;
185 _sigGalileoOffsetP = 0.0;
186
187 // Quick-Start Mode
188 // ----------------
189 _quickStart = 0;
190 if (settings.value("pppRefCrdX").toString() != "" &&
191 settings.value("pppRefCrdY").toString() != "" &&
192 settings.value("pppRefCrdZ").toString() != "" &&
193 !settings.value("pppQuickStart").toString().isEmpty()) {
194 _quickStart = settings.value("pppQuickStart").toDouble();
195 }
196
197 // Several options
198 // ---------------
199 _usePhase = false;
200 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
201 _usePhase = true;
202 }
203
204 _estTropo = false;
205 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
206 _estTropo = true;
207 }
208
209 _useGalileo = false;
210 if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
211 _useGalileo = true;
212 }
213
214 // NMEA Output
215 // -----------
216 QString nmeaFileName = settings.value("nmeaFile").toString();
217 if (nmeaFileName.isEmpty()) {
218 _nmeaFile = 0;
219 _nmeaStream = 0;
220 }
221 else {
222 expandEnvVar(nmeaFileName);
223 _nmeaFile = new QFile(nmeaFileName);
224 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
225 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
226 }
227 else {
228 _nmeaFile->open(QIODevice::WriteOnly);
229 }
230 _nmeaStream = new QTextStream();
231 _nmeaStream->setDevice(_nmeaFile);
232 }
233
234 // Antenna Name, ANTEX File
235 // ------------------------
236 _antex = 0;
237 QString antexFileName = settings.value("pppAntex").toString();
238 if (!antexFileName.isEmpty()) {
239 _antex = new bncAntex();
240 if (_antex->readFile(antexFileName) != success) {
241 emit newMessage("wrong ANTEX file", true);
242 delete _antex;
243 _antex = 0;
244 }
245 else {
246 _antennaName = settings.value("pppAntenna").toString();
247 }
248 }
249
250 // Antenna Eccentricities
251 // ----------------------
252 _dN = settings.value("pppRefdN").toDouble();
253 _dE = settings.value("pppRefdE").toDouble();
254 _dU = settings.value("pppRefdU").toDouble();
255
256 // Bancroft Coordinates
257 // --------------------
258 _xcBanc.ReSize(4); _xcBanc = 0.0;
259 _ellBanc.ReSize(3); _ellBanc = 0.0;
260
261 // Save for Outlier Detection
262 // --------------------------
263 _epoData_sav = 0;
264}
265
266// Destructor
267////////////////////////////////////////////////////////////////////////////
268bncModel::~bncModel() {
269 delete _nmeaStream;
270 delete _nmeaFile;
271 for (int ii = 0; ii < _posAverage.size(); ++ii) {
272 delete _posAverage[ii];
273 }
274 delete _antex;
275 for (int iPar = 1; iPar <= _params.size(); iPar++) {
276 delete _params[iPar-1];
277 }
278}
279
280// Reset Parameters and Variance-Covariance Matrix
281////////////////////////////////////////////////////////////////////////////
282void bncModel::reset() {
283
284 Tracer tracer("bncModel::reset");
285
286 for (int iPar = 1; iPar <= _params.size(); iPar++) {
287 delete _params[iPar-1];
288 }
289 _params.clear();
290
291 int nextPar = 0;
292 _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
293 _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
294 _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
295 _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
296 if (_estTropo) {
297 _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
298 }
299 if (_useGalileo) {
300 _params.push_back(new bncParam(bncParam::GALILEO_OFFSET, ++nextPar, ""));
301 }
302
303 _QQ.ReSize(_params.size());
304 _QQ = 0.0;
305 for (int iPar = 1; iPar <= _params.size(); iPar++) {
306 bncParam* pp = _params[iPar-1];
307 pp->xx = 0.0;
308 if (pp->isCrd()) {
309 _QQ(iPar,iPar) = _sigCrd0 * _sigCrd0;
310 }
311 else if (pp->type == bncParam::RECCLK) {
312 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
313 }
314 else if (pp->type == bncParam::TROPO) {
315 _QQ(iPar,iPar) = _sigTrp0 * _sigTrp0;
316 }
317 else if (pp->type == bncParam::GALILEO_OFFSET) {
318 _QQ(iPar,iPar) = _sigGalileoOffset0 * _sigGalileoOffset0;
319 }
320 }
321}
322
323// Bancroft Solution
324////////////////////////////////////////////////////////////////////////////
325t_irc bncModel::cmpBancroft(t_epoData* epoData) {
326
327 Tracer tracer("bncModel::cmpBancroft");
328
329 if (epoData->sizeGPS() < MINOBS) {
330 _log += "bncModel::cmpBancroft: not enough data\n";
331 return failure;
332 }
333
334 Matrix BB(epoData->sizeGPS(), 4);
335
336 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
337 int iObsBanc = 0;
338 while (it.hasNext()) {
339 ++iObsBanc;
340 it.next();
341 QString prn = it.key();
342 t_satData* satData = it.value();
343 BB(iObsBanc, 1) = satData->xx(1);
344 BB(iObsBanc, 2) = satData->xx(2);
345 BB(iObsBanc, 3) = satData->xx(3);
346 BB(iObsBanc, 4) = satData->P3 + satData->clk;
347 }
348
349 bancroft(BB, _xcBanc);
350
351 // Ellipsoidal Coordinates
352 // ------------------------
353 xyz2ell(_xcBanc.data(), _ellBanc.data());
354
355 // Compute Satellite Elevations
356 // ----------------------------
357 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
358 while (iGPS.hasNext()) {
359 iGPS.next();
360 t_satData* satData = iGPS.value();
361 cmpEle(satData);
362 if (satData->eleSat < MINELE_GPS) {
363 delete satData;
364 iGPS.remove();
365 }
366 }
367
368 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
369 while (iGlo.hasNext()) {
370 iGlo.next();
371 t_satData* satData = iGlo.value();
372 cmpEle(satData);
373 if (satData->eleSat < MINELE_GLO) {
374 delete satData;
375 iGlo.remove();
376 }
377 }
378
379 QMutableMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
380 while (iGal.hasNext()) {
381 iGal.next();
382 t_satData* satData = iGal.value();
383 cmpEle(satData);
384 if (satData->eleSat < MINELE_GAL) {
385 delete satData;
386 iGal.remove();
387 }
388 }
389
390 return success;
391}
392
393// Computed Value
394////////////////////////////////////////////////////////////////////////////
395double bncModel::cmpValue(t_satData* satData, bool phase) {
396
397 Tracer tracer("bncModel::cmpValue");
398
399 ColumnVector xRec(3);
400 xRec(1) = x();
401 xRec(2) = y();
402 xRec(3) = z();
403
404 double rho0 = (satData->xx - xRec).norm_Frobenius();
405 double dPhi = t_CST::omega * rho0 / t_CST::c;
406
407 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
408 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
409 xRec(3) = z();
410
411 tides(_time, xRec);
412
413 satData->rho = (satData->xx - xRec).norm_Frobenius();
414
415 double tropDelay = delay_saast(satData->eleSat) +
416 trp() / sin(satData->eleSat);
417
418 double wind = 0.0;
419 if (phase) {
420 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
421 }
422
423 double offset = 0.0;
424 if (satData->prn[0] == 'E') {
425 offset = Galileo_offset();
426 }
427
428 double phaseCenter = 0.0;
429 if (_antex) {
430 bool found;
431 phaseCenter = _antex->pco(_antennaName, satData->eleSat, found);
432 if (!found) {
433 emit newMessage("ANTEX: antenna >"
434 + _antennaName.toAscii() + "< not found", true);
435 }
436 }
437
438 double antennaOffset = 0.0;
439 if (_dN != 0.0 || _dE != 0.0 || _dU != 0.0) {
440 double cosa = cos(satData->azSat);
441 double sina = sin(satData->azSat);
442 double cose = cos(satData->eleSat);
443 double sine = sin(satData->eleSat);
444 antennaOffset = -_dN * cosa*cose - _dE * sina*cose - _dU * sine;
445 }
446
447 return satData->rho + phaseCenter + antennaOffset + clk()
448 + offset - satData->clk + tropDelay + wind;
449}
450
451// Tropospheric Model (Saastamoinen)
452////////////////////////////////////////////////////////////////////////////
453double bncModel::delay_saast(double Ele) {
454
455 Tracer tracer("bncModel::delay_saast");
456
457 double xyz[3];
458 xyz[0] = x();
459 xyz[1] = y();
460 xyz[2] = z();
461 double ell[3];
462 xyz2ell(xyz, ell);
463 double height = ell[2];
464
465 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
466 double TT = 18.0 - height * 0.0065 + 273.15;
467 double hh = 50.0 * exp(-6.396e-4 * height);
468 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
469
470 double h_km = height / 1000.0;
471
472 if (h_km < 0.0) h_km = 0.0;
473 if (h_km > 5.0) h_km = 5.0;
474 int ii = int(h_km + 1);
475 double href = ii - 1;
476
477 double bCor[6];
478 bCor[0] = 1.156;
479 bCor[1] = 1.006;
480 bCor[2] = 0.874;
481 bCor[3] = 0.757;
482 bCor[4] = 0.654;
483 bCor[5] = 0.563;
484
485 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
486
487 double zen = M_PI/2.0 - Ele;
488
489 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
490}
491
492// Prediction Step of the Filter
493////////////////////////////////////////////////////////////////////////////
494void bncModel::predict(int iPhase, t_epoData* epoData) {
495
496 Tracer tracer("bncModel::predict");
497
498 if (iPhase == 0) {
499
500 bncSettings settings;
501
502 _time = epoData->tt; // current epoch time
503
504 _maxSolGap = settings.value("pppMaxSolGap").toDouble();
505
506 bool firstCrd = false;
507 if (!_lastTimeOK.valid() || (_maxSolGap > 0 && _time - _lastTimeOK > _maxSolGap)) {
508 firstCrd = true;
509 _startTime = epoData->tt;
510 reset();
511 }
512
513 // Use different white noise for Quick-Start mode
514 // ----------------------------------------------
515 double sigCrdP_used = _sigCrdP;
516 if ( _quickStart > 0.0 && _quickStart > (epoData->tt - _startTime) ) {
517 sigCrdP_used = 0.0;
518 }
519
520 // Predict Parameter values, add white noise
521 // -----------------------------------------
522 for (int iPar = 1; iPar <= _params.size(); iPar++) {
523 bncParam* pp = _params[iPar-1];
524
525 // Coordinates
526 // -----------
527 if (pp->type == bncParam::CRD_X) {
528 if (firstCrd) {
529 if (settings.value("pppRefCrdX").toString() != "" &&
530 settings.value("pppRefCrdY").toString() != "" &&
531 settings.value("pppRefCrdZ").toString() != "") {
532 pp->xx = settings.value("pppRefCrdX").toDouble();
533 }
534 else {
535 pp->xx = _xcBanc(1);
536 }
537 }
538 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
539 }
540 else if (pp->type == bncParam::CRD_Y) {
541 if (firstCrd) {
542 if (settings.value("pppRefCrdX").toString() != "" &&
543 settings.value("pppRefCrdY").toString() != "" &&
544 settings.value("pppRefCrdZ").toString() != "") {
545 pp->xx = settings.value("pppRefCrdY").toDouble();
546 }
547 else {
548 pp->xx = _xcBanc(2);
549 }
550 }
551 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
552 }
553 else if (pp->type == bncParam::CRD_Z) {
554 if (firstCrd) {
555 if (settings.value("pppRefCrdX").toString() != "" &&
556 settings.value("pppRefCrdY").toString() != "" &&
557 settings.value("pppRefCrdZ").toString() != "") {
558 pp->xx = settings.value("pppRefCrdZ").toDouble();
559 }
560 else {
561 pp->xx = _xcBanc(3);
562 }
563 }
564 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
565 }
566
567 // Receiver Clocks
568 // ---------------
569 else if (pp->type == bncParam::RECCLK) {
570 pp->xx = _xcBanc(4);
571 for (int jj = 1; jj <= _params.size(); jj++) {
572 _QQ(iPar, jj) = 0.0;
573 }
574 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
575 }
576
577 // Tropospheric Delay
578 // ------------------
579 else if (pp->type == bncParam::TROPO) {
580 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
581 }
582
583 // Galileo Offset
584 // --------------
585 else if (pp->type == bncParam::GALILEO_OFFSET) {
586 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
587 }
588 }
589 }
590
591 // Add New Ambiguities if necessary
592 // --------------------------------
593 if (_usePhase) {
594
595 // Make a copy of QQ and xx, set parameter indices
596 // -----------------------------------------------
597 SymmetricMatrix QQ_old = _QQ;
598
599 for (int iPar = 1; iPar <= _params.size(); iPar++) {
600 _params[iPar-1]->index_old = _params[iPar-1]->index;
601 _params[iPar-1]->index = 0;
602 }
603
604 // Remove Ambiguity Parameters without observations
605 // ------------------------------------------------
606 int iPar = 0;
607 QMutableVectorIterator<bncParam*> it(_params);
608 while (it.hasNext()) {
609 bncParam* par = it.next();
610 bool removed = false;
611 if (par->type == bncParam::AMB_L3) {
612 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
613 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() &&
614 epoData->satDataGal.find(par->prn) == epoData->satDataGal.end() ) {
615 removed = true;
616 delete par;
617 it.remove();
618 }
619 }
620 if (! removed) {
621 ++iPar;
622 par->index = iPar;
623 }
624 }
625
626 // Add new ambiguity parameters
627 // ----------------------------
628 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
629 while (iGPS.hasNext()) {
630 iGPS.next();
631 t_satData* satData = iGPS.value();
632 addAmb(satData);
633 }
634
635 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
636 while (iGlo.hasNext()) {
637 iGlo.next();
638 t_satData* satData = iGlo.value();
639 addAmb(satData);
640 }
641
642 QMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
643 while (iGal.hasNext()) {
644 iGal.next();
645 t_satData* satData = iGal.value();
646 addAmb(satData);
647 }
648
649 int nPar = _params.size();
650 _QQ.ReSize(nPar); _QQ = 0.0;
651 for (int i1 = 1; i1 <= nPar; i1++) {
652 bncParam* p1 = _params[i1-1];
653 if (p1->index_old != 0) {
654 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
655 for (int i2 = 1; i2 <= nPar; i2++) {
656 bncParam* p2 = _params[i2-1];
657 if (p2->index_old != 0) {
658 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
659 }
660 }
661 }
662 }
663
664 for (int ii = 1; ii <= nPar; ii++) {
665 bncParam* par = _params[ii-1];
666 if (par->index_old == 0) {
667 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
668 }
669 par->index_old = par->index;
670 }
671 }
672}
673
674// Update Step of the Filter (currently just a single-epoch solution)
675////////////////////////////////////////////////////////////////////////////
676t_irc bncModel::update(t_epoData* epoData) {
677
678 Tracer tracer("bncModel::update");
679
680 bncSettings settings;
681
682 _log.clear();
683
684 if (settings.value("pppSPP").toString() == "PPP") {
685 _log += "Precise Point Positioning of Epoch "
686 + QByteArray(_time.timestr(1).c_str()) +
687 "\n---------------------------------------------------------------\n";
688 }
689 else {
690 _log += "Single Point Positioning of Epoch "
691 + QByteArray(_time.timestr(1).c_str()) +
692 "\n--------------------------------------------------------------\n";
693 }
694
695 // Outlier Detection Loop
696 // ----------------------
697 if (update_p(epoData) != success) {
698 emit newMessage(_log, false);
699 return failure;
700 }
701
702 // Remember the Epoch-specific Results for the computation of means
703 // ----------------------------------------------------------------
704 pppPos* newPos = new pppPos;
705 newPos->time = epoData->tt;
706
707 // Set Solution Vector
708 // -------------------
709 ostringstream strB;
710 strB.setf(ios::fixed);
711 QVectorIterator<bncParam*> itPar(_params);
712 while (itPar.hasNext()) {
713 bncParam* par = itPar.next();
714
715 if (par->type == bncParam::RECCLK) {
716 strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
717 << " +- " << setw(6) << setprecision(3)
718 << sqrt(_QQ(par->index,par->index));
719 }
720 else if (par->type == bncParam::AMB_L3) {
721 ++par->numEpo;
722 strB << "\n amb " << par->prn.toAscii().data() << " = "
723 << setw(10) << setprecision(3) << par->xx
724 << " +- " << setw(6) << setprecision(3)
725 << sqrt(_QQ(par->index,par->index))
726 << " nEpo = " << par->numEpo;
727 }
728 else if (par->type == bncParam::TROPO) {
729 double aprTrp = delay_saast(M_PI/2.0);
730 strB << "\n trp = " << par->prn.toAscii().data()
731 << setw(7) << setprecision(3) << aprTrp << " "
732 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
733 << " +- " << setw(6) << setprecision(3)
734 << sqrt(_QQ(par->index,par->index));
735 newPos->xnt[6] = aprTrp + par->xx;
736 }
737 else if (par->type == bncParam::GALILEO_OFFSET) {
738 strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
739 << " +- " << setw(6) << setprecision(3)
740 << sqrt(_QQ(par->index,par->index));
741 }
742 }
743 strB << '\n';
744 _log += strB.str().c_str();
745 emit newMessage(_log, false);
746
747 // Final Message (both log file and screen)
748 // ----------------------------------------
749 ostringstream strC;
750 strC.setf(ios::fixed);
751 strC << _staID.data() << " PPP "
752 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
753 << setw(14) << setprecision(3) << x() << " +- "
754 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
755 << setw(14) << setprecision(3) << y() << " +- "
756 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
757 << setw(14) << setprecision(3) << z() << " +- "
758 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
759
760 // NEU Output
761 // ----------
762 double xyzRef[3];
763
764 if (settings.value("pppRefCrdX").toString() != "" &&
765 settings.value("pppRefCrdY").toString() != "" &&
766 settings.value("pppRefCrdZ").toString() != "") {
767
768 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
769 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
770 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
771
772 newPos->xnt[0] = x() - xyzRef[0];
773 newPos->xnt[1] = y() - xyzRef[1];
774 newPos->xnt[2] = z() - xyzRef[2];
775
776 double ellRef[3];
777 xyz2ell(xyzRef, ellRef);
778 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
779
780 strC << " NEU "
781 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
782 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
783 << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
784
785 }
786
787 emit newMessage(QByteArray(strC.str().c_str()), true);
788
789 if (settings.value("pppAverage").toString() == "") {
790 delete newPos;
791 }
792 else {
793
794 _posAverage.push_back(newPos);
795
796 // Time Span for Average Computation
797 // ---------------------------------
798 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
799 if (tRangeAverage < 0) {
800 tRangeAverage = 0;
801 }
802 if (tRangeAverage > 86400) {
803 tRangeAverage = 86400;
804 }
805
806 // Compute the Mean
807 // ----------------
808 ColumnVector mean(7); mean = 0.0;
809
810 QMutableVectorIterator<pppPos*> it(_posAverage);
811 while (it.hasNext()) {
812 pppPos* pp = it.next();
813 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
814 delete pp;
815 it.remove();
816 }
817 else {
818 for (int ii = 0; ii < 7; ++ii) {
819 mean[ii] += pp->xnt[ii];
820 }
821 }
822 }
823
824 int nn = _posAverage.size();
825
826 if (nn > 0) {
827
828 mean /= nn;
829
830 // Compute the Deviation
831 // ---------------------
832 ColumnVector std(7); std = 0.0;
833 QVectorIterator<pppPos*> it2(_posAverage);
834 while (it2.hasNext()) {
835 pppPos* pp = it2.next();
836 for (int ii = 0; ii < 7; ++ii) {
837 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
838 }
839 }
840 for (int ii = 0; ii < 7; ++ii) {
841 std[ii] = sqrt(std[ii] / nn);
842 }
843
844 if (settings.value("pppRefCrdX").toString() != "" &&
845 settings.value("pppRefCrdY").toString() != "" &&
846 settings.value("pppRefCrdZ").toString() != "") {
847
848 ostringstream strD; strD.setf(ios::fixed);
849 strD << _staID.data() << " AVE-XYZ "
850 << epoData->tt.timestr(1) << " "
851 << setw(13) << setprecision(3) << mean[0] + xyzRef[0] << " +- "
852 << setw(6) << setprecision(3) << std[0] << " "
853 << setw(14) << setprecision(3) << mean[1] + xyzRef[1] << " +- "
854 << setw(6) << setprecision(3) << std[1] << " "
855 << setw(14) << setprecision(3) << mean[2] + xyzRef[2] << " +- "
856 << setw(6) << setprecision(3) << std[2];
857 emit newMessage(QByteArray(strD.str().c_str()), true);
858
859 ostringstream strE; strE.setf(ios::fixed);
860 strE << _staID.data() << " AVE-NEU "
861 << epoData->tt.timestr(1) << " "
862 << setw(13) << setprecision(3) << mean[3] << " +- "
863 << setw(6) << setprecision(3) << std[3] << " "
864 << setw(14) << setprecision(3) << mean[4] << " +- "
865 << setw(6) << setprecision(3) << std[4] << " "
866 << setw(14) << setprecision(3) << mean[5] << " +- "
867 << setw(6) << setprecision(3) << std[5];
868 emit newMessage(QByteArray(strE.str().c_str()), true);
869
870 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
871 ostringstream strF; strF.setf(ios::fixed);
872 strF << _staID.data() << " AVE-TRP "
873 << epoData->tt.timestr(1) << " "
874 << setw(13) << setprecision(3) << mean[6] << " +- "
875 << setw(6) << setprecision(3) << std[6] << endl;
876 emit newMessage(QByteArray(strF.str().c_str()), true);
877 }
878 }
879 }
880 }
881
882 // NMEA Output
883 // -----------
884 double xyz[3];
885 xyz[0] = x();
886 xyz[1] = y();
887 xyz[2] = z();
888 double ell[3];
889 xyz2ell(xyz, ell);
890 double phiDeg = ell[0] * 180 / M_PI;
891 double lamDeg = ell[1] * 180 / M_PI;
892
893 char phiCh = 'N';
894 if (phiDeg < 0) {
895 phiDeg = -phiDeg;
896 phiCh = 'S';
897 }
898 char lamCh = 'E';
899 if (lamDeg < 0) {
900 lamDeg = -lamDeg;
901 lamCh = 'W';
902 }
903
904 string datestr = epoData->tt.datestr(0); // yyyymmdd
905 ostringstream strRMC;
906 strRMC.setf(ios::fixed);
907 strRMC << "GPRMC,"
908 << epoData->tt.timestr(0,0) << ",A,"
909 << setw(2) << setfill('0') << int(phiDeg)
910 << setw(6) << setprecision(3) << setfill('0')
911 << fmod(60*phiDeg,60) << ',' << phiCh << ','
912 << setw(3) << setfill('0') << int(lamDeg)
913 << setw(6) << setprecision(3) << setfill('0')
914 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
915 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
916 << datestr[2] << datestr[3] << ",,";
917
918 writeNMEAstr(QString(strRMC.str().c_str()));
919
920 double dop = 2.0; // TODO
921
922 ostringstream strGGA;
923 strGGA.setf(ios::fixed);
924 strGGA << "GPGGA,"
925 << epoData->tt.timestr(0,0) << ','
926 << setw(2) << setfill('0') << int(phiDeg)
927 << setw(10) << setprecision(7) << setfill('0')
928 << fmod(60*phiDeg,60) << ',' << phiCh << ','
929 << setw(3) << setfill('0') << int(lamDeg)
930 << setw(10) << setprecision(7) << setfill('0')
931 << fmod(60*lamDeg,60) << ',' << lamCh
932 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
933 << setw(3) << setprecision(1) << dop << ','
934 << setprecision(3) << ell[2] << ",M,0.0,M,,";
935
936 writeNMEAstr(QString(strGGA.str().c_str()));
937
938 _lastTimeOK = _time; // remember time of last successful update
939 return success;
940}
941
942// Outlier Detection
943////////////////////////////////////////////////////////////////////////////
944bool bncModel::outlierDetection(int iPhase, const ColumnVector& vv,
945 QMap<QString, t_satData*>& satDataGPS,
946 QMap<QString, t_satData*>& satDataGlo,
947 QMap<QString, t_satData*>& satDataGal) {
948
949 Tracer tracer("bncModel::outlierDetection");
950
951 QString prnCode;
952 QString prnPhase;
953 double maxResCode = 0.0;
954 double maxResPhase = 0.0;
955
956 QString prnRemoved;
957 double maxRes;
958
959 bool irc = false;
960
961 if (iPhase == 0) {
962
963 // Check GPS Code
964 // --------------
965 if (!irc) {
966 findMaxRes(iPhase, vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
967 if (maxResCode > MAXRES_CODE_GPS) {
968 prnRemoved = prnCode;
969 maxRes = maxResCode;
970 irc = true;
971 }
972 }
973
974 // Check Galileo Code
975 // ------------------
976 if (!irc) {
977 findMaxRes(iPhase, vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
978 if (maxResCode > MAXRES_CODE_GAL) {
979 prnRemoved = prnCode;
980 maxRes = maxResCode;
981 irc = true;
982 }
983 }
984 }
985
986 else {
987
988 // Check Glonass Phase
989 // -------------------
990 if (!irc) {
991 findMaxRes(iPhase, vv,satDataGlo, prnCode, maxResCode, prnPhase, maxResPhase);
992 if (maxResPhase > MAXRES_PHASE_GLO) {
993 prnRemoved = prnPhase;
994 maxRes = maxResPhase;
995 irc = true;
996 }
997 }
998
999 // Check Galileo Phase
1000 // -------------------
1001 if (!irc) {
1002 findMaxRes(iPhase, vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
1003 if (maxResPhase > MAXRES_PHASE_GAL) {
1004 prnRemoved = prnPhase;
1005 maxRes = maxResPhase;
1006 irc = true;
1007 }
1008 }
1009
1010 // Check GPS Phase
1011 // ---------------
1012 if (!irc) {
1013 findMaxRes(iPhase, vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
1014 if (maxResPhase > MAXRES_PHASE_GPS) {
1015 prnRemoved = prnPhase;
1016 maxRes = maxResPhase;
1017 irc = true;
1018 }
1019 }
1020 }
1021
1022 if (irc) {
1023 _log += "Outlier " + prnRemoved.toAscii() + " "
1024 + QByteArray::number(maxRes, 'f', 3) + "\n";
1025 }
1026
1027 return irc;
1028}
1029
1030//
1031////////////////////////////////////////////////////////////////////////////
1032void bncModel::writeNMEAstr(const QString& nmStr) {
1033
1034 Tracer tracer("bncModel::writeNMEAstr");
1035
1036 unsigned char XOR = 0;
1037 for (int ii = 0; ii < nmStr.length(); ii++) {
1038 XOR ^= (unsigned char) nmStr[ii].toAscii();
1039 }
1040
1041 QString outStr = '$' + nmStr
1042 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
1043
1044 if (_nmeaStream) {
1045 *_nmeaStream << outStr;
1046 _nmeaStream->flush();
1047 }
1048
1049 emit newNMEAstr(outStr.toAscii());
1050}
1051
1052////
1053//////////////////////////////////////////////////////////////////////////////
1054void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1055 const DiagonalMatrix& PP,
1056 SymmetricMatrix& QQ, ColumnVector& dx) {
1057
1058 Tracer tracer("bncModel::kalman");
1059
1060 int nObs = AA.Nrows();
1061 int nPar = AA.Ncols();
1062
1063 UpperTriangularMatrix SS = Cholesky(QQ).t();
1064
1065 Matrix SA = SS*AA.t();
1066 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
1067 for (int ii = 1; ii <= nObs; ++ii) {
1068 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
1069 }
1070
1071 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
1072 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
1073
1074 UpperTriangularMatrix UU;
1075 QRZ(SRF, UU);
1076
1077 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
1078 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
1079 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
1080
1081 UpperTriangularMatrix SHi = SH_rt.i();
1082
1083 Matrix KT = SHi * YY;
1084 SymmetricMatrix Hi; Hi << SHi * SHi.t();
1085
1086 dx = KT.t() * ll;
1087 QQ << (SS.t() * SS);
1088}
1089
1090// Phase Wind-Up Correction
1091///////////////////////////////////////////////////////////////////////////
1092double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1093 const ColumnVector& rRec) {
1094
1095 Tracer tracer("bncModel::windUp");
1096
1097 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1098
1099 // First time - initialize to zero
1100 // -------------------------------
1101 if (!_windUpTime.contains(prn)) {
1102 _windUpSum[prn] = 0.0;
1103 }
1104
1105 // Compute the correction for new time
1106 // -----------------------------------
1107 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
1108 _windUpTime[prn] = Mjd;
1109
1110 // Unit Vector GPS Satellite --> Receiver
1111 // --------------------------------------
1112 ColumnVector rho = rRec - rSat;
1113 rho /= rho.norm_Frobenius();
1114
1115 // GPS Satellite unit Vectors sz, sy, sx
1116 // -------------------------------------
1117 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1118
1119 ColumnVector xSun = Sun(Mjd);
1120 xSun /= xSun.norm_Frobenius();
1121
1122 ColumnVector sy = crossproduct(sz, xSun);
1123 ColumnVector sx = crossproduct(sy, sz);
1124
1125 // Effective Dipole of the GPS Satellite Antenna
1126 // ---------------------------------------------
1127 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1128 - crossproduct(rho, sy);
1129
1130 // Receiver unit Vectors rx, ry
1131 // ----------------------------
1132 ColumnVector rx(3);
1133 ColumnVector ry(3);
1134
1135 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1136 double neu[3];
1137
1138 neu[0] = 1.0;
1139 neu[1] = 0.0;
1140 neu[2] = 0.0;
1141 neu2xyz(recEll, neu, rx.data());
1142
1143 neu[0] = 0.0;
1144 neu[1] = -1.0;
1145 neu[2] = 0.0;
1146 neu2xyz(recEll, neu, ry.data());
1147
1148 // Effective Dipole of the Receiver Antenna
1149 // ----------------------------------------
1150 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1151 + crossproduct(rho, ry);
1152
1153 // Resulting Effect
1154 // ----------------
1155 double alpha = DotProduct(dipSat,dipRec) /
1156 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1157
1158 if (alpha > 1.0) alpha = 1.0;
1159 if (alpha < -1.0) alpha = -1.0;
1160
1161 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1162
1163 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1164 dphi = -dphi;
1165 }
1166
1167 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1168 }
1169
1170 return _windUpSum[prn];
1171}
1172
1173//
1174///////////////////////////////////////////////////////////////////////////
1175void bncModel::cmpEle(t_satData* satData) {
1176 Tracer tracer("bncModel::cmpEle");
1177 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
1178 double rho = rr.norm_Frobenius();
1179
1180 double neu[3];
1181 xyz2neu(_ellBanc.data(), rr.data(), neu);
1182
1183 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
1184 if (neu[2] < 0) {
1185 satData->eleSat *= -1.0;
1186 }
1187 satData->azSat = atan2(neu[1], neu[0]);
1188}
1189
1190//
1191///////////////////////////////////////////////////////////////////////////
1192void bncModel::addAmb(t_satData* satData) {
1193 Tracer tracer("bncModel::addAmb");
1194 bool found = false;
1195 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1196 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1197 _params[iPar-1]->prn == satData->prn) {
1198 found = true;
1199 break;
1200 }
1201 }
1202 if (!found) {
1203 bncParam* par = new bncParam(bncParam::AMB_L3,
1204 _params.size()+1, satData->prn);
1205 _params.push_back(par);
1206 par->xx = satData->L3 - cmpValue(satData, true);
1207 }
1208}
1209
1210//
1211///////////////////////////////////////////////////////////////////////////
1212void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
1213 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1214
1215 Tracer tracer("bncModel::addObs");
1216
1217 const double ELEWGHT = 20.0;
1218 double ellWgtCoef = 1.0;
1219 double eleD = satData->eleSat * 180.0 / M_PI;
1220 if (eleD < ELEWGHT) {
1221 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
1222 }
1223
1224 // Phase Observations
1225 // ------------------
1226 if (iPhase == 1) {
1227 ++iObs;
1228 ll(iObs) = satData->L3 - cmpValue(satData, true);
1229 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3) / (ellWgtCoef * ellWgtCoef);
1230 if (satData->system() == 'R') {
1231 PP(iObs,iObs) /= 25.0;
1232 }
1233 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1234 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1235 _params[iPar-1]->prn == satData->prn) {
1236 ll(iObs) -= _params[iPar-1]->xx;
1237 }
1238 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
1239 }
1240 satData->indexPhase = iObs;
1241 }
1242
1243 // Code Observations
1244 // -----------------
1245 else {
1246 ++iObs;
1247 ll(iObs) = satData->P3 - cmpValue(satData, false);
1248 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3) / (ellWgtCoef * ellWgtCoef);
1249 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1250 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
1251 }
1252 satData->indexCode = iObs;
1253 }
1254}
1255
1256//
1257///////////////////////////////////////////////////////////////////////////
1258void bncModel::printRes(int iPhase, const ColumnVector& vv,
1259 ostringstream& str, t_satData* satData) {
1260 Tracer tracer("bncModel::printRes");
1261 if (iPhase == 1) {
1262 str << _time.timestr(1)
1263 << " RES " << satData->prn.toAscii().data() << " L3 "
1264 << setw(9) << setprecision(4) << vv(satData->indexPhase) << endl;
1265 }
1266 else {
1267 str << _time.timestr(1)
1268 << " RES " << satData->prn.toAscii().data() << " P3 "
1269 << setw(9) << setprecision(4) << vv(satData->indexCode) << endl;
1270 }
1271}
1272
1273//
1274///////////////////////////////////////////////////////////////////////////
1275void bncModel::findMaxRes(int iPhase, const ColumnVector& vv,
1276 const QMap<QString, t_satData*>& satData,
1277 QString& prnCode, double& maxResCode,
1278 QString& prnPhase, double& maxResPhase) {
1279 Tracer tracer("bncModel::findMaxRes");
1280 maxResCode = 0.0;
1281 maxResPhase = 0.0;
1282
1283 QMapIterator<QString, t_satData*> it(satData);
1284 while (it.hasNext()) {
1285 it.next();
1286 t_satData* satData = it.value();
1287 if (iPhase == 0) {
1288 if (satData->indexCode) {
1289 if (fabs(vv(satData->indexCode)) > maxResCode) {
1290 maxResCode = fabs(vv(satData->indexCode));
1291 prnCode = satData->prn;
1292 }
1293 }
1294 }
1295 else {
1296 if (satData->indexPhase) {
1297 if (fabs(vv(satData->indexPhase)) > maxResPhase) {
1298 maxResPhase = fabs(vv(satData->indexPhase));
1299 prnPhase = satData->prn;
1300 }
1301 }
1302 }
1303 }
1304}
1305
1306bool findInVector(const std::vector<QString>& vv, const QString& str) {
1307 std::vector<QString>::const_iterator it;
1308 for (it = vv.begin(); it != vv.end(); ++it) {
1309 if ( (*it) == str) {
1310 return true;
1311 }
1312 }
1313 return false;
1314}
1315
1316// Update Step (private - loop over outliers)
1317////////////////////////////////////////////////////////////////////////////
1318t_irc bncModel::update_p(t_epoData* epoData) {
1319
1320 Tracer tracer("bncModel::update_p");
1321
1322 rememberState(epoData);
1323
1324 ColumnVector dx;
1325
1326 std::vector<QString> allPrns;
1327 getAllPrns(epoData, &allPrns);
1328
1329 std::vector<QString> usedPrns;
1330
1331 // Try with all satellites, then with all minus one, etc.
1332 // ------------------------------------------------------
1333 for (unsigned nNeglected = 0; nNeglected < allPrns.size(); nNeglected++) {
1334 usedPrns = allPrns;
1335
1336 for (unsigned ii = 0; ii < nNeglected && usedPrns.size() > 0; ii++) {
1337 usedPrns.pop_back();
1338 }
1339
1340 bool outlierDetected = false;
1341
1342 // Loop over all Combinations of "nUsed" Satellites
1343 // ------------------------------------------------
1344 do {
1345
1346 if (outlierDetected) {
1347 _log += "TRY WITH PRNs: ";
1348 for (unsigned ip = 0; ip < usedPrns.size(); ip++) {
1349 _log += usedPrns[ip] + ' ';
1350 }
1351 _log += '\n';
1352 }
1353
1354 for (unsigned ip = 0; ip < allPrns.size(); ip++) {
1355 QString prn = allPrns[ip];
1356 if ( !findInVector(usedPrns, prn) ) {
1357 epoData->satDataGPS.remove(prn);
1358 epoData->satDataGlo.remove(prn);
1359 epoData->satDataGal.remove(prn);
1360 }
1361 }
1362
1363 // First update using code observations, then phase observations
1364 // -------------------------------------------------------------
1365 for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++) {
1366
1367 // Bancroft Solution
1368 // -----------------
1369 if (iPhase == 0) {
1370 if (cmpBancroft(epoData) != success) {
1371 restoreState(epoData);
1372 return failure;
1373 }
1374 else {
1375 if (nNeglected == 0) {
1376 delete _epoData_sav;
1377 _epoData_sav = new t_epoData(*epoData);
1378 }
1379 }
1380 }
1381 else {
1382 if (epoData->sizeGPS() < MINOBS) {
1383 restoreState(epoData);
1384 _log += "bncModel::update_p: not enough data\n";
1385 return failure;
1386 }
1387 unsigned numSatNoSlip = 0;
1388 QVectorIterator<bncParam*> itPar(_params);
1389 while (itPar.hasNext()) {
1390 bncParam* par = itPar.next();
1391 if (par->type == bncParam::AMB_L3 && par->prn[0] == 'G') {
1392 if (par->numEpo >= 1) {
1393 ++numSatNoSlip;
1394 }
1395 }
1396 }
1397 if (numSatNoSlip > 0 && numSatNoSlip < MINOBS) {
1398 restoreState(epoData);
1399 _log += "bncModel::update_p: not enough GPS satellites without cycle-slips\n";
1400 return failure;
1401 }
1402 }
1403
1404 // Status Prediction
1405 // -----------------
1406 predict(iPhase, epoData);
1407
1408 // Create First-Design Matrix
1409 // --------------------------
1410 unsigned nPar = _params.size();
1411 unsigned nObs = 0;
1412 if (iPhase == 0) {
1413 nObs = epoData->sizeGPS() + epoData->sizeGal(); // Glonass code not used
1414 }
1415 else {
1416 nObs = epoData->sizeGPS() + epoData->sizeGal() + epoData->sizeGlo();
1417 }
1418
1419 Matrix AA(nObs, nPar); // first design matrix
1420 ColumnVector ll(nObs); // tems observed-computed
1421 DiagonalMatrix PP(nObs); PP = 0.0;
1422
1423 unsigned iObs = 0;
1424
1425 // GPS
1426 // ---
1427 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
1428 while (itGPS.hasNext()) {
1429 itGPS.next();
1430 t_satData* satData = itGPS.value();
1431 QString prn = satData->prn;
1432 if (findInVector(usedPrns, satData->prn)) {
1433 addObs(iPhase, iObs, satData, AA, ll, PP);
1434 }
1435 }
1436
1437 // Glonass
1438 // -------
1439 if (iPhase == 1) {
1440 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
1441 while (itGlo.hasNext()) {
1442 itGlo.next();
1443 t_satData* satData = itGlo.value();
1444 if (findInVector(usedPrns, satData->prn)) {
1445 addObs(iPhase, iObs, satData, AA, ll, PP);
1446 }
1447 }
1448 }
1449
1450 // Galileo
1451 // -------
1452 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
1453 while (itGal.hasNext()) {
1454 itGal.next();
1455 t_satData* satData = itGal.value();
1456 if (findInVector(usedPrns, satData->prn)) {
1457 addObs(iPhase, iObs, satData, AA, ll, PP);
1458 }
1459 }
1460
1461 // Compute Filter Update
1462 // ---------------------
1463 kalman(AA, ll, PP, _QQ, dx);
1464
1465 ColumnVector vv = ll - AA * dx;
1466
1467 // Print Residuals
1468 // ---------------
1469 if (true) {
1470 ostringstream str;
1471 str.setf(ios::fixed);
1472
1473 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
1474 while (itGPS.hasNext()) {
1475 itGPS.next();
1476 t_satData* satData = itGPS.value();
1477 printRes(iPhase, vv, str, satData);
1478 }
1479 if (iPhase == 1) {
1480 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
1481 while (itGlo.hasNext()) {
1482 itGlo.next();
1483 t_satData* satData = itGlo.value();
1484 printRes(iPhase, vv, str, satData);
1485 }
1486 }
1487 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
1488 while (itGal.hasNext()) {
1489 itGal.next();
1490 t_satData* satData = itGal.value();
1491 printRes(iPhase, vv, str, satData);
1492 }
1493 _log += str.str().c_str();
1494 }
1495
1496 // Check the residuals
1497 // -------------------
1498 outlierDetected = outlierDetection(iPhase, vv,
1499 epoData->satDataGPS,
1500 epoData->satDataGlo,
1501 epoData->satDataGal);
1502 if (outlierDetected) {
1503 restoreState(epoData);
1504 break;
1505 }
1506
1507 } // for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++)
1508
1509 // Update Parameters
1510 // -----------------
1511 if (!outlierDetected) {
1512 QVectorIterator<bncParam*> itPar(_params);
1513 while (itPar.hasNext()) {
1514 bncParam* par = itPar.next();
1515 par->xx += dx(par->index);
1516 }
1517 return success;
1518 }
1519
1520 } while ( next_combination(allPrns.begin(), allPrns.end(),
1521 usedPrns.begin(), usedPrns.end()) );
1522
1523 } // for (unsigned nUsed = allPrns.size(); nUsed >= MINOBS; nUsed--)
1524
1525 return failure;
1526}
1527
1528// Remeber Original State Vector and Variance-Covariance Matrix
1529////////////////////////////////////////////////////////////////////////////
1530void bncModel::rememberState(t_epoData* epoData) {
1531
1532 _QQ_sav = _QQ;
1533
1534 QVectorIterator<bncParam*> itSav(_params_sav);
1535 while (itSav.hasNext()) {
1536 bncParam* par = itSav.next();
1537 delete par;
1538 }
1539 _params_sav.clear();
1540
1541 QVectorIterator<bncParam*> it(_params);
1542 while (it.hasNext()) {
1543 bncParam* par = it.next();
1544 _params_sav.push_back(new bncParam(*par));
1545 }
1546
1547 delete _epoData_sav;
1548 _epoData_sav = new t_epoData(*epoData);
1549}
1550
1551// Restore Original State Vector and Variance-Covariance Matrix
1552////////////////////////////////////////////////////////////////////////////
1553void bncModel::restoreState(t_epoData* epoData) {
1554
1555 _QQ = _QQ_sav;
1556
1557 QVectorIterator<bncParam*> it(_params);
1558 while (it.hasNext()) {
1559 bncParam* par = it.next();
1560 delete par;
1561 }
1562 _params.clear();
1563
1564 QVectorIterator<bncParam*> itSav(_params_sav);
1565 while (itSav.hasNext()) {
1566 bncParam* par = itSav.next();
1567 _params.push_back(new bncParam(*par));
1568 }
1569
1570 delete epoData;
1571 epoData = new t_epoData(*_epoData_sav);
1572}
1573
1574//
1575////////////////////////////////////////////////////////////////////////////
1576void bncModel::getAllPrns(const t_epoData* epoData,
1577 std::vector<QString>* allPrns) {
1578
1579 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
1580 while (itGPS.hasNext()) {
1581 itGPS.next();
1582 t_satData* satData = itGPS.value();
1583 allPrns->push_back(satData->prn);
1584 }
1585
1586 // Glonass
1587 // -------
1588 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
1589 while (itGlo.hasNext()) {
1590 itGlo.next();
1591 t_satData* satData = itGlo.value();
1592 allPrns->push_back(satData->prn);
1593 }
1594
1595 // Galileo
1596 // -------
1597 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
1598 while (itGal.hasNext()) {
1599 itGal.next();
1600 t_satData* satData = itGal.value();
1601 allPrns->push_back(satData->prn);
1602 }
1603}
1604
Note: See TracBrowser for help on using the repository browser.