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
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
[3322]57const unsigned MINOBS = 5;
[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 // ----------------------
[3321]692 if (update_p(epoData) != success) {
[3307]693 return failure;
694 }
[2080]695
[2670]696 // Remember the Epoch-specific Results for the computation of means
697 // ----------------------------------------------------------------
698 pppPos* newPos = new pppPos;
699 newPos->time = epoData->tt;
700
[2109]701 // Set Solution Vector
702 // -------------------
[2265]703 ostringstream strB;
704 strB.setf(ios::fixed);
[2073]705 QVectorIterator<bncParam*> itPar(_params);
[2060]706 while (itPar.hasNext()) {
707 bncParam* par = itPar.next();
[2265]708
709 if (par->type == bncParam::RECCLK) {
[2798]710 strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
[2124]711 << " +- " << setw(6) << setprecision(3)
712 << sqrt(_QQ(par->index,par->index));
713 }
714 else if (par->type == bncParam::AMB_L3) {
[2265]715 strB << "\n amb " << par->prn.toAscii().data() << " = "
[2798]716 << setw(10) << setprecision(3) << par->xx
[2124]717 << " +- " << setw(6) << setprecision(3)
718 << sqrt(_QQ(par->index,par->index));
719 }
[2212]720 else if (par->type == bncParam::TROPO) {
[2670]721 double aprTrp = delay_saast(M_PI/2.0);
[2547]722 strB << "\n trp = " << par->prn.toAscii().data()
[2670]723 << setw(7) << setprecision(3) << aprTrp << " "
[2213]724 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
[2212]725 << " +- " << setw(6) << setprecision(3)
726 << sqrt(_QQ(par->index,par->index));
[2670]727 newPos->xnt[6] = aprTrp + par->xx;
[2212]728 }
[2782]729 else if (par->type == bncParam::GALILEO_OFFSET) {
[2798]730 strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
[2782]731 << " +- " << setw(6) << setprecision(3)
732 << sqrt(_QQ(par->index,par->index));
733 }
[2060]734 }
[2265]735 strB << '\n';
[2547]736 _log += strB.str().c_str();
737 emit newMessage(_log, false);
[2060]738
[2547]739 // Final Message (both log file and screen)
740 // ----------------------------------------
741 ostringstream strC;
742 strC.setf(ios::fixed);
743 strC << _staID.data() << " PPP "
[2599]744 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
[2231]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() << " +- "
[2124]750 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
[2113]751
[2370]752 // NEU Output
753 // ----------
[2862]754 double xyzRef[3];
755
[2726]756 if (settings.value("pppRefCrdX").toString() != "" &&
757 settings.value("pppRefCrdY").toString() != "" &&
758 settings.value("pppRefCrdZ").toString() != "") {
[2649]759
[2370]760 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
761 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
762 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
[2649]763
[2670]764 newPos->xnt[0] = x() - xyzRef[0];
765 newPos->xnt[1] = y() - xyzRef[1];
766 newPos->xnt[2] = z() - xyzRef[2];
[2649]767
768 double ellRef[3];
[2370]769 xyz2ell(xyzRef, ellRef);
[2670]770 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
[2649]771
[2547]772 strC << " NEU "
[2670]773 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
774 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
[2797]775 << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
[2649]776
[2370]777 }
778
[2547]779 emit newMessage(QByteArray(strC.str().c_str()), true);
780
[2671]781 if (settings.value("pppAverage").toString() == "") {
782 delete newPos;
783 }
784 else {
785
786 _posAverage.push_back(newPos);
[2599]787
[2648]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 }
[2599]797
[2648]798 // Compute the Mean
799 // ----------------
[2670]800 ColumnVector mean(7); mean = 0.0;
[2648]801
[2599]802 QMutableVectorIterator<pppPos*> it(_posAverage);
803 while (it.hasNext()) {
804 pppPos* pp = it.next();
[2648]805 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
[2599]806 delete pp;
807 it.remove();
808 }
[2648]809 else {
[2670]810 for (int ii = 0; ii < 7; ++ii) {
811 mean[ii] += pp->xnt[ii];
[2649]812 }
[2648]813 }
[2599]814 }
[2648]815
816 int nn = _posAverage.size();
817
[2649]818 if (nn > 0) {
[2648]819
[2649]820 mean /= nn;
821
822 // Compute the Deviation
823 // ---------------------
[2670]824 ColumnVector std(7); std = 0.0;
[2649]825 QVectorIterator<pppPos*> it2(_posAverage);
826 while (it2.hasNext()) {
827 pppPos* pp = it2.next();
[2670]828 for (int ii = 0; ii < 7; ++ii) {
829 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
[2649]830 }
831 }
[2670]832 for (int ii = 0; ii < 7; ++ii) {
[2649]833 std[ii] = sqrt(std[ii] / nn);
834 }
[3169]835
836 if (settings.value("pppRefCrdX").toString() != "" &&
837 settings.value("pppRefCrdY").toString() != "" &&
838 settings.value("pppRefCrdZ").toString() != "") {
[2649]839
[3169]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);
[2649]850
[3169]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);
[2649]861
[3169]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 }
[2726]870 }
[2599]871 }
872 }
873
[2131]874 // NMEA Output
875 // -----------
[2181]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;
[2132]884
[2181]885 char phiCh = 'N';
886 if (phiDeg < 0) {
887 phiDeg = -phiDeg;
888 phiCh = 'S';
889 }
890 char lamCh = 'E';
891 if (lamDeg < 0) {
[2563]892 lamDeg = -lamDeg;
893 lamCh = 'W';
[2181]894 }
[2132]895
[2566]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 << ",,,"
[2569]907 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
908 << datestr[2] << datestr[3] << ",,";
[2566]909
910 writeNMEAstr(QString(strRMC.str().c_str()));
911
[2181]912 double dop = 2.0; // TODO
[2133]913
[2566]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 << ','
[2569]926 << setprecision(3) << ell[2] << ",M,0.0,M,,";
[2181]927
[2566]928 writeNMEAstr(QString(strGGA.str().c_str()));
[2131]929
[3106]930 _lastTimeOK = _time; // remember time of last successful update
[2060]931 return success;
932}
[2112]933
934// Outlier Detection
935////////////////////////////////////////////////////////////////////////////
[3309]936int bncModel::outlierDetection(int iPhase, const SymmetricMatrix& QQsav,
[2112]937 const ColumnVector& vv,
[2231]938 QMap<QString, t_satData*>& satDataGPS,
[2780]939 QMap<QString, t_satData*>& satDataGlo,
940 QMap<QString, t_satData*>& satDataGal) {
[2112]941
[3312]942 Tracer tracer("bncModel::outlierDetection");
943
[2792]944 QString prnCode;
945 QString prnPhase;
946 double maxResCode = 0.0;
947 double maxResPhase = 0.0;
[2231]948
[2792]949 QString prnRemoved;
950 double maxRes;
[2112]951
[2793]952 int irc = 0;
953
[3309]954 if (iPhase == 0) {
[3281]955
[3308]956 // Check GPS Code
957 // --------------
958 if (irc == 0) {
[3313]959 findMaxRes(iPhase, vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]960 if (maxResCode > MAXRES_CODE_GPS) {
961 satDataGPS.remove(prnCode);
962 prnRemoved = prnCode;
963 maxRes = maxResCode;
964 irc = 1;
965 }
[3281]966 }
[3308]967
968 // Check Galileo Code
969 // ------------------
970 if (irc == 0) {
[3313]971 findMaxRes(iPhase, vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]972 if (maxResCode > MAXRES_CODE_GAL) {
973 satDataGal.remove(prnCode);
974 prnRemoved = prnCode;
975 maxRes = maxResCode;
976 irc = 1;
977 }
[2793]978 }
[2792]979 }
[2112]980
[3308]981 else {
[3309]982
[3308]983 // Check Glonass Phase
984 // -------------------
985 if (irc == 0) {
[3313]986 findMaxRes(iPhase, vv,satDataGlo, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]987 if (maxResPhase > MAXRES_PHASE_GLO) {
988 satDataGlo.remove(prnPhase);
989 prnRemoved = prnPhase;
990 maxRes = maxResPhase;
991 irc = 1;
992 }
[2112]993 }
[3308]994
995 // Check Galileo Phase
996 // -------------------
997 if (irc == 0) {
[3313]998 findMaxRes(iPhase, vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]999 if (maxResPhase > MAXRES_PHASE_GAL) {
1000 satDataGal.remove(prnPhase);
1001 prnRemoved = prnPhase;
1002 maxRes = maxResPhase;
1003 irc = 1;
1004 }
[2780]1005 }
[3308]1006
1007 // Check GPS Phase
1008 // ---------------
1009 if (irc == 0) {
[3313]1010 findMaxRes(iPhase, vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
[3308]1011 if (maxResPhase > MAXRES_PHASE_GPS) {
1012 satDataGPS.remove(prnPhase);
1013 prnRemoved = prnPhase;
1014 maxRes = maxResPhase;
1015 irc = 1;
1016 }
1017 }
[2780]1018 }
1019
[2793]1020 if (irc != 0) {
[2792]1021 _log += "Outlier " + prnRemoved.toAscii() + " "
1022 + QByteArray::number(maxRes, 'f', 3) + "\n";
[2248]1023 _QQ = QQsav;
1024 }
[2793]1025
1026 return irc;
[2112]1027}
[2130]1028
1029//
1030////////////////////////////////////////////////////////////////////////////
1031void bncModel::writeNMEAstr(const QString& nmStr) {
1032
[3312]1033 Tracer tracer("bncModel::writeNMEAstr");
1034
[2130]1035 unsigned char XOR = 0;
1036 for (int ii = 0; ii < nmStr.length(); ii++) {
1037 XOR ^= (unsigned char) nmStr[ii].toAscii();
1038 }
[2181]1039
1040 QString outStr = '$' + nmStr
1041 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
[2130]1042
[2178]1043 if (_nmeaStream) {
[2181]1044 *_nmeaStream << outStr;
[2178]1045 _nmeaStream->flush();
1046 }
[2130]1047
[2181]1048 emit newNMEAstr(outStr.toAscii());
[2130]1049}
[2283]1050
1051////
1052//////////////////////////////////////////////////////////////////////////////
1053void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1054 const DiagonalMatrix& PP,
1055 SymmetricMatrix& QQ, ColumnVector& dx) {
1056
[3312]1057 Tracer tracer("bncModel::kalman");
1058
[2283]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}
[2582]1088
1089// Phase Wind-Up Correction
1090///////////////////////////////////////////////////////////////////////////
1091double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1092 const ColumnVector& rRec) {
1093
[3312]1094 Tracer tracer("bncModel::windUp");
1095
[2582]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 // -----------------------------------
[2942]1106 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
[2582]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}
[2789]1171
1172//
1173///////////////////////////////////////////////////////////////////////////
1174void bncModel::cmpEle(t_satData* satData) {
[3312]1175 Tracer tracer("bncModel::cmpEle");
[2789]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) {
[3312]1192 Tracer tracer("bncModel::addAmb");
[2789]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}
[2790]1208
1209//
1210///////////////////////////////////////////////////////////////////////////
[3309]1211void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
[2790]1212 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1213
[3312]1214 Tracer tracer("bncModel::addObs");
1215
[3316]1216 const double ELEWGHT = 20.0;
[3314]1217 double ellWgtCoef = 1.0;
1218 double eleD = satData->eleSat * 180.0 / M_PI;
1219 if (eleD < ELEWGHT) {
[3317]1220 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
[3314]1221 }
1222
[2791]1223 // Phase Observations
1224 // ------------------
[3309]1225 if (iPhase == 1) {
[2790]1226 ++iObs;
1227 ll(iObs) = satData->L3 - cmpValue(satData, true);
[3314]1228 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3) / (ellWgtCoef * ellWgtCoef);
[3319]1229 if (satData->system() == 'R') {
[3320]1230 PP(iObs,iObs) /= 25.0;
[3319]1231 }
[2790]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 }
[2791]1239 satData->indexPhase = iObs;
[2790]1240 }
[3307]1241
1242 // Code Observations
1243 // -----------------
1244 else {
1245 ++iObs;
1246 ll(iObs) = satData->P3 - cmpValue(satData, false);
[3314]1247 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3) / (ellWgtCoef * ellWgtCoef);
[3307]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 }
[2790]1253}
[2791]1254
1255//
1256///////////////////////////////////////////////////////////////////////////
[3309]1257void bncModel::printRes(int iPhase, const ColumnVector& vv,
[2791]1258 ostringstream& str, t_satData* satData) {
[3312]1259 Tracer tracer("bncModel::printRes");
[3309]1260 if (iPhase == 1) {
[2797]1261 str << _time.timestr(1)
[2800]1262 << " RES " << satData->prn.toAscii().data() << " L3 "
[3307]1263 << setw(9) << setprecision(4) << vv(satData->indexPhase) << endl;
[2791]1264 }
[3308]1265 else {
[3307]1266 str << _time.timestr(1)
1267 << " RES " << satData->prn.toAscii().data() << " P3 "
1268 << setw(9) << setprecision(4) << vv(satData->indexCode) << endl;
1269 }
[2791]1270}
[2792]1271
1272//
1273///////////////////////////////////////////////////////////////////////////
[3313]1274void bncModel::findMaxRes(int iPhase, const ColumnVector& vv,
[2792]1275 const QMap<QString, t_satData*>& satData,
1276 QString& prnCode, double& maxResCode,
1277 QString& prnPhase, double& maxResPhase) {
[3312]1278 Tracer tracer("bncModel::findMaxRes");
[2792]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();
[3313]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 }
[2792]1292 }
1293 }
[3313]1294 else {
1295 if (satData->indexPhase) {
1296 if (fabs(vv(satData->indexPhase)) > maxResPhase) {
1297 maxResPhase = fabs(vv(satData->indexPhase));
1298 prnPhase = satData->prn;
1299 }
[2792]1300 }
1301 }
1302 }
1303}
1304
[3307]1305// Update Step (private - loop over outliers)
1306////////////////////////////////////////////////////////////////////////////
[3321]1307t_irc bncModel::update_p(t_epoData* epoData) {
[3307]1308
[3312]1309 Tracer tracer("bncModel::update_p");
1310
[3322]1311 // Remeber Original State Vector and Variance-Covariance Matrix
1312 // ------------------------------------------------------------
1313 SymmetricMatrix QQ_orig = _QQ;
[3307]1314
[3322]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
[3308]1322 for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++) {
[3307]1323
[3322]1324 SymmetricMatrix QQsav;
1325 ColumnVector vv;
1326 ColumnVector dx;
[3321]1327
[3307]1328 do {
1329
[3309]1330 // Bancroft Solution
1331 // -----------------
[3307]1332 if (iPhase == 0) {
1333 if (cmpBancroft(epoData) != success) {
[3322]1334 QVectorIterator<bncParam*> itParOrig(params_orig);
1335 while (itParOrig.hasNext()) {
1336 bncParam* par = itParOrig.next();
1337 delete par;
1338 }
[3307]1339 emit newMessage(_log, false);
1340 return failure;
1341 }
1342 }
[3322]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 }
[3307]1365
[3308]1366 // Status Prediction
1367 // -----------------
[3309]1368 predict(iPhase, epoData);
[3308]1369
[3307]1370 // Create First-Design Matrix
1371 // --------------------------
1372 unsigned nPar = _params.size();
1373 unsigned nObs = 0;
[3308]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 }
[3307]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
[3308]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
[3307]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;
[3308]1423
[3307]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();
[3308]1434 printRes(iPhase, vv, str, satData);
[3307]1435 }
[3308]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 }
[3307]1443 }
1444 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
1445 while (itGal.hasNext()) {
1446 itGal.next();
1447 t_satData* satData = itGal.value();
[3308]1448 printRes(iPhase, vv, str, satData);
[3307]1449 }
1450 _log += str.str().c_str();
1451 }
1452
[3308]1453 } while (outlierDetection(iPhase, QQsav, vv, epoData->satDataGPS,
[3307]1454 epoData->satDataGlo, epoData->satDataGal) != 0);
[3321]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 }
[3307]1463 }
1464
[3322]1465 QVectorIterator<bncParam*> itParOrig(params_orig);
1466 while (itParOrig.hasNext()) {
1467 bncParam* par = itParOrig.next();
1468 delete par;
1469 }
[3307]1470 return success;
1471}
Note: See TracBrowser for help on using the repository browser.