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

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