source: ntrip/branches/BNC_2.11.0/src/bncmodel.cpp@ 8356

Last change on this file since 8356 was 6325, checked in by stuerze, 10 years ago

a small condition is added to prevent an illegal array access

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