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

Last change on this file since 3319 was 3319, checked in by mervart, 13 years ago
File size: 40.9 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
[2243]57const unsigned MINOBS = 4;
[2287]58const double MINELE_GPS = 10.0 * M_PI / 180.0;
59const double MINELE_GLO = 10.0 * M_PI / 180.0;
[2780]60const double MINELE_GAL = 10.0 * M_PI / 180.0;
[2243]61const double MAXRES_CODE_GPS = 10.0;
[3315]62const double MAXRES_PHASE_GPS = 0.05;
63const double MAXRES_PHASE_GLO = 0.05;
[2784]64const double MAXRES_CODE_GAL = 10.0;
[3315]65const double MAXRES_PHASE_GAL = 0.05;
[2070]66
[2057]67// Constructor
68////////////////////////////////////////////////////////////////////////////
[2080]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;
[2473]76
[2057]77}
78
79// Destructor
80////////////////////////////////////////////////////////////////////////////
81bncParam::~bncParam() {
82}
83
[2060]84// Partial
85////////////////////////////////////////////////////////////////////////////
[2239]86double bncParam::partial(t_satData* satData, bool phase) {
87
[3312]88 Tracer tracer("bncParam::partial");
89
[2239]90 // Coordinates
91 // -----------
[2060]92 if (type == CRD_X) {
[2109]93 return (xx - satData->xx(1)) / satData->rho;
[2060]94 }
95 else if (type == CRD_Y) {
[2109]96 return (xx - satData->xx(2)) / satData->rho;
[2060]97 }
98 else if (type == CRD_Z) {
[2109]99 return (xx - satData->xx(3)) / satData->rho;
[2060]100 }
[2239]101
102 // Receiver Clocks
103 // ---------------
[2265]104 else if (type == RECCLK) {
105 return 1.0;
[2060]106 }
[2239]107
108 // Troposphere
109 // -----------
[2084]110 else if (type == TROPO) {
111 return 1.0 / sin(satData->eleSat);
112 }
[2239]113
[2782]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
[2239]125 // Ambiguities
126 // -----------
[2080]127 else if (type == AMB_L3) {
[2239]128 if (phase && satData->prn == prn) {
[2080]129 return 1.0;
130 }
131 else {
132 return 0.0;
133 }
134 }
[2239]135
136 // Default return
137 // --------------
[2060]138 return 0.0;
139}
140
[2058]141// Constructor
142////////////////////////////////////////////////////////////////////////////
[2113]143bncModel::bncModel(QByteArray staID) {
[2084]144
[2113]145 _staID = staID;
146
[3107]147 connect(this, SIGNAL(newMessage(QByteArray,bool)),
148 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
149
[2648]150 bncSettings settings;
151
[2720]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()) {
[2741]160 _sigL3 = settings.value("pppSigmaPhase").toDouble();
[2720]161 }
[2648]162
[2720]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 }
[2782]181 _sigClk0 = 1000.0;
182 _sigAmb0 = 1000.0;
183 _sigGalileoOffset0 = 1000.0;
[2784]184 _sigGalileoOffsetP = 0.0;
[2648]185
[2720]186 // Quick-Start Mode
187 // ----------------
188 _quickStart = 0;
[2726]189 if (settings.value("pppRefCrdX").toString() != "" &&
190 settings.value("pppRefCrdY").toString() != "" &&
191 settings.value("pppRefCrdZ").toString() != "" &&
[2720]192 !settings.value("pppQuickStart").toString().isEmpty()) {
[2745]193 _quickStart = settings.value("pppQuickStart").toDouble();
[2720]194 }
195
[3107]196 // Several options
197 // ---------------
[2084]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
[3107]208 _useGalileo = false;
[2799]209 if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
[3107]210 _useGalileo = true;
[2782]211 }
[2073]212
[2125]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 }
[2881]232
[3107]233 // Antenna Name, ANTEX File
234 // ------------------------
[2896]235 _antex = 0;
[2881]236 QString antexFileName = settings.value("pppAntex").toString();
237 if (!antexFileName.isEmpty()) {
238 _antex = new bncAntex();
[2883]239 if (_antex->readFile(antexFileName) != success) {
[2938]240 emit newMessage("wrong ANTEX file", true);
[2887]241 delete _antex;
242 _antex = 0;
[2883]243 }
[2938]244 else {
245 _antennaName = settings.value("pppAntenna").toString();
246 }
[2881]247 }
[3107]248
[3286]249 // Antenna Eccentricities
250 // ----------------------
251 _dN = settings.value("pppRefdN").toDouble();
252 _dE = settings.value("pppRefdE").toDouble();
253 _dU = settings.value("pppRefdU").toDouble();
254
[3107]255 // Bancroft Coordinates
256 // --------------------
257 _xcBanc.ReSize(4); _xcBanc = 0.0;
258 _ellBanc.ReSize(3); _ellBanc = 0.0;
[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
[2231]324 if (epoData->sizeGPS() < MINOBS) {
[2547]325 _log += "bncModel::cmpBancroft: not enough data\n";
[2058]326 return failure;
327 }
328
[2231]329 Matrix BB(epoData->sizeGPS(), 4);
[2058]330
[2231]331 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
[2791]332 int iObsBanc = 0;
[2058]333 while (it.hasNext()) {
[2791]334 ++iObsBanc;
[2058]335 it.next();
336 QString prn = it.key();
337 t_satData* satData = it.value();
[2791]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;
[2058]342 }
343
344 bancroft(BB, _xcBanc);
345
[2064]346 // Ellipsoidal Coordinates
347 // ------------------------
348 xyz2ell(_xcBanc.data(), _ellBanc.data());
[2063]349
[2064]350 // Compute Satellite Elevations
351 // ----------------------------
[2231]352 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
353 while (iGPS.hasNext()) {
354 iGPS.next();
355 t_satData* satData = iGPS.value();
[2789]356 cmpEle(satData);
[2287]357 if (satData->eleSat < MINELE_GPS) {
[2070]358 delete satData;
[2231]359 iGPS.remove();
[2070]360 }
[2064]361 }
362
[2231]363 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
364 while (iGlo.hasNext()) {
365 iGlo.next();
366 t_satData* satData = iGlo.value();
[2789]367 cmpEle(satData);
[2287]368 if (satData->eleSat < MINELE_GLO) {
[2231]369 delete satData;
370 iGlo.remove();
371 }
372 }
373
[2780]374 QMutableMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
375 while (iGal.hasNext()) {
376 iGal.next();
377 t_satData* satData = iGal.value();
[2789]378 cmpEle(satData);
[2780]379 if (satData->eleSat < MINELE_GAL) {
380 delete satData;
381 iGal.remove();
382 }
383 }
384
[2058]385 return success;
386}
[2060]387
388// Computed Value
389////////////////////////////////////////////////////////////////////////////
[2583]390double bncModel::cmpValue(t_satData* satData, bool phase) {
[2060]391
[3312]392 Tracer tracer("bncModel::cmpValue");
393
[2073]394 ColumnVector xRec(3);
395 xRec(1) = x();
396 xRec(2) = y();
397 xRec(3) = z();
[2060]398
[2073]399 double rho0 = (satData->xx - xRec).norm_Frobenius();
[2060]400 double dPhi = t_CST::omega * rho0 / t_CST::c;
401
[2073]402 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
403 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
404 xRec(3) = z();
405
[2580]406 tides(_time, xRec);
407
[2060]408 satData->rho = (satData->xx - xRec).norm_Frobenius();
409
[2084]410 double tropDelay = delay_saast(satData->eleSat) +
411 trp() / sin(satData->eleSat);
[2060]412
[2583]413 double wind = 0.0;
414 if (phase) {
415 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
416 }
417
[2783]418 double offset = 0.0;
419 if (satData->prn[0] == 'E') {
420 offset = Galileo_offset();
421 }
422
[2894]423 double phaseCenter = 0.0;
[2938]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 }
[2894]431 }
432
[3286]433 double antennaOffset = 0.0;
434 if (_dN != 0.0 || _dE != 0.0 || _dU != 0.0) {
[3287]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;
[3286]440 }
441
442 return satData->rho + phaseCenter + antennaOffset + clk()
[2894]443 + offset - satData->clk + tropDelay + wind;
[2060]444}
445
[2063]446// Tropospheric Model (Saastamoinen)
447////////////////////////////////////////////////////////////////////////////
[2065]448double bncModel::delay_saast(double Ele) {
[2063]449
[3312]450 Tracer tracer("bncModel::delay_saast");
451
[2769]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];
[2063]459
[2064]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);
[2063]463 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
464
[2064]465 double h_km = height / 1000.0;
[2063]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
[2073]487// Prediction Step of the Filter
488////////////////////////////////////////////////////////////////////////////
[3309]489void bncModel::predict(int iPhase, t_epoData* epoData) {
[2073]490
[3312]491 Tracer tracer("bncModel::predict");
492
[3310]493 if (iPhase == 0) {
[2244]494
[3310]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 }
[3106]514
[3310]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 }
[2648]532 }
[3310]533 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]534 }
[3310]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 }
[2648]545 }
[3310]546 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]547 }
[3310]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 }
[2648]558 }
[3310]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;
[2648]568 }
[3310]569 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
[2244]570 }
[3310]571
572 // Tropospheric Delay
573 // ------------------
574 else if (pp->type == bncParam::TROPO) {
575 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
[2244]576 }
[3310]577
578 // Galileo Offset
579 // --------------
580 else if (pp->type == bncParam::GALILEO_OFFSET) {
581 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
582 }
[2244]583 }
584 }
585
586 // Add New Ambiguities if necessary
587 // --------------------------------
[2083]588 if (_usePhase) {
[2080]589
[2083]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) {
[2231]607 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
[2780]608 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() &&
609 epoData->satDataGal.find(par->prn) == epoData->satDataGal.end() ) {
[2083]610 removed = true;
611 delete par;
612 it.remove();
613 }
[2080]614 }
[2083]615 if (! removed) {
616 ++iPar;
617 par->index = iPar;
618 }
[2080]619 }
[2083]620
621 // Add new ambiguity parameters
622 // ----------------------------
[2231]623 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
624 while (iGPS.hasNext()) {
625 iGPS.next();
[2244]626 t_satData* satData = iGPS.value();
[2789]627 addAmb(satData);
[2080]628 }
[2231]629
630 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
631 while (iGlo.hasNext()) {
632 iGlo.next();
[2233]633 t_satData* satData = iGlo.value();
[2789]634 addAmb(satData);
[2231]635 }
[2780]636
637 QMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
638 while (iGal.hasNext()) {
639 iGal.next();
640 t_satData* satData = iGal.value();
[2789]641 addAmb(satData);
[2780]642 }
[2083]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 }
[2080]655 }
656 }
657 }
[2083]658
659 for (int ii = 1; ii <= nPar; ii++) {
660 bncParam* par = _params[ii-1];
661 if (par->index_old == 0) {
[2720]662 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
[2083]663 }
664 par->index_old = par->index;
[2080]665 }
666 }
[2073]667}
668
[2060]669// Update Step of the Filter (currently just a single-epoch solution)
670////////////////////////////////////////////////////////////////////////////
671t_irc bncModel::update(t_epoData* epoData) {
672
[3312]673 Tracer tracer("bncModel::update");
674
[2473]675 bncSettings settings;
676
[2248]677 _log.clear();
[2124]678
[2827]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()) +
[2547]687 "\n--------------------------------------------------------------\n";
[2827]688 }
[2547]689
[3307]690 // Outlier Detection Loop
[2113]691 // ----------------------
[3307]692 ColumnVector dx;
693 if (update_p(epoData, dx) != success) {
694 return failure;
695 }
[2080]696
[2670]697 // Remember the Epoch-specific Results for the computation of means
698 // ----------------------------------------------------------------
699 pppPos* newPos = new pppPos;
700 newPos->time = epoData->tt;
701
[2109]702 // Set Solution Vector
703 // -------------------
[2265]704 ostringstream strB;
705 strB.setf(ios::fixed);
[2073]706 QVectorIterator<bncParam*> itPar(_params);
[2060]707 while (itPar.hasNext()) {
708 bncParam* par = itPar.next();
[2109]709 par->xx += dx(par->index);
[2265]710
711 if (par->type == bncParam::RECCLK) {
[2798]712 strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
[2124]713 << " +- " << setw(6) << setprecision(3)
714 << sqrt(_QQ(par->index,par->index));
715 }
716 else if (par->type == bncParam::AMB_L3) {
[2265]717 strB << "\n amb " << par->prn.toAscii().data() << " = "
[2798]718 << setw(10) << setprecision(3) << par->xx
[2124]719 << " +- " << setw(6) << setprecision(3)
720 << sqrt(_QQ(par->index,par->index));
721 }
[2212]722 else if (par->type == bncParam::TROPO) {
[2670]723 double aprTrp = delay_saast(M_PI/2.0);
[2547]724 strB << "\n trp = " << par->prn.toAscii().data()
[2670]725 << setw(7) << setprecision(3) << aprTrp << " "
[2213]726 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
[2212]727 << " +- " << setw(6) << setprecision(3)
728 << sqrt(_QQ(par->index,par->index));
[2670]729 newPos->xnt[6] = aprTrp + par->xx;
[2212]730 }
[2782]731 else if (par->type == bncParam::GALILEO_OFFSET) {
[2798]732 strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
[2782]733 << " +- " << setw(6) << setprecision(3)
734 << sqrt(_QQ(par->index,par->index));
735 }
[2060]736 }
[2265]737 strB << '\n';
[2547]738 _log += strB.str().c_str();
739 emit newMessage(_log, false);
[2060]740
[2547]741 // Final Message (both log file and screen)
742 // ----------------------------------------
743 ostringstream strC;
744 strC.setf(ios::fixed);
745 strC << _staID.data() << " PPP "
[2599]746 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
[2231]747 << setw(14) << setprecision(3) << x() << " +- "
748 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
749 << setw(14) << setprecision(3) << y() << " +- "
750 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
751 << setw(14) << setprecision(3) << z() << " +- "
[2124]752 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
[2113]753
[2370]754 // NEU Output
755 // ----------
[2862]756 double xyzRef[3];
757
[2726]758 if (settings.value("pppRefCrdX").toString() != "" &&
759 settings.value("pppRefCrdY").toString() != "" &&
760 settings.value("pppRefCrdZ").toString() != "") {
[2649]761
[2370]762 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
763 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
764 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
[2649]765
[2670]766 newPos->xnt[0] = x() - xyzRef[0];
767 newPos->xnt[1] = y() - xyzRef[1];
768 newPos->xnt[2] = z() - xyzRef[2];
[2649]769
770 double ellRef[3];
[2370]771 xyz2ell(xyzRef, ellRef);
[2670]772 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
[2649]773
[2547]774 strC << " NEU "
[2670]775 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
776 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
[2797]777 << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
[2649]778
[2370]779 }
780
[2547]781 emit newMessage(QByteArray(strC.str().c_str()), true);
782
[2671]783 if (settings.value("pppAverage").toString() == "") {
784 delete newPos;
785 }
786 else {
787
788 _posAverage.push_back(newPos);
[2599]789
[2648]790 // Time Span for Average Computation
791 // ---------------------------------
792 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
793 if (tRangeAverage < 0) {
794 tRangeAverage = 0;
795 }
796 if (tRangeAverage > 86400) {
797 tRangeAverage = 86400;
798 }
[2599]799
[2648]800 // Compute the Mean
801 // ----------------
[2670]802 ColumnVector mean(7); mean = 0.0;
[2648]803
[2599]804 QMutableVectorIterator<pppPos*> it(_posAverage);
805 while (it.hasNext()) {
806 pppPos* pp = it.next();
[2648]807 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
[2599]808 delete pp;
809 it.remove();
810 }
[2648]811 else {
[2670]812 for (int ii = 0; ii < 7; ++ii) {
813 mean[ii] += pp->xnt[ii];
[2649]814 }
[2648]815 }
[2599]816 }
[2648]817
818 int nn = _posAverage.size();
819
[2649]820 if (nn > 0) {
[2648]821
[2649]822 mean /= nn;
823
824 // Compute the Deviation
825 // ---------------------
[2670]826 ColumnVector std(7); std = 0.0;
[2649]827 QVectorIterator<pppPos*> it2(_posAverage);
828 while (it2.hasNext()) {
829 pppPos* pp = it2.next();
[2670]830 for (int ii = 0; ii < 7; ++ii) {
831 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
[2649]832 }
833 }
[2670]834 for (int ii = 0; ii < 7; ++ii) {
[2649]835 std[ii] = sqrt(std[ii] / nn);
836 }
[3169]837
838 if (settings.value("pppRefCrdX").toString() != "" &&
839 settings.value("pppRefCrdY").toString() != "" &&
840 settings.value("pppRefCrdZ").toString() != "") {
[2649]841
[3169]842 ostringstream strD; strD.setf(ios::fixed);
843 strD << _staID.data() << " AVE-XYZ "
844 << epoData->tt.timestr(1) << " "
845 << setw(13) << setprecision(3) << mean[0] + xyzRef[0] << " +- "
846 << setw(6) << setprecision(3) << std[0] << " "
847 << setw(14) << setprecision(3) << mean[1] + xyzRef[1] << " +- "
848 << setw(6) << setprecision(3) << std[1] << " "
849 << setw(14) << setprecision(3) << mean[2] + xyzRef[2] << " +- "
850 << setw(6) << setprecision(3) << std[2];
851 emit newMessage(QByteArray(strD.str().c_str()), true);
[2649]852
[3169]853 ostringstream strE; strE.setf(ios::fixed);
854 strE << _staID.data() << " AVE-NEU "
855 << epoData->tt.timestr(1) << " "
856 << setw(13) << setprecision(3) << mean[3] << " +- "
857 << setw(6) << setprecision(3) << std[3] << " "
858 << setw(14) << setprecision(3) << mean[4] << " +- "
859 << setw(6) << setprecision(3) << std[4] << " "
860 << setw(14) << setprecision(3) << mean[5] << " +- "
861 << setw(6) << setprecision(3) << std[5];
862 emit newMessage(QByteArray(strE.str().c_str()), true);
[2649]863
[3169]864 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
865 ostringstream strF; strF.setf(ios::fixed);
866 strF << _staID.data() << " AVE-TRP "
867 << epoData->tt.timestr(1) << " "
868 << setw(13) << setprecision(3) << mean[6] << " +- "
869 << setw(6) << setprecision(3) << std[6] << endl;
870 emit newMessage(QByteArray(strF.str().c_str()), true);
871 }
[2726]872 }
[2599]873 }
874 }
875
[2131]876 // NMEA Output
877 // -----------
[2181]878 double xyz[3];
879 xyz[0] = x();
880 xyz[1] = y();
881 xyz[2] = z();
882 double ell[3];
883 xyz2ell(xyz, ell);
884 double phiDeg = ell[0] * 180 / M_PI;
885 double lamDeg = ell[1] * 180 / M_PI;
[2132]886
[2181]887 char phiCh = 'N';
888 if (phiDeg < 0) {
889 phiDeg = -phiDeg;
890 phiCh = 'S';
891 }
892 char lamCh = 'E';
893 if (lamDeg < 0) {
[2563]894 lamDeg = -lamDeg;
895 lamCh = 'W';
[2181]896 }
[2132]897
[2566]898 string datestr = epoData->tt.datestr(0); // yyyymmdd
899 ostringstream strRMC;
900 strRMC.setf(ios::fixed);
901 strRMC << "GPRMC,"
902 << epoData->tt.timestr(0,0) << ",A,"
903 << setw(2) << setfill('0') << int(phiDeg)
904 << setw(6) << setprecision(3) << setfill('0')
905 << fmod(60*phiDeg,60) << ',' << phiCh << ','
906 << setw(3) << setfill('0') << int(lamDeg)
907 << setw(6) << setprecision(3) << setfill('0')
908 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
[2569]909 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
910 << datestr[2] << datestr[3] << ",,";
[2566]911
912 writeNMEAstr(QString(strRMC.str().c_str()));
913
[2181]914 double dop = 2.0; // TODO
[2133]915
[2566]916 ostringstream strGGA;
917 strGGA.setf(ios::fixed);
918 strGGA << "GPGGA,"
919 << epoData->tt.timestr(0,0) << ','
920 << setw(2) << setfill('0') << int(phiDeg)
921 << setw(10) << setprecision(7) << setfill('0')
922 << fmod(60*phiDeg,60) << ',' << phiCh << ','
923 << setw(3) << setfill('0') << int(lamDeg)
924 << setw(10) << setprecision(7) << setfill('0')
925 << fmod(60*lamDeg,60) << ',' << lamCh
926 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
927 << setw(3) << setprecision(1) << dop << ','
[2569]928 << setprecision(3) << ell[2] << ",M,0.0,M,,";
[2181]929
[2566]930 writeNMEAstr(QString(strGGA.str().c_str()));
[2131]931
[3106]932 _lastTimeOK = _time; // remember time of last successful update
[2060]933 return success;
934}
[2112]935
936// Outlier Detection
937////////////////////////////////////////////////////////////////////////////
[3309]938int bncModel::outlierDetection(int iPhase, const SymmetricMatrix& QQsav,
[2112]939 const ColumnVector& vv,
[2231]940 QMap<QString, t_satData*>& satDataGPS,
[2780]941 QMap<QString, t_satData*>& satDataGlo,
942 QMap<QString, t_satData*>& satDataGal) {
[2112]943
[3312]944 Tracer tracer("bncModel::outlierDetection");
945
[2792]946 QString prnCode;
947 QString prnPhase;
948 double maxResCode = 0.0;
949 double maxResPhase = 0.0;
[2231]950
[2792]951 QString prnRemoved;
952 double maxRes;
[2112]953
[2793]954 int irc = 0;
955
[3309]956 if (iPhase == 0) {
[3281]957
[3308]958 // Check GPS Code
959 // --------------
960 if (irc == 0) {
[3313]961 findMaxRes(iPhase, vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]962 if (maxResCode > MAXRES_CODE_GPS) {
963 satDataGPS.remove(prnCode);
964 prnRemoved = prnCode;
965 maxRes = maxResCode;
966 irc = 1;
967 }
[3281]968 }
[3308]969
970 // Check Galileo Code
971 // ------------------
972 if (irc == 0) {
[3313]973 findMaxRes(iPhase, vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]974 if (maxResCode > MAXRES_CODE_GAL) {
975 satDataGal.remove(prnCode);
976 prnRemoved = prnCode;
977 maxRes = maxResCode;
978 irc = 1;
979 }
[2793]980 }
[2792]981 }
[2112]982
[3308]983 else {
[3309]984
[3308]985 // Check Glonass Phase
986 // -------------------
987 if (irc == 0) {
[3313]988 findMaxRes(iPhase, vv,satDataGlo, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]989 if (maxResPhase > MAXRES_PHASE_GLO) {
990 satDataGlo.remove(prnPhase);
991 prnRemoved = prnPhase;
992 maxRes = maxResPhase;
993 irc = 1;
994 }
[2112]995 }
[3308]996
997 // Check Galileo Phase
998 // -------------------
999 if (irc == 0) {
[3313]1000 findMaxRes(iPhase, vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]1001 if (maxResPhase > MAXRES_PHASE_GAL) {
1002 satDataGal.remove(prnPhase);
1003 prnRemoved = prnPhase;
1004 maxRes = maxResPhase;
1005 irc = 1;
1006 }
[2780]1007 }
[3308]1008
1009 // Check GPS Phase
1010 // ---------------
1011 if (irc == 0) {
[3313]1012 findMaxRes(iPhase, vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]1013 if (maxResPhase > MAXRES_PHASE_GPS) {
1014 satDataGPS.remove(prnPhase);
1015 prnRemoved = prnPhase;
1016 maxRes = maxResPhase;
1017 irc = 1;
1018 }
1019 }
[2780]1020 }
1021
[2793]1022 if (irc != 0) {
[2792]1023 _log += "Outlier " + prnRemoved.toAscii() + " "
1024 + QByteArray::number(maxRes, 'f', 3) + "\n";
[2248]1025 _QQ = QQsav;
1026 }
[2793]1027
1028 return irc;
[2112]1029}
[2130]1030
1031//
1032////////////////////////////////////////////////////////////////////////////
1033void bncModel::writeNMEAstr(const QString& nmStr) {
1034
[3312]1035 Tracer tracer("bncModel::writeNMEAstr");
1036
[2130]1037 unsigned char XOR = 0;
1038 for (int ii = 0; ii < nmStr.length(); ii++) {
1039 XOR ^= (unsigned char) nmStr[ii].toAscii();
1040 }
[2181]1041
1042 QString outStr = '$' + nmStr
1043 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
[2130]1044
[2178]1045 if (_nmeaStream) {
[2181]1046 *_nmeaStream << outStr;
[2178]1047 _nmeaStream->flush();
1048 }
[2130]1049
[2181]1050 emit newNMEAstr(outStr.toAscii());
[2130]1051}
[2283]1052
1053////
1054//////////////////////////////////////////////////////////////////////////////
1055void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1056 const DiagonalMatrix& PP,
1057 SymmetricMatrix& QQ, ColumnVector& dx) {
1058
[3312]1059 Tracer tracer("bncModel::kalman");
1060
[2283]1061 int nObs = AA.Nrows();
1062 int nPar = AA.Ncols();
1063
1064 UpperTriangularMatrix SS = Cholesky(QQ).t();
1065
1066 Matrix SA = SS*AA.t();
1067 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
1068 for (int ii = 1; ii <= nObs; ++ii) {
1069 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
1070 }
1071
1072 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
1073 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
1074
1075 UpperTriangularMatrix UU;
1076 QRZ(SRF, UU);
1077
1078 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
1079 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
1080 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
1081
1082 UpperTriangularMatrix SHi = SH_rt.i();
1083
1084 Matrix KT = SHi * YY;
1085 SymmetricMatrix Hi; Hi << SHi * SHi.t();
1086
1087 dx = KT.t() * ll;
1088 QQ << (SS.t() * SS);
1089}
[2582]1090
1091// Phase Wind-Up Correction
1092///////////////////////////////////////////////////////////////////////////
1093double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1094 const ColumnVector& rRec) {
1095
[3312]1096 Tracer tracer("bncModel::windUp");
1097
[2582]1098 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1099
1100 // First time - initialize to zero
1101 // -------------------------------
1102 if (!_windUpTime.contains(prn)) {
1103 _windUpSum[prn] = 0.0;
1104 }
1105
1106 // Compute the correction for new time
1107 // -----------------------------------
[2942]1108 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
[2582]1109 _windUpTime[prn] = Mjd;
1110
1111 // Unit Vector GPS Satellite --> Receiver
1112 // --------------------------------------
1113 ColumnVector rho = rRec - rSat;
1114 rho /= rho.norm_Frobenius();
1115
1116 // GPS Satellite unit Vectors sz, sy, sx
1117 // -------------------------------------
1118 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1119
1120 ColumnVector xSun = Sun(Mjd);
1121 xSun /= xSun.norm_Frobenius();
1122
1123 ColumnVector sy = crossproduct(sz, xSun);
1124 ColumnVector sx = crossproduct(sy, sz);
1125
1126 // Effective Dipole of the GPS Satellite Antenna
1127 // ---------------------------------------------
1128 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1129 - crossproduct(rho, sy);
1130
1131 // Receiver unit Vectors rx, ry
1132 // ----------------------------
1133 ColumnVector rx(3);
1134 ColumnVector ry(3);
1135
1136 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1137 double neu[3];
1138
1139 neu[0] = 1.0;
1140 neu[1] = 0.0;
1141 neu[2] = 0.0;
1142 neu2xyz(recEll, neu, rx.data());
1143
1144 neu[0] = 0.0;
1145 neu[1] = -1.0;
1146 neu[2] = 0.0;
1147 neu2xyz(recEll, neu, ry.data());
1148
1149 // Effective Dipole of the Receiver Antenna
1150 // ----------------------------------------
1151 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1152 + crossproduct(rho, ry);
1153
1154 // Resulting Effect
1155 // ----------------
1156 double alpha = DotProduct(dipSat,dipRec) /
1157 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1158
1159 if (alpha > 1.0) alpha = 1.0;
1160 if (alpha < -1.0) alpha = -1.0;
1161
1162 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1163
1164 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1165 dphi = -dphi;
1166 }
1167
1168 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1169 }
1170
1171 return _windUpSum[prn];
1172}
[2789]1173
1174//
1175///////////////////////////////////////////////////////////////////////////
1176void bncModel::cmpEle(t_satData* satData) {
[3312]1177 Tracer tracer("bncModel::cmpEle");
[2789]1178 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
1179 double rho = rr.norm_Frobenius();
1180
1181 double neu[3];
1182 xyz2neu(_ellBanc.data(), rr.data(), neu);
1183
1184 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
1185 if (neu[2] < 0) {
1186 satData->eleSat *= -1.0;
1187 }
1188 satData->azSat = atan2(neu[1], neu[0]);
1189}
1190
1191//
1192///////////////////////////////////////////////////////////////////////////
1193void bncModel::addAmb(t_satData* satData) {
[3312]1194 Tracer tracer("bncModel::addAmb");
[2789]1195 bool found = false;
1196 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1197 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1198 _params[iPar-1]->prn == satData->prn) {
1199 found = true;
1200 break;
1201 }
1202 }
1203 if (!found) {
1204 bncParam* par = new bncParam(bncParam::AMB_L3,
1205 _params.size()+1, satData->prn);
1206 _params.push_back(par);
1207 par->xx = satData->L3 - cmpValue(satData, true);
1208 }
1209}
[2790]1210
1211//
1212///////////////////////////////////////////////////////////////////////////
[3309]1213void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
[2790]1214 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1215
[3312]1216 Tracer tracer("bncModel::addObs");
1217
[3316]1218 const double ELEWGHT = 20.0;
[3314]1219 double ellWgtCoef = 1.0;
1220 double eleD = satData->eleSat * 180.0 / M_PI;
1221 if (eleD < ELEWGHT) {
[3317]1222 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
[3314]1223 }
1224
[2791]1225 // Phase Observations
1226 // ------------------
[3309]1227 if (iPhase == 1) {
[2790]1228 ++iObs;
1229 ll(iObs) = satData->L3 - cmpValue(satData, true);
[3314]1230 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3) / (ellWgtCoef * ellWgtCoef);
[3319]1231 if (satData->system() == 'R') {
1232 PP(iObs,iObs) /= 4.0;
1233 }
[2790]1234 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1235 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1236 _params[iPar-1]->prn == satData->prn) {
1237 ll(iObs) -= _params[iPar-1]->xx;
1238 }
1239 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
1240 }
[2791]1241 satData->indexPhase = iObs;
[2790]1242 }
[3307]1243
1244 // Code Observations
1245 // -----------------
1246 else {
1247 ++iObs;
1248 ll(iObs) = satData->P3 - cmpValue(satData, false);
[3314]1249 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3) / (ellWgtCoef * ellWgtCoef);
[3307]1250 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1251 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
1252 }
1253 satData->indexCode = iObs;
1254 }
[2790]1255}
[2791]1256
1257//
1258///////////////////////////////////////////////////////////////////////////
[3309]1259void bncModel::printRes(int iPhase, const ColumnVector& vv,
[2791]1260 ostringstream& str, t_satData* satData) {
[3312]1261 Tracer tracer("bncModel::printRes");
[3309]1262 if (iPhase == 1) {
[2797]1263 str << _time.timestr(1)
[2800]1264 << " RES " << satData->prn.toAscii().data() << " L3 "
[3307]1265 << setw(9) << setprecision(4) << vv(satData->indexPhase) << endl;
[2791]1266 }
[3308]1267 else {
[3307]1268 str << _time.timestr(1)
1269 << " RES " << satData->prn.toAscii().data() << " P3 "
1270 << setw(9) << setprecision(4) << vv(satData->indexCode) << endl;
1271 }
[2791]1272}
[2792]1273
1274//
1275///////////////////////////////////////////////////////////////////////////
[3313]1276void bncModel::findMaxRes(int iPhase, const ColumnVector& vv,
[2792]1277 const QMap<QString, t_satData*>& satData,
1278 QString& prnCode, double& maxResCode,
1279 QString& prnPhase, double& maxResPhase) {
[3312]1280 Tracer tracer("bncModel::findMaxRes");
[2792]1281 maxResCode = 0.0;
1282 maxResPhase = 0.0;
1283
1284 QMapIterator<QString, t_satData*> it(satData);
1285 while (it.hasNext()) {
1286 it.next();
1287 t_satData* satData = it.value();
[3313]1288 if (iPhase == 0) {
1289 if (satData->indexCode) {
1290 if (fabs(vv(satData->indexCode)) > maxResCode) {
1291 maxResCode = fabs(vv(satData->indexCode));
1292 prnCode = satData->prn;
1293 }
[2792]1294 }
1295 }
[3313]1296 else {
1297 if (satData->indexPhase) {
1298 if (fabs(vv(satData->indexPhase)) > maxResPhase) {
1299 maxResPhase = fabs(vv(satData->indexPhase));
1300 prnPhase = satData->prn;
1301 }
[2792]1302 }
1303 }
1304 }
1305}
1306
[3307]1307// Update Step (private - loop over outliers)
1308////////////////////////////////////////////////////////////////////////////
1309t_irc bncModel::update_p(t_epoData* epoData, ColumnVector& dx) {
1310
[3312]1311 Tracer tracer("bncModel::update_p");
1312
[3307]1313 SymmetricMatrix QQsav;
1314 ColumnVector vv;
1315
[3308]1316 for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++) {
[3307]1317
1318 do {
1319
[3309]1320 // Bancroft Solution
1321 // -----------------
[3307]1322 if (iPhase == 0) {
1323 if (cmpBancroft(epoData) != success) {
1324 emit newMessage(_log, false);
1325 return failure;
1326 }
1327 }
1328
[3308]1329 // Status Prediction
1330 // -----------------
[3309]1331 predict(iPhase, epoData);
[3308]1332
[3307]1333 // Create First-Design Matrix
1334 // --------------------------
1335 unsigned nPar = _params.size();
1336 unsigned nObs = 0;
[3308]1337 if (iPhase == 0) {
1338 nObs = epoData->sizeGPS() + epoData->sizeGal(); // Glonass code not used
1339 }
1340 else {
1341 nObs = epoData->sizeGPS() + epoData->sizeGal() + epoData->sizeGlo();
1342 }
[3307]1343
1344 Matrix AA(nObs, nPar); // first design matrix
1345 ColumnVector ll(nObs); // tems observed-computed
1346 DiagonalMatrix PP(nObs); PP = 0.0;
1347
1348 unsigned iObs = 0;
1349
1350 // GPS
1351 // ---
1352 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
1353 while (itGPS.hasNext()) {
1354 itGPS.next();
1355 t_satData* satData = itGPS.value();
1356 addObs(iPhase, iObs, satData, AA, ll, PP);
1357 }
1358
[3308]1359 // Glonass
1360 // -------
1361 if (iPhase == 1) {
1362 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
1363 while (itGlo.hasNext()) {
1364 itGlo.next();
1365 t_satData* satData = itGlo.value();
1366 addObs(iPhase, iObs, satData, AA, ll, PP);
1367 }
1368 }
1369
[3307]1370 // Galileo
1371 // -------
1372 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
1373 while (itGal.hasNext()) {
1374 itGal.next();
1375 t_satData* satData = itGal.value();
1376 addObs(iPhase, iObs, satData, AA, ll, PP);
1377 }
1378
1379 // Compute Filter Update
1380 // ---------------------
1381 QQsav = _QQ;
1382
1383 kalman(AA, ll, PP, _QQ, dx);
1384
1385 vv = ll - AA * dx;
[3308]1386
[3307]1387 // Print Residuals
1388 // ---------------
1389 if (true) {
1390 ostringstream str;
1391 str.setf(ios::fixed);
1392
1393 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
1394 while (itGPS.hasNext()) {
1395 itGPS.next();
1396 t_satData* satData = itGPS.value();
[3308]1397 printRes(iPhase, vv, str, satData);
[3307]1398 }
[3308]1399 if (iPhase == 1) {
1400 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
1401 while (itGlo.hasNext()) {
1402 itGlo.next();
1403 t_satData* satData = itGlo.value();
1404 printRes(iPhase, vv, str, satData);
1405 }
[3307]1406 }
1407 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
1408 while (itGal.hasNext()) {
1409 itGal.next();
1410 t_satData* satData = itGal.value();
[3308]1411 printRes(iPhase, vv, str, satData);
[3307]1412 }
1413 _log += str.str().c_str();
1414 }
1415
[3308]1416 } while (outlierDetection(iPhase, QQsav, vv, epoData->satDataGPS,
[3307]1417 epoData->satDataGlo, epoData->satDataGal) != 0);
1418 }
1419
1420 return success;
1421}
Note: See TracBrowser for help on using the repository browser.