source: ntrip/branches/BNC_LM/bncmodel.cpp@ 10463

Last change on this file since 10463 was 3571, checked in by mervart, 13 years ago
File size: 41.2 KB
RevLine 
[2057]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>
[2063]42#include <cmath>
[2060]43#include <newmatio.h>
[2113]44#include <sstream>
[2057]45
46#include "bncmodel.h"
[2113]47#include "bncapp.h"
[2058]48#include "bncpppclient.h"
49#include "bancroft.h"
[2063]50#include "bncutils.h"
[2077]51#include "bncsettings.h"
[2580]52#include "bnctides.h"
[2881]53#include "bncantex.h"
[2057]54
55using namespace std;
56
[3420]57const unsigned MINOBS = 5;
[3408]58const double MINELE = 10.0 * M_PI / 180.0;
59const double MAXRES_CODE = 10.0;
[3421]60const double MAXRES_PHASE_GPS = 0.04;
[3419]61const double MAXRES_PHASE_GLONASS = 0.08;
[3408]62const double GLONASS_WEIGHT_FACTOR = 5.0;
[2070]63
[2057]64// Constructor
65////////////////////////////////////////////////////////////////////////////
[2080]66bncParam::bncParam(bncParam::parType typeIn, int indexIn,
67 const QString& prnIn) {
68 type = typeIn;
69 index = indexIn;
70 prn = prnIn;
71 index_old = 0;
72 xx = 0.0;
[3330]73 numEpo = 0;
[2057]74}
75
76// Destructor
77////////////////////////////////////////////////////////////////////////////
78bncParam::~bncParam() {
79}
80
[2060]81// Partial
82////////////////////////////////////////////////////////////////////////////
[2239]83double bncParam::partial(t_satData* satData, bool phase) {
84
[3312]85 Tracer tracer("bncParam::partial");
86
[2239]87 // Coordinates
88 // -----------
[2060]89 if (type == CRD_X) {
[2109]90 return (xx - satData->xx(1)) / satData->rho;
[2060]91 }
92 else if (type == CRD_Y) {
[2109]93 return (xx - satData->xx(2)) / satData->rho;
[2060]94 }
95 else if (type == CRD_Z) {
[2109]96 return (xx - satData->xx(3)) / satData->rho;
[2060]97 }
[2239]98
99 // Receiver Clocks
100 // ---------------
[2265]101 else if (type == RECCLK) {
102 return 1.0;
[2060]103 }
[2239]104
105 // Troposphere
106 // -----------
[2084]107 else if (type == TROPO) {
108 return 1.0 / sin(satData->eleSat);
109 }
[2239]110
[2782]111 // Galileo Offset
112 // --------------
113 else if (type == GALILEO_OFFSET) {
114 if (satData->prn[0] == 'E') {
115 return 1.0;
116 }
117 else {
118 return 0.0;
119 }
120 }
121
[2239]122 // Ambiguities
123 // -----------
[2080]124 else if (type == AMB_L3) {
[2239]125 if (phase && satData->prn == prn) {
[2080]126 return 1.0;
127 }
128 else {
129 return 0.0;
130 }
131 }
[2239]132
133 // Default return
134 // --------------
[2060]135 return 0.0;
136}
137
[2058]138// Constructor
139////////////////////////////////////////////////////////////////////////////
[2113]140bncModel::bncModel(QByteArray staID) {
[2084]141
[2113]142 _staID = staID;
143
[3107]144 connect(this, SIGNAL(newMessage(QByteArray,bool)),
145 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
146
[2648]147 bncSettings settings;
148
[2720]149 // Observation Sigmas
150 // ------------------
151 _sigP3 = 5.0;
152 if (!settings.value("pppSigmaCode").toString().isEmpty()) {
153 _sigP3 = settings.value("pppSigmaCode").toDouble();
154 }
155 _sigL3 = 0.02;
156 if (!settings.value("pppSigmaPhase").toString().isEmpty()) {
[2741]157 _sigL3 = settings.value("pppSigmaPhase").toDouble();
[2720]158 }
[2648]159
[2720]160 // Parameter Sigmas
161 // ----------------
162 _sigCrd0 = 100.0;
163 if (!settings.value("pppSigCrd0").toString().isEmpty()) {
164 _sigCrd0 = settings.value("pppSigCrd0").toDouble();
165 }
166 _sigCrdP = 100.0;
167 if (!settings.value("pppSigCrdP").toString().isEmpty()) {
168 _sigCrdP = settings.value("pppSigCrdP").toDouble();
169 }
170 _sigTrp0 = 0.1;
171 if (!settings.value("pppSigTrp0").toString().isEmpty()) {
172 _sigTrp0 = settings.value("pppSigTrp0").toDouble();
173 }
174 _sigTrpP = 1e-6;
175 if (!settings.value("pppSigTrpP").toString().isEmpty()) {
176 _sigTrpP = settings.value("pppSigTrpP").toDouble();
177 }
[2782]178 _sigClk0 = 1000.0;
179 _sigAmb0 = 1000.0;
180 _sigGalileoOffset0 = 1000.0;
[2784]181 _sigGalileoOffsetP = 0.0;
[2648]182
[2720]183 // Quick-Start Mode
184 // ----------------
185 _quickStart = 0;
[2726]186 if (settings.value("pppRefCrdX").toString() != "" &&
187 settings.value("pppRefCrdY").toString() != "" &&
188 settings.value("pppRefCrdZ").toString() != "" &&
[2720]189 !settings.value("pppQuickStart").toString().isEmpty()) {
[2745]190 _quickStart = settings.value("pppQuickStart").toDouble();
[2720]191 }
192
[3107]193 // Several options
194 // ---------------
[2084]195 _usePhase = false;
196 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
197 _usePhase = true;
198 }
199
200 _estTropo = false;
201 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
202 _estTropo = true;
203 }
204
[3107]205 _useGalileo = false;
[2799]206 if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
[3107]207 _useGalileo = true;
[2782]208 }
[2073]209
[2125]210 // NMEA Output
211 // -----------
212 QString nmeaFileName = settings.value("nmeaFile").toString();
213 if (nmeaFileName.isEmpty()) {
214 _nmeaFile = 0;
215 _nmeaStream = 0;
216 }
217 else {
218 expandEnvVar(nmeaFileName);
219 _nmeaFile = new QFile(nmeaFileName);
220 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
221 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
222 }
223 else {
224 _nmeaFile->open(QIODevice::WriteOnly);
225 }
226 _nmeaStream = new QTextStream();
227 _nmeaStream->setDevice(_nmeaFile);
228 }
[2881]229
[3107]230 // Antenna Name, ANTEX File
231 // ------------------------
[2896]232 _antex = 0;
[2881]233 QString antexFileName = settings.value("pppAntex").toString();
234 if (!antexFileName.isEmpty()) {
235 _antex = new bncAntex();
[2883]236 if (_antex->readFile(antexFileName) != success) {
[2938]237 emit newMessage("wrong ANTEX file", true);
[2887]238 delete _antex;
239 _antex = 0;
[2883]240 }
[2938]241 else {
242 _antennaName = settings.value("pppAntenna").toString();
243 }
[2881]244 }
[3107]245
[3286]246 // Antenna Eccentricities
247 // ----------------------
248 _dN = settings.value("pppRefdN").toDouble();
249 _dE = settings.value("pppRefdE").toDouble();
250 _dU = settings.value("pppRefdU").toDouble();
251
[3107]252 // Bancroft Coordinates
253 // --------------------
254 _xcBanc.ReSize(4); _xcBanc = 0.0;
255 _ellBanc.ReSize(3); _ellBanc = 0.0;
[3408]256
257 // Save copy of data (used in outlier detection)
258 // ---------------------------------------------
259 _epoData_sav = new t_epoData();
[2058]260}
261
[3108]262// Destructor
[3107]263////////////////////////////////////////////////////////////////////////////
[3108]264bncModel::~bncModel() {
265 delete _nmeaStream;
266 delete _nmeaFile;
267 for (int ii = 0; ii < _posAverage.size(); ++ii) {
268 delete _posAverage[ii];
269 }
270 delete _antex;
271 for (int iPar = 1; iPar <= _params.size(); iPar++) {
272 delete _params[iPar-1];
273 }
[3571]274 for (int iPar = 1; iPar <= _params_sav.size(); iPar++) {
275 delete _params_sav[iPar-1];
276 }
[3408]277 delete _epoData_sav;
[3108]278}
279
280// Reset Parameters and Variance-Covariance Matrix
281////////////////////////////////////////////////////////////////////////////
[3107]282void bncModel::reset() {
283
[3312]284 Tracer tracer("bncModel::reset");
285
[3107]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
[2058]323// Bancroft Solution
324////////////////////////////////////////////////////////////////////////////
325t_irc bncModel::cmpBancroft(t_epoData* epoData) {
326
[3312]327 Tracer tracer("bncModel::cmpBancroft");
328
[3408]329 if (epoData->sizeSys('G') < MINOBS) {
[2547]330 _log += "bncModel::cmpBancroft: not enough data\n";
[2058]331 return failure;
332 }
333
[3408]334 Matrix BB(epoData->sizeSys('G'), 4);
[2058]335
[3408]336 QMapIterator<QString, t_satData*> it(epoData->satData);
[2791]337 int iObsBanc = 0;
[2058]338 while (it.hasNext()) {
339 it.next();
340 t_satData* satData = it.value();
[3408]341 if (satData->system() == 'G') {
342 ++iObsBanc;
343 QString prn = it.key();
344 BB(iObsBanc, 1) = satData->xx(1);
345 BB(iObsBanc, 2) = satData->xx(2);
346 BB(iObsBanc, 3) = satData->xx(3);
347 BB(iObsBanc, 4) = satData->P3 + satData->clk;
348 }
[2058]349 }
350
351 bancroft(BB, _xcBanc);
352
[2064]353 // Ellipsoidal Coordinates
354 // ------------------------
355 xyz2ell(_xcBanc.data(), _ellBanc.data());
[2063]356
[2064]357 // Compute Satellite Elevations
358 // ----------------------------
[3408]359 QMutableMapIterator<QString, t_satData*> im(epoData->satData);
360 while (im.hasNext()) {
361 im.next();
362 t_satData* satData = im.value();
[2789]363 cmpEle(satData);
[3408]364 if (satData->eleSat < MINELE) {
[2070]365 delete satData;
[3408]366 im.remove();
[2070]367 }
[2064]368 }
369
[2058]370 return success;
371}
[2060]372
373// Computed Value
374////////////////////////////////////////////////////////////////////////////
[2583]375double bncModel::cmpValue(t_satData* satData, bool phase) {
[2060]376
[3312]377 Tracer tracer("bncModel::cmpValue");
378
[2073]379 ColumnVector xRec(3);
380 xRec(1) = x();
381 xRec(2) = y();
382 xRec(3) = z();
[2060]383
[2073]384 double rho0 = (satData->xx - xRec).norm_Frobenius();
[2060]385 double dPhi = t_CST::omega * rho0 / t_CST::c;
386
[2073]387 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
388 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
389 xRec(3) = z();
390
[2580]391 tides(_time, xRec);
392
[2060]393 satData->rho = (satData->xx - xRec).norm_Frobenius();
394
[2084]395 double tropDelay = delay_saast(satData->eleSat) +
396 trp() / sin(satData->eleSat);
[2060]397
[2583]398 double wind = 0.0;
399 if (phase) {
400 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
401 }
402
[2783]403 double offset = 0.0;
404 if (satData->prn[0] == 'E') {
405 offset = Galileo_offset();
406 }
407
[2894]408 double phaseCenter = 0.0;
[2938]409 if (_antex) {
410 bool found;
411 phaseCenter = _antex->pco(_antennaName, satData->eleSat, found);
412 if (!found) {
413 emit newMessage("ANTEX: antenna >"
414 + _antennaName.toAscii() + "< not found", true);
415 }
[2894]416 }
417
[3286]418 double antennaOffset = 0.0;
419 if (_dN != 0.0 || _dE != 0.0 || _dU != 0.0) {
[3287]420 double cosa = cos(satData->azSat);
421 double sina = sin(satData->azSat);
422 double cose = cos(satData->eleSat);
423 double sine = sin(satData->eleSat);
424 antennaOffset = -_dN * cosa*cose - _dE * sina*cose - _dU * sine;
[3286]425 }
426
427 return satData->rho + phaseCenter + antennaOffset + clk()
[2894]428 + offset - satData->clk + tropDelay + wind;
[2060]429}
430
[2063]431// Tropospheric Model (Saastamoinen)
432////////////////////////////////////////////////////////////////////////////
[2065]433double bncModel::delay_saast(double Ele) {
[2063]434
[3312]435 Tracer tracer("bncModel::delay_saast");
436
[2769]437 double xyz[3];
438 xyz[0] = x();
439 xyz[1] = y();
440 xyz[2] = z();
441 double ell[3];
442 xyz2ell(xyz, ell);
443 double height = ell[2];
[2063]444
[2064]445 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
446 double TT = 18.0 - height * 0.0065 + 273.15;
447 double hh = 50.0 * exp(-6.396e-4 * height);
[2063]448 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
449
[2064]450 double h_km = height / 1000.0;
[2063]451
452 if (h_km < 0.0) h_km = 0.0;
453 if (h_km > 5.0) h_km = 5.0;
454 int ii = int(h_km + 1);
455 double href = ii - 1;
456
457 double bCor[6];
458 bCor[0] = 1.156;
459 bCor[1] = 1.006;
460 bCor[2] = 0.874;
461 bCor[3] = 0.757;
462 bCor[4] = 0.654;
463 bCor[5] = 0.563;
464
465 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
466
467 double zen = M_PI/2.0 - Ele;
468
469 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
470}
471
[2073]472// Prediction Step of the Filter
473////////////////////////////////////////////////////////////////////////////
[3309]474void bncModel::predict(int iPhase, t_epoData* epoData) {
[2073]475
[3312]476 Tracer tracer("bncModel::predict");
477
[3310]478 if (iPhase == 0) {
[2244]479
[3310]480 bncSettings settings;
481
482 _maxSolGap = settings.value("pppMaxSolGap").toDouble();
483
484 bool firstCrd = false;
485 if (!_lastTimeOK.valid() || (_maxSolGap > 0 && _time - _lastTimeOK > _maxSolGap)) {
486 firstCrd = true;
487 _startTime = epoData->tt;
488 reset();
489 }
490
491 // Use different white noise for Quick-Start mode
492 // ----------------------------------------------
493 double sigCrdP_used = _sigCrdP;
494 if ( _quickStart > 0.0 && _quickStart > (epoData->tt - _startTime) ) {
495 sigCrdP_used = 0.0;
496 }
[3106]497
[3310]498 // Predict Parameter values, add white noise
499 // -----------------------------------------
500 for (int iPar = 1; iPar <= _params.size(); iPar++) {
501 bncParam* pp = _params[iPar-1];
502
503 // Coordinates
504 // -----------
505 if (pp->type == bncParam::CRD_X) {
506 if (firstCrd) {
507 if (settings.value("pppRefCrdX").toString() != "" &&
508 settings.value("pppRefCrdY").toString() != "" &&
509 settings.value("pppRefCrdZ").toString() != "") {
510 pp->xx = settings.value("pppRefCrdX").toDouble();
511 }
512 else {
513 pp->xx = _xcBanc(1);
514 }
[2648]515 }
[3310]516 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]517 }
[3310]518 else if (pp->type == bncParam::CRD_Y) {
519 if (firstCrd) {
520 if (settings.value("pppRefCrdX").toString() != "" &&
521 settings.value("pppRefCrdY").toString() != "" &&
522 settings.value("pppRefCrdZ").toString() != "") {
523 pp->xx = settings.value("pppRefCrdY").toDouble();
524 }
525 else {
526 pp->xx = _xcBanc(2);
527 }
[2648]528 }
[3310]529 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]530 }
[3310]531 else if (pp->type == bncParam::CRD_Z) {
532 if (firstCrd) {
533 if (settings.value("pppRefCrdX").toString() != "" &&
534 settings.value("pppRefCrdY").toString() != "" &&
535 settings.value("pppRefCrdZ").toString() != "") {
536 pp->xx = settings.value("pppRefCrdZ").toDouble();
537 }
538 else {
539 pp->xx = _xcBanc(3);
540 }
[2648]541 }
[3310]542 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
543 }
544
545 // Receiver Clocks
546 // ---------------
547 else if (pp->type == bncParam::RECCLK) {
548 pp->xx = _xcBanc(4);
549 for (int jj = 1; jj <= _params.size(); jj++) {
550 _QQ(iPar, jj) = 0.0;
[2648]551 }
[3310]552 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
[2244]553 }
[3310]554
555 // Tropospheric Delay
556 // ------------------
557 else if (pp->type == bncParam::TROPO) {
558 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
[2244]559 }
[3310]560
561 // Galileo Offset
562 // --------------
563 else if (pp->type == bncParam::GALILEO_OFFSET) {
564 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
565 }
[2244]566 }
567 }
568
569 // Add New Ambiguities if necessary
570 // --------------------------------
[2083]571 if (_usePhase) {
[2080]572
[2083]573 // Make a copy of QQ and xx, set parameter indices
574 // -----------------------------------------------
575 SymmetricMatrix QQ_old = _QQ;
576
577 for (int iPar = 1; iPar <= _params.size(); iPar++) {
578 _params[iPar-1]->index_old = _params[iPar-1]->index;
579 _params[iPar-1]->index = 0;
580 }
581
582 // Remove Ambiguity Parameters without observations
583 // ------------------------------------------------
584 int iPar = 0;
[3408]585 QMutableVectorIterator<bncParam*> im(_params);
586 while (im.hasNext()) {
587 bncParam* par = im.next();
[2083]588 bool removed = false;
589 if (par->type == bncParam::AMB_L3) {
[3408]590 if (epoData->satData.find(par->prn) == epoData->satData.end()) {
[2083]591 removed = true;
592 delete par;
[3408]593 im.remove();
[2083]594 }
[2080]595 }
[2083]596 if (! removed) {
597 ++iPar;
598 par->index = iPar;
599 }
[2080]600 }
[2083]601
602 // Add new ambiguity parameters
603 // ----------------------------
[3408]604 QMapIterator<QString, t_satData*> it(epoData->satData);
605 while (it.hasNext()) {
606 it.next();
607 t_satData* satData = it.value();
[2789]608 addAmb(satData);
[2080]609 }
[2083]610
611 int nPar = _params.size();
612 _QQ.ReSize(nPar); _QQ = 0.0;
613 for (int i1 = 1; i1 <= nPar; i1++) {
614 bncParam* p1 = _params[i1-1];
615 if (p1->index_old != 0) {
616 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
617 for (int i2 = 1; i2 <= nPar; i2++) {
618 bncParam* p2 = _params[i2-1];
619 if (p2->index_old != 0) {
620 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
621 }
[2080]622 }
623 }
624 }
[2083]625
626 for (int ii = 1; ii <= nPar; ii++) {
627 bncParam* par = _params[ii-1];
628 if (par->index_old == 0) {
[2720]629 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
[2083]630 }
631 par->index_old = par->index;
[2080]632 }
633 }
[2073]634}
635
[2060]636// Update Step of the Filter (currently just a single-epoch solution)
637////////////////////////////////////////////////////////////////////////////
638t_irc bncModel::update(t_epoData* epoData) {
639
[3312]640 Tracer tracer("bncModel::update");
641
[2473]642 bncSettings settings;
643
[2248]644 _log.clear();
[2124]645
[3571]646 _time = epoData->tt; // current epoch time
647
[2827]648 if (settings.value("pppSPP").toString() == "PPP") {
649 _log += "Precise Point Positioning of Epoch "
650 + QByteArray(_time.timestr(1).c_str()) +
651 "\n---------------------------------------------------------------\n";
652 }
653 else {
654 _log += "Single Point Positioning of Epoch "
655 + QByteArray(_time.timestr(1).c_str()) +
[2547]656 "\n--------------------------------------------------------------\n";
[2827]657 }
[2547]658
[3307]659 // Outlier Detection Loop
[2113]660 // ----------------------
[3321]661 if (update_p(epoData) != success) {
[3408]662 emit newMessage(_log, false);
[3307]663 return failure;
664 }
[2080]665
[2670]666 // Remember the Epoch-specific Results for the computation of means
667 // ----------------------------------------------------------------
668 pppPos* newPos = new pppPos;
669 newPos->time = epoData->tt;
670
[2109]671 // Set Solution Vector
672 // -------------------
[2265]673 ostringstream strB;
674 strB.setf(ios::fixed);
[2073]675 QVectorIterator<bncParam*> itPar(_params);
[2060]676 while (itPar.hasNext()) {
677 bncParam* par = itPar.next();
[2265]678
679 if (par->type == bncParam::RECCLK) {
[2798]680 strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
[2124]681 << " +- " << setw(6) << setprecision(3)
682 << sqrt(_QQ(par->index,par->index));
683 }
684 else if (par->type == bncParam::AMB_L3) {
[3330]685 ++par->numEpo;
[2265]686 strB << "\n amb " << par->prn.toAscii().data() << " = "
[2798]687 << setw(10) << setprecision(3) << par->xx
[2124]688 << " +- " << setw(6) << setprecision(3)
[3330]689 << sqrt(_QQ(par->index,par->index))
690 << " nEpo = " << par->numEpo;
[2124]691 }
[2212]692 else if (par->type == bncParam::TROPO) {
[2670]693 double aprTrp = delay_saast(M_PI/2.0);
[2547]694 strB << "\n trp = " << par->prn.toAscii().data()
[2670]695 << setw(7) << setprecision(3) << aprTrp << " "
[2213]696 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
[2212]697 << " +- " << setw(6) << setprecision(3)
698 << sqrt(_QQ(par->index,par->index));
[2670]699 newPos->xnt[6] = aprTrp + par->xx;
[2212]700 }
[2782]701 else if (par->type == bncParam::GALILEO_OFFSET) {
[2798]702 strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
[2782]703 << " +- " << setw(6) << setprecision(3)
704 << sqrt(_QQ(par->index,par->index));
705 }
[2060]706 }
[2265]707 strB << '\n';
[2547]708 _log += strB.str().c_str();
709 emit newMessage(_log, false);
[2060]710
[2547]711 // Final Message (both log file and screen)
712 // ----------------------------------------
713 ostringstream strC;
714 strC.setf(ios::fixed);
715 strC << _staID.data() << " PPP "
[2599]716 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
[2231]717 << setw(14) << setprecision(3) << x() << " +- "
718 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
719 << setw(14) << setprecision(3) << y() << " +- "
720 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
721 << setw(14) << setprecision(3) << z() << " +- "
[2124]722 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
[2113]723
[2370]724 // NEU Output
725 // ----------
[2862]726 double xyzRef[3];
727
[2726]728 if (settings.value("pppRefCrdX").toString() != "" &&
729 settings.value("pppRefCrdY").toString() != "" &&
730 settings.value("pppRefCrdZ").toString() != "") {
[2649]731
[2370]732 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
733 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
734 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
[2649]735
[2670]736 newPos->xnt[0] = x() - xyzRef[0];
737 newPos->xnt[1] = y() - xyzRef[1];
738 newPos->xnt[2] = z() - xyzRef[2];
[2649]739
740 double ellRef[3];
[2370]741 xyz2ell(xyzRef, ellRef);
[2670]742 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
[2649]743
[2547]744 strC << " NEU "
[2670]745 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
746 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
[2797]747 << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
[2649]748
[2370]749 }
750
[2547]751 emit newMessage(QByteArray(strC.str().c_str()), true);
752
[2671]753 if (settings.value("pppAverage").toString() == "") {
754 delete newPos;
755 }
756 else {
757
758 _posAverage.push_back(newPos);
[2599]759
[2648]760 // Time Span for Average Computation
761 // ---------------------------------
762 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
763 if (tRangeAverage < 0) {
764 tRangeAverage = 0;
765 }
766 if (tRangeAverage > 86400) {
767 tRangeAverage = 86400;
768 }
[2599]769
[2648]770 // Compute the Mean
771 // ----------------
[2670]772 ColumnVector mean(7); mean = 0.0;
[2648]773
[2599]774 QMutableVectorIterator<pppPos*> it(_posAverage);
775 while (it.hasNext()) {
776 pppPos* pp = it.next();
[2648]777 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
[2599]778 delete pp;
779 it.remove();
780 }
[2648]781 else {
[2670]782 for (int ii = 0; ii < 7; ++ii) {
783 mean[ii] += pp->xnt[ii];
[2649]784 }
[2648]785 }
[2599]786 }
[2648]787
788 int nn = _posAverage.size();
789
[2649]790 if (nn > 0) {
[2648]791
[2649]792 mean /= nn;
793
794 // Compute the Deviation
795 // ---------------------
[2670]796 ColumnVector std(7); std = 0.0;
[2649]797 QVectorIterator<pppPos*> it2(_posAverage);
798 while (it2.hasNext()) {
799 pppPos* pp = it2.next();
[2670]800 for (int ii = 0; ii < 7; ++ii) {
801 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
[2649]802 }
803 }
[2670]804 for (int ii = 0; ii < 7; ++ii) {
[2649]805 std[ii] = sqrt(std[ii] / nn);
806 }
[3169]807
808 if (settings.value("pppRefCrdX").toString() != "" &&
809 settings.value("pppRefCrdY").toString() != "" &&
810 settings.value("pppRefCrdZ").toString() != "") {
[2649]811
[3169]812 ostringstream strD; strD.setf(ios::fixed);
813 strD << _staID.data() << " AVE-XYZ "
814 << epoData->tt.timestr(1) << " "
815 << setw(13) << setprecision(3) << mean[0] + xyzRef[0] << " +- "
816 << setw(6) << setprecision(3) << std[0] << " "
817 << setw(14) << setprecision(3) << mean[1] + xyzRef[1] << " +- "
818 << setw(6) << setprecision(3) << std[1] << " "
819 << setw(14) << setprecision(3) << mean[2] + xyzRef[2] << " +- "
820 << setw(6) << setprecision(3) << std[2];
821 emit newMessage(QByteArray(strD.str().c_str()), true);
[2649]822
[3169]823 ostringstream strE; strE.setf(ios::fixed);
824 strE << _staID.data() << " AVE-NEU "
825 << epoData->tt.timestr(1) << " "
826 << setw(13) << setprecision(3) << mean[3] << " +- "
827 << setw(6) << setprecision(3) << std[3] << " "
828 << setw(14) << setprecision(3) << mean[4] << " +- "
829 << setw(6) << setprecision(3) << std[4] << " "
830 << setw(14) << setprecision(3) << mean[5] << " +- "
831 << setw(6) << setprecision(3) << std[5];
832 emit newMessage(QByteArray(strE.str().c_str()), true);
[2649]833
[3169]834 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
835 ostringstream strF; strF.setf(ios::fixed);
836 strF << _staID.data() << " AVE-TRP "
837 << epoData->tt.timestr(1) << " "
838 << setw(13) << setprecision(3) << mean[6] << " +- "
839 << setw(6) << setprecision(3) << std[6] << endl;
840 emit newMessage(QByteArray(strF.str().c_str()), true);
841 }
[2726]842 }
[2599]843 }
844 }
845
[2131]846 // NMEA Output
847 // -----------
[2181]848 double xyz[3];
849 xyz[0] = x();
850 xyz[1] = y();
851 xyz[2] = z();
852 double ell[3];
853 xyz2ell(xyz, ell);
854 double phiDeg = ell[0] * 180 / M_PI;
855 double lamDeg = ell[1] * 180 / M_PI;
[2132]856
[2181]857 char phiCh = 'N';
858 if (phiDeg < 0) {
859 phiDeg = -phiDeg;
860 phiCh = 'S';
861 }
862 char lamCh = 'E';
863 if (lamDeg < 0) {
[2563]864 lamDeg = -lamDeg;
865 lamCh = 'W';
[2181]866 }
[2132]867
[2566]868 string datestr = epoData->tt.datestr(0); // yyyymmdd
869 ostringstream strRMC;
870 strRMC.setf(ios::fixed);
871 strRMC << "GPRMC,"
872 << epoData->tt.timestr(0,0) << ",A,"
873 << setw(2) << setfill('0') << int(phiDeg)
874 << setw(6) << setprecision(3) << setfill('0')
875 << fmod(60*phiDeg,60) << ',' << phiCh << ','
876 << setw(3) << setfill('0') << int(lamDeg)
877 << setw(6) << setprecision(3) << setfill('0')
878 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
[2569]879 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
880 << datestr[2] << datestr[3] << ",,";
[2566]881
882 writeNMEAstr(QString(strRMC.str().c_str()));
883
[2181]884 double dop = 2.0; // TODO
[2133]885
[2566]886 ostringstream strGGA;
887 strGGA.setf(ios::fixed);
888 strGGA << "GPGGA,"
889 << epoData->tt.timestr(0,0) << ','
890 << setw(2) << setfill('0') << int(phiDeg)
891 << setw(10) << setprecision(7) << setfill('0')
892 << fmod(60*phiDeg,60) << ',' << phiCh << ','
893 << setw(3) << setfill('0') << int(lamDeg)
894 << setw(10) << setprecision(7) << setfill('0')
895 << fmod(60*lamDeg,60) << ',' << lamCh
896 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
897 << setw(3) << setprecision(1) << dop << ','
[2569]898 << setprecision(3) << ell[2] << ",M,0.0,M,,";
[2181]899
[2566]900 writeNMEAstr(QString(strGGA.str().c_str()));
[2131]901
[3106]902 _lastTimeOK = _time; // remember time of last successful update
[2060]903 return success;
904}
[2112]905
906// Outlier Detection
907////////////////////////////////////////////////////////////////////////////
[3412]908QString bncModel::outlierDetection(int iPhase, const ColumnVector& vv,
909 QMap<QString, t_satData*>& satData) {
[2112]910
[3312]911 Tracer tracer("bncModel::outlierDetection");
912
[3414]913 QString prnGPS;
914 QString prnGlo;
915 double maxResGPS = 0.0;
916 double maxResGlo = 0.0;
917 findMaxRes(vv, satData, prnGPS, prnGlo, maxResGPS, maxResGlo);
[2231]918
[3414]919 if (iPhase == 1) {
920 if (maxResGlo > MAXRES_PHASE_GLONASS) {
921 _log += "Outlier Phase " + prnGlo + " "
922 + QByteArray::number(maxResGlo, 'f', 3) + "\n";
923 return prnGlo;
924 }
925 else if (maxResGPS > MAXRES_PHASE_GPS) {
926 _log += "Outlier Phase " + prnGPS + " "
927 + QByteArray::number(maxResGPS, 'f', 3) + "\n";
928 return prnGPS;
929 }
[2792]930 }
[3414]931 else if (iPhase == 0 && maxResGPS > MAXRES_CODE) {
932 _log += "Outlier Code " + prnGPS + " "
933 + QByteArray::number(maxResGPS, 'f', 3) + "\n";
934 return prnGPS;
[3408]935 }
[3414]936
937 return QString();
[2112]938}
[2130]939
940//
941////////////////////////////////////////////////////////////////////////////
942void bncModel::writeNMEAstr(const QString& nmStr) {
943
[3312]944 Tracer tracer("bncModel::writeNMEAstr");
945
[2130]946 unsigned char XOR = 0;
947 for (int ii = 0; ii < nmStr.length(); ii++) {
948 XOR ^= (unsigned char) nmStr[ii].toAscii();
949 }
[2181]950
951 QString outStr = '$' + nmStr
952 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
[2130]953
[2178]954 if (_nmeaStream) {
[2181]955 *_nmeaStream << outStr;
[2178]956 _nmeaStream->flush();
957 }
[2130]958
[2181]959 emit newNMEAstr(outStr.toAscii());
[2130]960}
[2283]961
[3408]962//
[2283]963//////////////////////////////////////////////////////////////////////////////
964void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
965 const DiagonalMatrix& PP,
966 SymmetricMatrix& QQ, ColumnVector& dx) {
967
[3312]968 Tracer tracer("bncModel::kalman");
969
[2283]970 int nObs = AA.Nrows();
971 int nPar = AA.Ncols();
972
973 UpperTriangularMatrix SS = Cholesky(QQ).t();
974
975 Matrix SA = SS*AA.t();
976 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
977 for (int ii = 1; ii <= nObs; ++ii) {
978 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
979 }
980
981 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
982 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
983
984 UpperTriangularMatrix UU;
985 QRZ(SRF, UU);
986
987 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
988 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
989 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
990
991 UpperTriangularMatrix SHi = SH_rt.i();
992
993 Matrix KT = SHi * YY;
994 SymmetricMatrix Hi; Hi << SHi * SHi.t();
995
996 dx = KT.t() * ll;
997 QQ << (SS.t() * SS);
998}
[2582]999
1000// Phase Wind-Up Correction
1001///////////////////////////////////////////////////////////////////////////
1002double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1003 const ColumnVector& rRec) {
1004
[3312]1005 Tracer tracer("bncModel::windUp");
1006
[2582]1007 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1008
1009 // First time - initialize to zero
1010 // -------------------------------
1011 if (!_windUpTime.contains(prn)) {
1012 _windUpSum[prn] = 0.0;
1013 }
1014
1015 // Compute the correction for new time
1016 // -----------------------------------
[2942]1017 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
[2582]1018 _windUpTime[prn] = Mjd;
1019
1020 // Unit Vector GPS Satellite --> Receiver
1021 // --------------------------------------
1022 ColumnVector rho = rRec - rSat;
1023 rho /= rho.norm_Frobenius();
1024
1025 // GPS Satellite unit Vectors sz, sy, sx
1026 // -------------------------------------
1027 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1028
1029 ColumnVector xSun = Sun(Mjd);
1030 xSun /= xSun.norm_Frobenius();
1031
1032 ColumnVector sy = crossproduct(sz, xSun);
1033 ColumnVector sx = crossproduct(sy, sz);
1034
1035 // Effective Dipole of the GPS Satellite Antenna
1036 // ---------------------------------------------
1037 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1038 - crossproduct(rho, sy);
1039
1040 // Receiver unit Vectors rx, ry
1041 // ----------------------------
1042 ColumnVector rx(3);
1043 ColumnVector ry(3);
1044
1045 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1046 double neu[3];
1047
1048 neu[0] = 1.0;
1049 neu[1] = 0.0;
1050 neu[2] = 0.0;
1051 neu2xyz(recEll, neu, rx.data());
1052
1053 neu[0] = 0.0;
1054 neu[1] = -1.0;
1055 neu[2] = 0.0;
1056 neu2xyz(recEll, neu, ry.data());
1057
1058 // Effective Dipole of the Receiver Antenna
1059 // ----------------------------------------
1060 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1061 + crossproduct(rho, ry);
1062
1063 // Resulting Effect
1064 // ----------------
1065 double alpha = DotProduct(dipSat,dipRec) /
1066 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1067
1068 if (alpha > 1.0) alpha = 1.0;
1069 if (alpha < -1.0) alpha = -1.0;
1070
1071 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1072
1073 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1074 dphi = -dphi;
1075 }
1076
1077 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1078 }
1079
1080 return _windUpSum[prn];
1081}
[2789]1082
1083//
1084///////////////////////////////////////////////////////////////////////////
1085void bncModel::cmpEle(t_satData* satData) {
[3312]1086 Tracer tracer("bncModel::cmpEle");
[2789]1087 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
1088 double rho = rr.norm_Frobenius();
1089
1090 double neu[3];
1091 xyz2neu(_ellBanc.data(), rr.data(), neu);
1092
1093 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
1094 if (neu[2] < 0) {
1095 satData->eleSat *= -1.0;
1096 }
1097 satData->azSat = atan2(neu[1], neu[0]);
1098}
1099
1100//
1101///////////////////////////////////////////////////////////////////////////
1102void bncModel::addAmb(t_satData* satData) {
[3312]1103 Tracer tracer("bncModel::addAmb");
[2789]1104 bool found = false;
1105 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1106 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1107 _params[iPar-1]->prn == satData->prn) {
1108 found = true;
1109 break;
1110 }
1111 }
1112 if (!found) {
1113 bncParam* par = new bncParam(bncParam::AMB_L3,
1114 _params.size()+1, satData->prn);
1115 _params.push_back(par);
1116 par->xx = satData->L3 - cmpValue(satData, true);
1117 }
1118}
[2790]1119
1120//
1121///////////////////////////////////////////////////////////////////////////
[3309]1122void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
[2790]1123 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1124
[3312]1125 Tracer tracer("bncModel::addObs");
1126
[3316]1127 const double ELEWGHT = 20.0;
[3314]1128 double ellWgtCoef = 1.0;
1129 double eleD = satData->eleSat * 180.0 / M_PI;
1130 if (eleD < ELEWGHT) {
[3317]1131 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
[3314]1132 }
1133
[3408]1134 // Remember Observation Index
1135 // --------------------------
1136 ++iObs;
1137 satData->obsIndex = iObs;
1138
[2791]1139 // Phase Observations
1140 // ------------------
[3309]1141 if (iPhase == 1) {
[2790]1142 ll(iObs) = satData->L3 - cmpValue(satData, true);
[3408]1143 double sigL3 = _sigL3;
[3319]1144 if (satData->system() == 'R') {
[3408]1145 sigL3 *= GLONASS_WEIGHT_FACTOR;
[3319]1146 }
[3408]1147 PP(iObs,iObs) = 1.0 / (sigL3 * sigL3) / (ellWgtCoef * ellWgtCoef);
[2790]1148 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1149 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1150 _params[iPar-1]->prn == satData->prn) {
1151 ll(iObs) -= _params[iPar-1]->xx;
1152 }
1153 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
1154 }
1155 }
[3307]1156
1157 // Code Observations
1158 // -----------------
1159 else {
1160 ll(iObs) = satData->P3 - cmpValue(satData, false);
[3314]1161 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3) / (ellWgtCoef * ellWgtCoef);
[3307]1162 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1163 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
1164 }
1165 }
[2790]1166}
[2791]1167
1168//
1169///////////////////////////////////////////////////////////////////////////
[3408]1170QByteArray bncModel::printRes(int iPhase, const ColumnVector& vv,
1171 const QMap<QString, t_satData*>& satDataMap) {
1172
[3312]1173 Tracer tracer("bncModel::printRes");
[3408]1174
1175 ostringstream str;
1176 str.setf(ios::fixed);
1177
1178 QMapIterator<QString, t_satData*> it(satDataMap);
1179 while (it.hasNext()) {
1180 it.next();
1181 t_satData* satData = it.value();
1182 if (satData->obsIndex != 0) {
1183 str << _time.timestr(1)
1184 << " RES " << satData->prn.toAscii().data()
1185 << (iPhase ? " L3 " : " P3 ")
1186 << setw(9) << setprecision(4) << vv(satData->obsIndex) << endl;
1187 }
[2791]1188 }
[3408]1189
1190 return QByteArray(str.str().c_str());
[2791]1191}
[2792]1192
1193//
1194///////////////////////////////////////////////////////////////////////////
[3408]1195void bncModel::findMaxRes(const ColumnVector& vv,
[2792]1196 const QMap<QString, t_satData*>& satData,
[3414]1197 QString& prnGPS, QString& prnGlo,
1198 double& maxResGPS, double& maxResGlo) {
[3408]1199
[3312]1200 Tracer tracer("bncModel::findMaxRes");
[2792]1201
[3414]1202 maxResGPS = 0.0;
1203 maxResGlo = 0.0;
[3408]1204
[2792]1205 QMapIterator<QString, t_satData*> it(satData);
1206 while (it.hasNext()) {
1207 it.next();
1208 t_satData* satData = it.value();
[3414]1209 if (satData->obsIndex != 0) {
1210 QString prn = satData->prn;
1211 if (prn[0] == 'R') {
1212 if (fabs(vv(satData->obsIndex)) > maxResGlo) {
1213 maxResGlo = fabs(vv(satData->obsIndex));
1214 prnGlo = prn;
1215 }
1216 }
1217 else {
1218 if (fabs(vv(satData->obsIndex)) > maxResGPS) {
1219 maxResGPS = fabs(vv(satData->obsIndex));
1220 prnGPS = prn;
1221 }
1222 }
[2792]1223 }
1224 }
1225}
1226
[3307]1227// Update Step (private - loop over outliers)
1228////////////////////////////////////////////////////////////////////////////
[3321]1229t_irc bncModel::update_p(t_epoData* epoData) {
[3307]1230
[3312]1231 Tracer tracer("bncModel::update_p");
1232
[3408]1233 // Save Variance-Covariance Matrix, and Status Vector
1234 // --------------------------------------------------
1235 rememberState(epoData);
[3307]1236
[3412]1237 QString lastOutlierPrn;
[3375]1238
[3408]1239 // Try with all satellites, then with all minus one, etc.
1240 // ------------------------------------------------------
[3412]1241 while (selectSatellites(lastOutlierPrn, epoData->satData) == success) {
[3307]1242
[3412]1243 QByteArray strResCode;
1244 QByteArray strResPhase;
1245
1246 // Bancroft Solution
1247 // -----------------
1248 if (cmpBancroft(epoData) != success) {
1249 break;
[3408]1250 }
[3406]1251
[3412]1252 // First update using code observations, then phase observations
1253 // -------------------------------------------------------------
1254 for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++) {
1255
1256 // Status Prediction
1257 // -----------------
1258 predict(iPhase, epoData);
1259
1260 // Create First-Design Matrix
1261 // --------------------------
1262 unsigned nPar = _params.size();
1263 unsigned nObs = 0;
1264 if (iPhase == 0) {
1265 nObs = epoData->sizeAll() - epoData->sizeSys('R'); // Glonass code not used
[3408]1266 }
[3412]1267 else {
1268 nObs = epoData->sizeAll();
[3409]1269 }
[3412]1270
1271 // Prepare first-design Matrix, vector observed-computed
1272 // -----------------------------------------------------
1273 Matrix AA(nObs, nPar); // first design matrix
1274 ColumnVector ll(nObs); // tems observed-computed
1275 DiagonalMatrix PP(nObs); PP = 0.0;
1276
1277 unsigned iObs = 0;
1278 QMapIterator<QString, t_satData*> it(epoData->satData);
1279 while (it.hasNext()) {
1280 it.next();
1281 t_satData* satData = it.value();
1282 if (iPhase == 1 || satData->system() != 'R') {
1283 QString prn = satData->prn;
1284 addObs(iPhase, iObs, satData, AA, ll, PP);
1285 }
[3408]1286 }
1287
[3412]1288 // Compute Filter Update
1289 // ---------------------
[3422]1290 ColumnVector dx;
[3412]1291 kalman(AA, ll, PP, _QQ, dx);
1292 ColumnVector vv = ll - AA * dx;
1293
1294 // Print Residuals
1295 // ---------------
1296 if (iPhase == 0) {
1297 strResCode = printRes(iPhase, vv, epoData->satData);
[3399]1298 }
[3412]1299 else {
1300 strResPhase = printRes(iPhase, vv, epoData->satData);
1301 }
[3408]1302
[3412]1303 // Check the residuals
1304 // -------------------
1305 lastOutlierPrn = outlierDetection(iPhase, vv, epoData->satData);
[3408]1306
[3412]1307 // No Outlier Detected
1308 // -------------------
1309 if (lastOutlierPrn.isEmpty()) {
[3413]1310
[3422]1311 QVectorIterator<bncParam*> itPar(_params);
1312 while (itPar.hasNext()) {
1313 bncParam* par = itPar.next();
1314 par->xx += dx(par->index);
1315 }
[3413]1316
[3422]1317 if (!_usePhase || iPhase == 1) {
[3413]1318 if (_outlierGPS.size() > 0 || _outlierGlo.size() > 0) {
1319 _log += "Neglected PRNs: ";
[3415]1320 if (!_outlierGPS.isEmpty()) {
1321 _log += _outlierGPS.last() + ' ';
[3413]1322 }
1323 QStringListIterator itGlo(_outlierGlo);
1324 while (itGlo.hasNext()) {
1325 QString prn = itGlo.next();
1326 _log += prn + ' ';
1327 }
1328 }
1329 _log += '\n';
1330
[3408]1331 _log += strResCode + strResPhase;
[3413]1332
[3408]1333 return success;
[3393]1334 }
[3412]1335 }
[3393]1336
[3412]1337 // Outlier Found
1338 // -------------
1339 else {
1340 restoreState(epoData);
1341 break;
1342 }
[3406]1343
[3412]1344 } // for iPhase
[3406]1345
[3412]1346 } // while selectSatellites
[3375]1347
[3412]1348 restoreState(epoData);
[3408]1349 return failure;
[3323]1350}
1351
1352// Remeber Original State Vector and Variance-Covariance Matrix
1353////////////////////////////////////////////////////////////////////////////
[3408]1354void bncModel::rememberState(t_epoData* epoData) {
[3323]1355
1356 _QQ_sav = _QQ;
1357
1358 QVectorIterator<bncParam*> itSav(_params_sav);
1359 while (itSav.hasNext()) {
1360 bncParam* par = itSav.next();
[3322]1361 delete par;
1362 }
[3323]1363 _params_sav.clear();
1364
1365 QVectorIterator<bncParam*> it(_params);
1366 while (it.hasNext()) {
1367 bncParam* par = it.next();
1368 _params_sav.push_back(new bncParam(*par));
1369 }
[3408]1370
1371 _epoData_sav->deepCopy(epoData);
[3307]1372}
[3323]1373
1374// Restore Original State Vector and Variance-Covariance Matrix
1375////////////////////////////////////////////////////////////////////////////
[3408]1376void bncModel::restoreState(t_epoData* epoData) {
[3323]1377
1378 _QQ = _QQ_sav;
1379
1380 QVectorIterator<bncParam*> it(_params);
1381 while (it.hasNext()) {
1382 bncParam* par = it.next();
1383 delete par;
1384 }
1385 _params.clear();
1386
1387 QVectorIterator<bncParam*> itSav(_params_sav);
1388 while (itSav.hasNext()) {
1389 bncParam* par = itSav.next();
1390 _params.push_back(new bncParam(*par));
1391 }
[3408]1392
1393 epoData->deepCopy(_epoData_sav);
[3405]1394}
[3412]1395
1396//
1397////////////////////////////////////////////////////////////////////////////
1398t_irc bncModel::selectSatellites(const QString& lastOutlierPrn,
1399 QMap<QString, t_satData*>& satData) {
1400
1401 // First Call
1402 // ----------
1403 if (lastOutlierPrn.isEmpty()) {
1404 _outlierGPS.clear();
1405 _outlierGlo.clear();
1406 return success;
1407 }
1408
1409 // Second and next trials
1410 // ----------------------
1411 else {
1412
1413 if (lastOutlierPrn[0] == 'R') {
1414 _outlierGlo << lastOutlierPrn;
1415 }
1416
1417 // Remove all Glonass Outliers
1418 // ---------------------------
1419 QStringListIterator it(_outlierGlo);
1420 while (it.hasNext()) {
1421 QString prn = it.next();
1422 if (satData.contains(prn)) {
1423 delete satData.take(prn);
1424 }
1425 }
1426
1427 if (lastOutlierPrn[0] == 'R') {
1428 _outlierGPS.clear();
1429 return success;
1430 }
1431
1432 // GPS Outlier appeared for the first time - try to delete it
1433 // ----------------------------------------------------------
1434 if (_outlierGPS.indexOf(lastOutlierPrn) == -1) {
1435 _outlierGPS << lastOutlierPrn;
1436 if (satData.contains(lastOutlierPrn)) {
1437 delete satData.take(lastOutlierPrn);
1438 }
1439 return success;
1440 }
1441
1442 }
1443
1444 return failure;
1445}
Note: See TracBrowser for help on using the repository browser.