source: ntrip/trunk/BNC/src/bncmodel.cpp@ 5805

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