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

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