source: ntrip/trunk/BNC/src/combination/bnccomb.cpp@ 8005

Last change on this file since 8005 was 7715, checked in by stuerze, 9 years ago

minor changes

File size: 34.4 KB
RevLine 
[2898]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncComb
6 *
7 * Purpose: Combinations of Orbit/Clock Corrections
8 *
9 * Author: L. Mervart
10 *
11 * Created: 22-Jan-2011
12 *
[7297]13 * Changes:
[2898]14 *
15 * -----------------------------------------------------------------------*/
16
[2933]17#include <newmatio.h>
[2921]18#include <iomanip>
[3214]19#include <sstream>
[2898]20
21#include "bnccomb.h"
[5070]22#include "bnccore.h"
[3201]23#include "upload/bncrtnetdecoder.h"
[2910]24#include "bncsettings.h"
[2988]25#include "bncutils.h"
[3181]26#include "bncsp3.h"
[3052]27#include "bncantex.h"
[5742]28#include "t_prn.h"
[2898]29
[3455]30const double sig0_offAC = 1000.0;
31const double sig0_offACSat = 100.0;
[3468]32const double sigP_offACSat = 0.01;
[3455]33const double sig0_clkSat = 100.0;
34
35const double sigObs = 0.05;
36
37using namespace std;
38
[2898]39// Constructor
40////////////////////////////////////////////////////////////////////////////
[6155]41bncComb::cmbParam::cmbParam(parType type_, int index_, const QString& ac_, const QString& prn_) {
[3032]42
[3433]43 type = type_;
44 index = index_;
45 AC = ac_;
46 prn = prn_;
47 xx = 0.0;
[3455]48 eph = 0;
[3429]49
[3485]50 if (type == offACgps) {
[3455]51 epoSpec = true;
52 sig0 = sig0_offAC;
53 sigP = sig0;
[3429]54 }
[3485]55 else if (type == offACglo) {
56 epoSpec = true;
57 sig0 = sig0_offAC;
58 sigP = sig0;
59 }
[3429]60 else if (type == offACSat) {
[3455]61 epoSpec = false;
62 sig0 = sig0_offACSat;
63 sigP = sigP_offACSat;
[3429]64 }
65 else if (type == clkSat) {
[3455]66 epoSpec = true;
67 sig0 = sig0_clkSat;
68 sigP = sig0;
[3429]69 }
[2933]70}
71
72// Destructor
73////////////////////////////////////////////////////////////////////////////
[6155]74bncComb::cmbParam::~cmbParam() {
[2933]75}
76
77// Partial
78////////////////////////////////////////////////////////////////////////////
[6155]79double bncComb::cmbParam::partial(const QString& AC_, const QString& prn_) {
[7297]80
[3485]81 if (type == offACgps) {
82 if (AC == AC_ && prn_[0] == 'G') {
[2934]83 return 1.0;
84 }
85 }
[3485]86 else if (type == offACglo) {
87 if (AC == AC_ && prn_[0] == 'R') {
88 return 1.0;
89 }
90 }
[3429]91 else if (type == offACSat) {
92 if (AC == AC_ && prn == prn_) {
[2933]93 return 1.0;
94 }
95 }
[3429]96 else if (type == clkSat) {
97 if (prn == prn_) {
[2933]98 return 1.0;
99 }
100 }
101
102 return 0.0;
103}
104
[7297]105//
[2990]106////////////////////////////////////////////////////////////////////////////
[6155]107QString bncComb::cmbParam::toString() const {
[2933]108
[2990]109 QString outStr;
[7297]110
[3485]111 if (type == offACgps) {
112 outStr = "AC offset GPS " + AC;
[2990]113 }
[3485]114 else if (type == offACglo) {
115 outStr = "AC offset GLO " + AC;
116 }
[3429]117 else if (type == offACSat) {
[7008]118 outStr = "Sat Offset " + AC + " " + prn.mid(0,3);
[2990]119 }
[3429]120 else if (type == clkSat) {
[7008]121 outStr = "Clk Corr " + prn.mid(0,3);
[2990]122 }
[2933]123
[2990]124 return outStr;
125}
126
[7299]127// Singleton
128////////////////////////////////////////////////////////////////////////////
129bncComb* bncComb::instance() {
130 static bncComb _bncComb;
131 return &_bncComb;
132}
133
[2933]134// Constructor
135////////////////////////////////////////////////////////////////////////////
[6443]136bncComb::bncComb() : _ephUser(true) {
[2910]137
138 bncSettings settings;
139
[7297]140 QStringList cmbStreams = settings.value("cmbStreams").toStringList();
[2918]141
[4183]142 _cmbSampl = settings.value("cmbSampl").toInt();
143 if (_cmbSampl <= 0) {
144 _cmbSampl = 10;
145 }
146
[3455]147 _masterMissingEpochs = 0;
148
[7297]149 if (cmbStreams.size() >= 1 && !cmbStreams[0].isEmpty()) {
150 QListIterator<QString> it(cmbStreams);
[2910]151 while (it.hasNext()) {
152 QStringList hlp = it.next().split(" ");
[2918]153 cmbAC* newAC = new cmbAC();
154 newAC->mountPoint = hlp[0];
155 newAC->name = hlp[1];
156 newAC->weight = hlp[2].toDouble();
[3453]157 if (_masterOrbitAC.isEmpty()) {
158 _masterOrbitAC = newAC->name;
159 }
[3429]160 _ACs.append(newAC);
[2910]161 }
162 }
[2927]163
[3211]164 _rtnetDecoder = 0;
[3201]165
[7297]166 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[5068]167 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[2933]168
[5583]169 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)),
[6155]170 this, SLOT(slotProviderIDChanged(QString)));
[5583]171
[6155]172 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
173 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
174
175 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
176 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
177
[3470]178 // Combination Method
179 // ------------------
[3481]180 if (settings.value("cmbMethod").toString() == "Single-Epoch") {
181 _method = singleEpoch;
[3470]182 }
183 else {
[3481]184 _method = filter;
[3470]185 }
[3032]186
[3484]187 // Use Glonass
188 // -----------
[6174]189 if ( Qt::CheckState(settings.value("cmbUseGlonass").toInt()) == Qt::Checked) {
[3484]190 _useGlonass = true;
191 }
192 else {
193 _useGlonass = false;
194 }
195
[3032]196 // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
197 // ----------------------------------------------------------------------
[3470]198 if (_method == filter) {
199 int nextPar = 0;
200 QListIterator<cmbAC*> it(_ACs);
201 while (it.hasNext()) {
202 cmbAC* AC = it.next();
[3485]203 _params.push_back(new cmbParam(cmbParam::offACgps, ++nextPar, AC->name, ""));
[5808]204 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
[7008]205 QString prn = QString("G%1_0").arg(iGps, 2, 10, QChar('0'));
[7297]206 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
[3470]207 AC->name, prn));
208 }
[3483]209 if (_useGlonass) {
[3485]210 _params.push_back(new cmbParam(cmbParam::offACglo, ++nextPar, AC->name, ""));
[5808]211 for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
[7008]212 QString prn = QString("R%1_0").arg(iGlo, 2, 10, QChar('0'));
[7297]213 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
[3483]214 AC->name, prn));
215 }
216 }
[3470]217 }
[5808]218 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
[7008]219 QString prn = QString("G%1_0").arg(iGps, 2, 10, QChar('0'));
[3470]220 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
[2991]221 }
[3483]222 if (_useGlonass) {
[5808]223 for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
[7008]224 QString prn = QString("R%1_0").arg(iGlo, 2, 10, QChar('0'));
[3483]225 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
226 }
227 }
[7297]228
[3470]229 // Initialize Variance-Covariance Matrix
230 // -------------------------------------
231 _QQ.ReSize(_params.size());
232 _QQ = 0.0;
233 for (int iPar = 1; iPar <= _params.size(); iPar++) {
234 cmbParam* pp = _params[iPar-1];
235 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
236 }
[2991]237 }
[2933]238
[3052]239 // ANTEX File
240 // ----------
241 _antex = 0;
[6667]242 QString antexFileName = settings.value("uploadAntexFile").toString();
[3052]243 if (!antexFileName.isEmpty()) {
244 _antex = new bncAntex();
245 if (_antex->readFile(antexFileName) != success) {
246 emit newMessage("wrong ANTEX file", true);
247 delete _antex;
248 _antex = 0;
249 }
250 }
[3138]251
[3329]252 // Maximal Residuum
253 // ----------------
254 _MAXRES = settings.value("cmbMaxres").toDouble();
255 if (_MAXRES <= 0.0) {
256 _MAXRES = 999.0;
257 }
[2898]258}
259
260// Destructor
261////////////////////////////////////////////////////////////////////////////
262bncComb::~bncComb() {
[3429]263 QListIterator<cmbAC*> icAC(_ACs);
264 while (icAC.hasNext()) {
265 delete icAC.next();
[2918]266 }
[3201]267 delete _rtnetDecoder;
[3052]268 delete _antex;
[3296]269 for (int iPar = 1; iPar <= _params.size(); iPar++) {
270 delete _params[iPar-1];
271 }
[3556]272 QListIterator<bncTime> itTime(_buffer.keys());
[3551]273 while (itTime.hasNext()) {
[3556]274 bncTime epoTime = itTime.next();
275 _buffer.remove(epoTime);
[3429]276 }
[2898]277}
278
[6155]279// Remember orbit corrections
[2898]280////////////////////////////////////////////////////////////////////////////
[6155]281void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
[2906]282 QMutexLocker locker(&_mutex);
[2913]283
[6155]284 for (int ii = 0; ii < orbCorrections.size(); ii++) {
285 t_orbCorr& orbCorr = orbCorrections[ii];
286 QString staID(orbCorr._staID.c_str());
[7008]287 QString prn(orbCorr._prn.toInternalString().c_str());
[6155]288
289 // Find/Check the AC Name
290 // ----------------------
291 QString acName;
292 QListIterator<cmbAC*> icAC(_ACs);
293 while (icAC.hasNext()) {
294 cmbAC* AC = icAC.next();
295 if (AC->mountPoint == staID) {
296 acName = AC->name;
297 break;
298 }
[3431]299 }
[6155]300 if (acName.isEmpty()) {
301 continue;
302 }
[3431]303
[6155]304 // Store the correction
305 // --------------------
306 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
307 storage[orbCorr._prn] = orbCorr;
[2913]308 }
[6155]309}
[2913]310
[6155]311// Process clock corrections
312////////////////////////////////////////////////////////////////////////////
313void bncComb::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
314 QMutexLocker locker(&_mutex);
315
316 bncTime lastTime;
317
318 for (int ii = 0; ii < clkCorrections.size(); ii++) {
319 t_clkCorr& clkCorr = clkCorrections[ii];
320 QString staID(clkCorr._staID.c_str());
[6961]321 QString prn(clkCorr._prn.toInternalString().c_str());
[6155]322
323 // Set the last time
324 // -----------------
325 if (lastTime.undef() || clkCorr._time > lastTime) {
326 lastTime = clkCorr._time;
[3483]327 }
328
[6155]329 // Find/Check the AC Name
330 // ----------------------
331 QString acName;
332 QListIterator<cmbAC*> icAC(_ACs);
333 while (icAC.hasNext()) {
334 cmbAC* AC = icAC.next();
335 if (AC->mountPoint == staID) {
336 acName = AC->name;
337 break;
338 }
[3588]339 }
[6155]340 if (acName.isEmpty()) {
341 continue;
342 }
[3588]343
[6155]344 // Check GLONASS
345 // -------------
346 if (!_useGlonass && clkCorr._prn.system() == 'R') {
347 continue;
[3590]348 }
349
[6155]350 // Check Modulo Time
351 // -----------------
352 if (int(clkCorr._time.gpssec()) % _cmbSampl != 0.0) {
353 continue;
354 }
[3274]355
[6155]356 // Check Correction Age
357 // --------------------
358 if (_resTime.valid() && clkCorr._time <= _resTime) {
[7008]359 emit newMessage("bncComb: old correction: " + acName.toAscii() + " " + prn.mid(0,3).toAscii(), true);
[6155]360 continue;
361 }
[7297]362
[6155]363 // Create new correction
364 // ---------------------
365 cmbCorr* newCorr = new cmbCorr();
[6157]366 newCorr->_prn = prn;
[6155]367 newCorr->_time = clkCorr._time;
368 newCorr->_iod = clkCorr._iod;
369 newCorr->_acName = acName;
[6159]370 newCorr->_clkCorr = clkCorr;
[6155]371
[6156]372 // Check orbit correction
373 // ----------------------
374 if (!_orbCorrections.contains(acName)) {
375 delete newCorr;
376 continue;
377 }
378 else {
379 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
380 if (!storage.contains(clkCorr._prn) || storage[clkCorr._prn]._iod != newCorr->_iod) {
381 delete newCorr;
382 continue;
383 }
384 else {
[6159]385 newCorr->_orbCorr = storage[clkCorr._prn];
[6156]386 }
387 }
388
[6155]389 // Check the Ephemeris
390 //--------------------
[7012]391 t_eph* ephLast = _ephUser.ephLast(prn);
392 t_eph* ephPrev = _ephUser.ephPrev(prn);
[6443]393 if (ephLast == 0) {
[6962]394 emit newMessage("bncComb: eph not found " + prn.mid(0,3).toAscii(), true);
[6155]395 delete newCorr;
396 continue;
[2986]397 }
[3029]398 else {
[6443]399 if (ephLast->IOD() == newCorr->_iod) {
400 newCorr->_eph = ephLast;
[6155]401 }
[6443]402 else if (ephPrev && ephPrev->IOD() == newCorr->_iod) {
403 newCorr->_eph = ephPrev;
404 switchToLastEph(ephLast, newCorr);
[6155]405 }
406 else {
[6962]407 emit newMessage("bncComb: eph not found " + prn.mid(0,3).toAscii() +
[6155]408 QString(" %1").arg(newCorr->_iod).toAscii(), true);
409 delete newCorr;
410 continue;
411 }
[2986]412 }
[6155]413
414 // Store correction into the buffer
415 // --------------------------------
416 QVector<cmbCorr*>& corrs = _buffer[newCorr->_time].corrs;
417 corrs.push_back(newCorr);
[2986]418 }
419
[3435]420 // Process previous Epoch(s)
421 // -------------------------
[7392]422 const double outWait = 1.0 * _cmbSampl;
[3556]423 QListIterator<bncTime> itTime(_buffer.keys());
[3435]424 while (itTime.hasNext()) {
[3556]425 bncTime epoTime = itTime.next();
[7392]426 if (epoTime < lastTime - outWait) {
[3556]427 _resTime = epoTime;
[3435]428 processEpoch();
429 }
[2927]430 }
[2898]431}
432
[7297]433// Change the correction so that it refers to last received ephemeris
[2986]434////////////////////////////////////////////////////////////////////////////
[7012]435void bncComb::switchToLastEph(t_eph* lastEph, cmbCorr* corr) {
[3028]436
[6155]437 if (corr->_eph == lastEph) {
[3429]438 return;
439 }
440
[2987]441 ColumnVector oldXC(4);
442 ColumnVector oldVV(3);
[6155]443 corr->_eph->getCrd(corr->_time, oldXC, oldVV, false);
[2988]444
[2987]445 ColumnVector newXC(4);
446 ColumnVector newVV(3);
[6155]447 lastEph->getCrd(corr->_time, newXC, newVV, false);
[2988]448
449 ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
[2989]450 ColumnVector dV = newVV - oldVV;
451 double dC = newXC(4) - oldXC(4);
452
[2988]453 ColumnVector dRAO(3);
454 XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
[2989]455
456 ColumnVector dDotRAO(3);
457 XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
458
[6963]459 QString msg = "switch corr " + corr->_prn.mid(0,3)
[6155]460 + QString(" %1 -> %2 %3").arg(corr->_iod,3).arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
[3013]461
[3029]462 emit newMessage(msg.toAscii(), false);
[3028]463
[6155]464 corr->_iod = lastEph->IOD();
465 corr->_eph = lastEph;
466
[6159]467 corr->_orbCorr._xr += dRAO;
468 corr->_orbCorr._dotXr += dDotRAO;
469 corr->_clkCorr._dClk -= dC;
[2986]470}
471
[3429]472// Process Epoch
[2928]473////////////////////////////////////////////////////////////////////////////
[3429]474void bncComb::processEpoch() {
[2918]475
[2990]476 _log.clear();
477
478 QTextStream out(&_log, QIODevice::WriteOnly);
479
[7297]480 out << endl << "Combination:" << endl
[3472]481 << "------------------------------" << endl;
[2990]482
[3433]483 // Observation Statistics
484 // ----------------------
[3455]485 bool masterPresent = false;
[3433]486 QListIterator<cmbAC*> icAC(_ACs);
487 while (icAC.hasNext()) {
488 cmbAC* AC = icAC.next();
489 AC->numObs = 0;
[3434]490 QVectorIterator<cmbCorr*> itCorr(corrs());
[3433]491 while (itCorr.hasNext()) {
492 cmbCorr* corr = itCorr.next();
[6157]493 if (corr->_acName == AC->name) {
[3433]494 AC->numObs += 1;
[3453]495 if (AC->name == _masterOrbitAC) {
496 masterPresent = true;
497 }
[3433]498 }
499 }
500 out << AC->name.toAscii().data() << ": " << AC->numObs << endl;
501 }
502
[3453]503 // If Master not present, switch to another one
504 // --------------------------------------------
[4889]505 const unsigned switchMasterAfterGap = 1;
[3456]506 if (masterPresent) {
507 _masterMissingEpochs = 0;
508 }
509 else {
[3455]510 ++_masterMissingEpochs;
[4889]511 if (_masterMissingEpochs < switchMasterAfterGap) {
[3457]512 out << "Missing Master, Epoch skipped" << endl;
[3556]513 _buffer.remove(_resTime);
[3455]514 emit newMessage(_log, false);
515 return;
[3453]516 }
[3455]517 else {
518 _masterMissingEpochs = 0;
519 QListIterator<cmbAC*> icAC(_ACs);
520 while (icAC.hasNext()) {
521 cmbAC* AC = icAC.next();
522 if (AC->numObs > 0) {
523 out << "Switching Master AC "
[7297]524 << _masterOrbitAC.toAscii().data() << " --> "
525 << AC->name.toAscii().data() << " "
526 << _resTime.datestr().c_str() << " "
[3455]527 << _resTime.timestr().c_str() << endl;
528 _masterOrbitAC = AC->name;
529 break;
530 }
[3452]531 }
532 }
533 }
534
[6157]535 QMap<QString, cmbCorr*> resCorr;
[3472]536
537 // Perform the actual Combination using selected Method
538 // ----------------------------------------------------
539 t_irc irc;
[3475]540 ColumnVector dx;
[3472]541 if (_method == filter) {
[3475]542 irc = processEpoch_filter(out, resCorr, dx);
[3472]543 }
544 else {
[3475]545 irc = processEpoch_singleEpoch(out, resCorr, dx);
[3472]546 }
547
[3475]548 // Update Parameter Values, Print Results
549 // --------------------------------------
[3472]550 if (irc == success) {
[3475]551 for (int iPar = 1; iPar <= _params.size(); iPar++) {
552 cmbParam* pp = _params[iPar-1];
553 pp->xx += dx(iPar);
554 if (pp->type == cmbParam::clkSat) {
555 if (resCorr.find(pp->prn) != resCorr.end()) {
[6160]556 resCorr[pp->prn]->_dClkResult = pp->xx / t_CST::c;
[3475]557 }
558 }
[7297]559 out << _resTime.datestr().c_str() << " "
[3475]560 << _resTime.timestr().c_str() << " ";
561 out.setRealNumberNotation(QTextStream::FixedNotation);
562 out.setFieldWidth(8);
563 out.setRealNumberPrecision(4);
564 out << pp->toString() << " "
565 << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
566 out.setFieldWidth(0);
567 }
[3472]568 printResults(out, resCorr);
569 dumpResults(resCorr);
570 }
571
572 // Delete Data, emit Message
573 // -------------------------
[3556]574 _buffer.remove(_resTime);
[3472]575 emit newMessage(_log, false);
576}
577
578// Process Epoch - Filter Method
579////////////////////////////////////////////////////////////////////////////
580t_irc bncComb::processEpoch_filter(QTextStream& out,
[6157]581 QMap<QString, cmbCorr*>& resCorr,
[3475]582 ColumnVector& dx) {
[3472]583
[3429]584 // Prediction Step
585 // ---------------
[3472]586 int nPar = _params.size();
[2933]587 ColumnVector x0(nPar);
588 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[3455]589 cmbParam* pp = _params[iPar-1];
590 if (pp->epoSpec) {
[3451]591 pp->xx = 0.0;
[3455]592 _QQ.Row(iPar) = 0.0;
593 _QQ.Column(iPar) = 0.0;
594 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
[3451]595 }
[3455]596 else {
597 _QQ(iPar,iPar) += pp->sigP * pp->sigP;
598 }
[2933]599 x0(iPar) = pp->xx;
600 }
601
[3487]602 // Check Satellite Positions for Outliers
603 // --------------------------------------
[3497]604 if (checkOrbits(out) != success) {
[3487]605 return failure;
606 }
[3441]607
[3455]608 // Update and outlier detection loop
609 // ---------------------------------
[3487]610 SymmetricMatrix QQ_sav = _QQ;
[3455]611 while (true) {
[3135]612
[3455]613 Matrix AA;
614 ColumnVector ll;
615 DiagonalMatrix PP;
[3429]616
[3455]617 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
[3472]618 return failure;
[3441]619 }
[2933]620
[6169]621 dx.ReSize(nPar); dx = 0.0;
[5808]622 kalman(AA, ll, PP, _QQ, dx);
[6164]623
[3429]624 ColumnVector vv = ll - AA * dx;
[3080]625
[3429]626 int maxResIndex;
[7297]627 double maxRes = vv.maximum_absolute_value1(maxResIndex);
[3429]628 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]629 out.setRealNumberPrecision(3);
[3429]630 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
[3432]631 << " Maximum Residuum " << maxRes << ' '
[6962]632 << corrs()[maxResIndex-1]->_acName << ' ' << corrs()[maxResIndex-1]->_prn.mid(0,3);
[3432]633 if (maxRes > _MAXRES) {
634 for (int iPar = 1; iPar <= _params.size(); iPar++) {
635 cmbParam* pp = _params[iPar-1];
[7297]636 if (pp->type == cmbParam::offACSat &&
[6157]637 pp->AC == corrs()[maxResIndex-1]->_acName &&
[6962]638 pp->prn == corrs()[maxResIndex-1]->_prn.mid(0,3)) {
[3432]639 QQ_sav.Row(iPar) = 0.0;
640 QQ_sav.Column(iPar) = 0.0;
[3455]641 QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
[3432]642 }
643 }
644
645 out << " Outlier" << endl;
646 _QQ = QQ_sav;
[3455]647 corrs().remove(maxResIndex-1);
[3432]648 }
649 else {
650 out << " OK" << endl;
[6330]651 out.setRealNumberNotation(QTextStream::FixedNotation);
652 out.setRealNumberPrecision(4);
653 for (int ii = 0; ii < corrs().size(); ii++) {
654 const cmbCorr* corr = corrs()[ii];
655 out << _resTime.datestr().c_str() << ' '
656 << _resTime.timestr().c_str() << " "
[6962]657 << corr->_acName << ' ' << corr->_prn.mid(0,3);
[6330]658 out.setFieldWidth(10);
659 out << " res = " << vv[ii] << endl;
660 out.setFieldWidth(0);
661 }
[3432]662 break;
663 }
664 }
665
[3472]666 return success;
[2918]667}
[3011]668
[3201]669// Print results
[3011]670////////////////////////////////////////////////////////////////////////////
[3429]671void bncComb::printResults(QTextStream& out,
[6157]672 const QMap<QString, cmbCorr*>& resCorr) {
[3011]673
[6157]674 QMapIterator<QString, cmbCorr*> it(resCorr);
[3011]675 while (it.hasNext()) {
676 it.next();
[6157]677 cmbCorr* corr = it.value();
678 const t_eph* eph = corr->_eph;
[3015]679 if (eph) {
[6109]680 ColumnVector xc(4);
681 ColumnVector vv(3);
682 eph->getCrd(_resTime, xc, vv, false);
[3015]683
[7297]684 out << _resTime.datestr().c_str() << " "
[3429]685 << _resTime.timestr().c_str() << " ";
[3015]686 out.setFieldWidth(3);
[6962]687 out << "Full Clock " << corr->_prn.mid(0,3) << " " << corr->_iod << " ";
[3015]688 out.setFieldWidth(14);
[6160]689 out << (xc(4) + corr->_dClkResult) * t_CST::c << endl;
[3370]690 out.setFieldWidth(0);
[3015]691 }
692 else {
693 out << "bncComb::printResuls bug" << endl;
694 }
[3011]695 }
696}
[3202]697
698// Send results to RTNet Decoder and directly to PPP Client
699////////////////////////////////////////////////////////////////////////////
[6157]700void bncComb::dumpResults(const QMap<QString, cmbCorr*>& resCorr) {
[3202]701
[6161]702 QList<t_orbCorr> orbCorrections;
703 QList<t_clkCorr> clkCorrections;
704
[5337]705 QString outLines;
706 QStringList corrLines;
[3214]707
708 unsigned year, month, day, hour, minute;
709 double sec;
[3429]710 _resTime.civil_date(year, month, day);
711 _resTime.civil_time(hour, minute, sec);
[3214]712
[7297]713 outLines.sprintf("* %4d %2d %2d %d %d %12.8f\n",
[5337]714 year, month, day, hour, minute, sec);
[3214]715
[6157]716 QMapIterator<QString, cmbCorr*> it(resCorr);
[3202]717 while (it.hasNext()) {
718 it.next();
[6157]719 cmbCorr* corr = it.value();
[3202]720
[7013]721 t_orbCorr orbCorr(corr->_orbCorr);
722 orbCorr._staID = "INTERNAL";
723 orbCorrections.push_back(orbCorr);
724
725 t_clkCorr clkCorr(corr->_clkCorr);
726 clkCorr._staID = "INTERNAL";
727 clkCorr._dClk = corr->_dClkResult;
728 clkCorr._dotDClk = 0.0;
729 clkCorr._dotDotDClk = 0.0;
730 clkCorrections.push_back(clkCorr);
731
[4978]732 ColumnVector xc(4);
733 ColumnVector vv(3);
[7013]734 corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
735 corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
[7012]736 corr->_eph->getCrd(_resTime, xc, vv, true);
737
[4978]738 // Correction Phase Center --> CoM
739 // -------------------------------
740 ColumnVector dx(3); dx = 0.0;
741 if (_antex) {
742 double Mjd = _resTime.mjd() + _resTime.daysec()/86400.0;
[6157]743 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
[4992]744 dx = 0;
[6970]745 _log += "antenna not found " + corr->_prn.mid(0,3).toAscii() + '\n';
[3214]746 }
747 }
[7012]748
749 outLines += corr->_prn.mid(0,3);
[5337]750 QString hlp;
751 hlp.sprintf(" APC 3 %15.4f %15.4f %15.4f"
752 " Clk 1 %15.4f"
753 " Vel 3 %15.4f %15.4f %15.4f"
754 " CoM 3 %15.4f %15.4f %15.4f\n",
[7012]755 xc(1), xc(2), xc(3),
756 xc(4) * t_CST::c,
[5337]757 vv(1), vv(2), vv(3),
758 xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
759 outLines += hlp;
760
[4978]761 QString line;
[5564]762 int messageType = COTYPE_GPSCOMBINED;
763 int updateInt = 0;
[4978]764 line.sprintf("%d %d %d %.1f %s"
[7055]765 " %lu"
[4978]766 " %8.3f %8.3f %8.3f %8.3f"
767 " %10.5f %10.5f %10.5f %10.5f"
[5576]768 " %10.5f INTERNAL",
[4978]769 messageType, updateInt, _resTime.gpsw(), _resTime.gpssec(),
[7012]770 corr->_prn.mid(0,3).toAscii().data(),
[6157]771 corr->_iod,
[6160]772 corr->_dClkResult * t_CST::c,
[6159]773 corr->_orbCorr._xr[0],
774 corr->_orbCorr._xr[1],
775 corr->_orbCorr._xr[2],
[6157]776 0.0,
[6159]777 corr->_orbCorr._dotXr[0],
778 corr->_orbCorr._dotXr[1],
779 corr->_orbCorr._dotXr[2],
[6157]780 0.0);
[4978]781 corrLines << line;
782
[3214]783 delete corr;
784 }
785
[5337]786 outLines += "EOE\n"; // End Of Epoch flag
787
[3215]788 if (!_rtnetDecoder) {
789 _rtnetDecoder = new bncRtnetDecoder();
790 }
[3221]791
[3215]792 vector<string> errmsg;
[5337]793 _rtnetDecoder->Decode(outLines.toAscii().data(), outLines.length(), errmsg);
[3215]794
[5861]795 // Send new Corrections to PPP etc.
796 // --------------------------------
[6161]797 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
798 emit newOrbCorrections(orbCorrections);
799 emit newClkCorrections(clkCorrections);
800 }
[3202]801}
[3455]802
803// Create First Design Matrix and Vector of Measurements
804////////////////////////////////////////////////////////////////////////////
805t_irc bncComb::createAmat(Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
[7297]806 const ColumnVector& x0,
[6157]807 QMap<QString, cmbCorr*>& resCorr) {
[3455]808
809 unsigned nPar = _params.size();
[7297]810 unsigned nObs = corrs().size();
[3455]811
812 if (nObs == 0) {
813 return failure;
814 }
815
[5742]816 int maxSat = t_prn::MAXPRN_GPS;
[3486]817// if (_useGlonass) {
[5742]818// maxSat = t_prn::MAXPRN_GPS + t_prn::MAXPRN_GLONASS;
[3486]819// }
[3455]820
[5742]821 const int nCon = (_method == filter) ? 1 + maxSat : 0;
[3483]822
[3455]823 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
824 ll.ReSize(nObs+nCon); ll = 0.0;
825 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
826
827 int iObs = 0;
828 QVectorIterator<cmbCorr*> itCorr(corrs());
829 while (itCorr.hasNext()) {
830 cmbCorr* corr = itCorr.next();
[6157]831 QString prn = corr->_prn;
[3487]832
[3455]833 ++iObs;
834
[6157]835 if (corr->_acName == _masterOrbitAC && resCorr.find(prn) == resCorr.end()) {
836 resCorr[prn] = new cmbCorr(*corr);
[3455]837 }
838
839 for (int iPar = 1; iPar <= _params.size(); iPar++) {
840 cmbParam* pp = _params[iPar-1];
[6157]841 AA(iObs, iPar) = pp->partial(corr->_acName, prn);
[3455]842 }
843
[6160]844 ll(iObs) = corr->_clkCorr._dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
[3455]845 }
846
847 // Regularization
848 // --------------
[3474]849 if (_method == filter) {
850 const double Ph = 1.e6;
851 PP(nObs+1) = Ph;
[3461]852 for (int iPar = 1; iPar <= _params.size(); iPar++) {
853 cmbParam* pp = _params[iPar-1];
[3465]854 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[3474]855 pp->type == cmbParam::clkSat ) {
856 AA(nObs+1, iPar) = 1.0;
[3455]857 }
858 }
[3474]859 int iCond = 1;
[5808]860 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
[7132]861 QString prn = QString("G%1_0").arg(iGps, 2, 10, QChar('0'));
[3474]862 ++iCond;
863 PP(nObs+iCond) = Ph;
864 for (int iPar = 1; iPar <= _params.size(); iPar++) {
865 cmbParam* pp = _params[iPar-1];
[7299]866 if ( pp &&
867 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[7297]868 pp->type == cmbParam::offACSat &&
[3474]869 pp->prn == prn) {
870 AA(nObs+iCond, iPar) = 1.0;
871 }
872 }
873 }
[3486]874// if (_useGlonass) {
[5742]875// for (int iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
[7132]876// QString prn = QString("R%1_0").arg(iGlo, 2, 10, QChar('0'));
[3486]877// ++iCond;
878// PP(nObs+iCond) = Ph;
879// for (int iPar = 1; iPar <= _params.size(); iPar++) {
880// cmbParam* pp = _params[iPar-1];
[7299]881// if ( pp &&
882// AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[7297]883// pp->type == cmbParam::offACSat &&
[3486]884// pp->prn == prn) {
885// AA(nObs+iCond, iPar) = 1.0;
886// }
887// }
888// }
889// }
[3455]890 }
891
892 return success;
893}
[3470]894
895// Process Epoch - Single-Epoch Method
896////////////////////////////////////////////////////////////////////////////
[3472]897t_irc bncComb::processEpoch_singleEpoch(QTextStream& out,
[6157]898 QMap<QString, cmbCorr*>& resCorr,
[3475]899 ColumnVector& dx) {
[3470]900
[3487]901 // Check Satellite Positions for Outliers
902 // --------------------------------------
[3497]903 if (checkOrbits(out) != success) {
[3487]904 return failure;
905 }
906
[3482]907 // Outlier Detection Loop
908 // ----------------------
909 while (true) {
[7297]910
[3482]911 // Remove Satellites that are not in Master
912 // ----------------------------------------
913 QMutableVectorIterator<cmbCorr*> it(corrs());
914 while (it.hasNext()) {
915 cmbCorr* corr = it.next();
[6157]916 QString prn = corr->_prn;
[3482]917 bool foundMaster = false;
918 QVectorIterator<cmbCorr*> itHlp(corrs());
919 while (itHlp.hasNext()) {
920 cmbCorr* corrHlp = itHlp.next();
[6157]921 QString prnHlp = corrHlp->_prn;
922 QString ACHlp = corrHlp->_acName;
[3482]923 if (ACHlp == _masterOrbitAC && prn == prnHlp) {
924 foundMaster = true;
925 break;
926 }
[3476]927 }
[3482]928 if (!foundMaster) {
[3556]929 delete corr;
[3482]930 it.remove();
931 }
[3473]932 }
[7297]933
[3482]934 // Count Number of Observations per Satellite and per AC
935 // -----------------------------------------------------
936 QMap<QString, int> numObsPrn;
937 QMap<QString, int> numObsAC;
938 QVectorIterator<cmbCorr*> itCorr(corrs());
939 while (itCorr.hasNext()) {
940 cmbCorr* corr = itCorr.next();
[6157]941 QString prn = corr->_prn;
942 QString AC = corr->_acName;
[3482]943 if (numObsPrn.find(prn) == numObsPrn.end()) {
944 numObsPrn[prn] = 1;
945 }
946 else {
947 numObsPrn[prn] += 1;
948 }
949 if (numObsAC.find(AC) == numObsAC.end()) {
950 numObsAC[AC] = 1;
951 }
952 else {
953 numObsAC[AC] += 1;
954 }
[3476]955 }
[7297]956
[3482]957 // Clean-Up the Paramters
958 // ----------------------
959 for (int iPar = 1; iPar <= _params.size(); iPar++) {
960 delete _params[iPar-1];
[3474]961 }
[3482]962 _params.clear();
[7297]963
[3482]964 // Set new Parameters
965 // ------------------
966 int nextPar = 0;
[7297]967
[3482]968 QMapIterator<QString, int> itAC(numObsAC);
969 while (itAC.hasNext()) {
970 itAC.next();
971 const QString& AC = itAC.key();
972 int numObs = itAC.value();
973 if (AC != _masterOrbitAC && numObs > 0) {
[3485]974 _params.push_back(new cmbParam(cmbParam::offACgps, ++nextPar, AC, ""));
975 if (_useGlonass) {
976 _params.push_back(new cmbParam(cmbParam::offACglo, ++nextPar, AC, ""));
977 }
[3482]978 }
[7297]979 }
980
[3482]981 QMapIterator<QString, int> itPrn(numObsPrn);
982 while (itPrn.hasNext()) {
983 itPrn.next();
984 const QString& prn = itPrn.key();
985 int numObs = itPrn.value();
986 if (numObs > 0) {
987 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
988 }
[7297]989 }
990
[3482]991 int nPar = _params.size();
[7297]992 ColumnVector x0(nPar);
[3482]993 x0 = 0.0;
[7297]994
[3482]995 // Create First-Design Matrix
996 // --------------------------
997 Matrix AA;
998 ColumnVector ll;
999 DiagonalMatrix PP;
1000 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
1001 return failure;
[3476]1002 }
[7297]1003
[3482]1004 ColumnVector vv;
1005 try {
1006 Matrix ATP = AA.t() * PP;
1007 SymmetricMatrix NN; NN << ATP * AA;
1008 ColumnVector bb = ATP * ll;
1009 _QQ = NN.i();
1010 dx = _QQ * bb;
1011 vv = ll - AA * dx;
[3476]1012 }
[3482]1013 catch (Exception& exc) {
1014 out << exc.what() << endl;
1015 return failure;
[3476]1016 }
[3474]1017
[3482]1018 int maxResIndex;
[7297]1019 double maxRes = vv.maximum_absolute_value1(maxResIndex);
[3482]1020 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]1021 out.setRealNumberPrecision(3);
[3482]1022 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
1023 << " Maximum Residuum " << maxRes << ' '
[7715]1024 << corrs()[maxResIndex-1]->_acName << ' ' << corrs()[maxResIndex-1]->_prn.mid(0,3);
[3474]1025
[3482]1026 if (maxRes > _MAXRES) {
1027 out << " Outlier" << endl;
[3556]1028 delete corrs()[maxResIndex-1];
[3482]1029 corrs().remove(maxResIndex-1);
[3474]1030 }
[3482]1031 else {
1032 out << " OK" << endl;
1033 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]1034 out.setRealNumberPrecision(3);
[3482]1035 for (int ii = 0; ii < vv.Nrows(); ii++) {
1036 const cmbCorr* corr = corrs()[ii];
[7297]1037 out << _resTime.datestr().c_str() << ' '
[3482]1038 << _resTime.timestr().c_str() << " "
[6962]1039 << corr->_acName << ' ' << corr->_prn.mid(0,3);
[3482]1040 out.setFieldWidth(6);
[6330]1041 out << " res = " << vv[ii] << endl;
[3482]1042 out.setFieldWidth(0);
1043 }
1044 return success;
[3474]1045 }
1046
[3473]1047 }
[3474]1048
[3482]1049 return failure;
[3470]1050}
[3487]1051
1052// Check Satellite Positions for Outliers
1053////////////////////////////////////////////////////////////////////////////
[3497]1054t_irc bncComb::checkOrbits(QTextStream& out) {
[3487]1055
[3489]1056 const double MAX_DISPLACEMENT = 0.20;
[3488]1057
[3502]1058 // Switch to last ephemeris (if possible)
1059 // --------------------------------------
[3501]1060 QMutableVectorIterator<cmbCorr*> im(corrs());
1061 while (im.hasNext()) {
1062 cmbCorr* corr = im.next();
[6157]1063 QString prn = corr->_prn;
[6443]1064
[7012]1065 t_eph* ephLast = _ephUser.ephLast(prn);
1066 t_eph* ephPrev = _ephUser.ephPrev(prn);
[6443]1067
1068 if (ephLast == 0) {
[6962]1069 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << endl;
[3556]1070 delete corr;
[3501]1071 im.remove();
1072 }
[6157]1073 else if (corr->_eph == 0) {
[6962]1074 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << endl;
[3556]1075 delete corr;
[3503]1076 im.remove();
1077 }
[3502]1078 else {
[6443]1079 if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
1080 switchToLastEph(ephLast, corr);
[3502]1081 }
1082 else {
[6962]1083 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << endl;
[3556]1084 delete corr;
[3502]1085 im.remove();
1086 }
1087 }
[3501]1088 }
1089
[3488]1090 while (true) {
1091
1092 // Compute Mean Corrections for all Satellites
1093 // -------------------------------------------
[3489]1094 QMap<QString, int> numCorr;
[3488]1095 QMap<QString, ColumnVector> meanRao;
1096 QVectorIterator<cmbCorr*> it(corrs());
1097 while (it.hasNext()) {
1098 cmbCorr* corr = it.next();
[6157]1099 QString prn = corr->_prn;
[3488]1100 if (meanRao.find(prn) == meanRao.end()) {
1101 meanRao[prn].ReSize(4);
[6159]1102 meanRao[prn].Rows(1,3) = corr->_orbCorr._xr;
[7297]1103 meanRao[prn](4) = 1;
[3488]1104 }
1105 else {
[6159]1106 meanRao[prn].Rows(1,3) += corr->_orbCorr._xr;
[7297]1107 meanRao[prn](4) += 1;
[3488]1108 }
[3489]1109 if (numCorr.find(prn) == numCorr.end()) {
1110 numCorr[prn] = 1;
1111 }
1112 else {
1113 numCorr[prn] += 1;
1114 }
[3487]1115 }
[7297]1116
[3488]1117 // Compute Differences wrt Mean, find Maximum
1118 // ------------------------------------------
1119 QMap<QString, cmbCorr*> maxDiff;
1120 it.toFront();
1121 while (it.hasNext()) {
1122 cmbCorr* corr = it.next();
[6157]1123 QString prn = corr->_prn;
[3488]1124 if (meanRao[prn](4) != 0) {
1125 meanRao[prn] /= meanRao[prn](4);
1126 meanRao[prn](4) = 0;
1127 }
[6159]1128 corr->_diffRao = corr->_orbCorr._xr - meanRao[prn].Rows(1,3);
[3488]1129 if (maxDiff.find(prn) == maxDiff.end()) {
1130 maxDiff[prn] = corr;
1131 }
1132 else {
[6157]1133 double normMax = maxDiff[prn]->_diffRao.norm_Frobenius();
1134 double norm = corr->_diffRao.norm_Frobenius();
[3488]1135 if (norm > normMax) {
1136 maxDiff[prn] = corr;
1137 }
[7297]1138 }
[3487]1139 }
[7297]1140
[3655]1141 if (_ACs.size() == 1) {
1142 break;
1143 }
1144
[3488]1145 // Remove Outliers
1146 // ---------------
1147 bool removed = false;
1148 QMutableVectorIterator<cmbCorr*> im(corrs());
1149 while (im.hasNext()) {
1150 cmbCorr* corr = im.next();
[6157]1151 QString prn = corr->_prn;
[3489]1152 if (numCorr[prn] < 2) {
[3556]1153 delete corr;
[3489]1154 im.remove();
1155 }
1156 else if (corr == maxDiff[prn]) {
[6157]1157 double norm = corr->_diffRao.norm_Frobenius();
[3488]1158 if (norm > MAX_DISPLACEMENT) {
[3497]1159 out << _resTime.datestr().c_str() << " "
1160 << _resTime.timestr().c_str() << " "
[7297]1161 << "Orbit Outlier: "
1162 << corr->_acName.toAscii().data() << " "
[6963]1163 << prn.mid(0,3).toAscii().data() << " "
[7297]1164 << corr->_iod << " "
[6157]1165 << norm << endl;
[3556]1166 delete corr;
[3488]1167 im.remove();
1168 removed = true;
1169 }
1170 }
[3487]1171 }
[7297]1172
[3488]1173 if (!removed) {
1174 break;
1175 }
[3487]1176 }
1177
1178 return success;
1179}
[3588]1180
[7297]1181//
[3588]1182////////////////////////////////////////////////////////////////////////////
[5583]1183void bncComb::slotProviderIDChanged(QString mountPoint) {
1184 QMutexLocker locker(&_mutex);
1185
1186 // Find the AC Name
1187 // ----------------
1188 QString acName;
1189 QListIterator<cmbAC*> icAC(_ACs);
1190 while (icAC.hasNext()) {
1191 cmbAC* AC = icAC.next();
1192 if (AC->mountPoint == mountPoint) {
1193 acName = AC->name;
1194 break;
1195 }
1196 }
1197 if (acName.isEmpty()) {
1198 return;
1199 }
1200
1201 // Remove all corrections of the corresponding AC
1202 // ----------------------------------------------
1203 QListIterator<bncTime> itTime(_buffer.keys());
1204 while (itTime.hasNext()) {
1205 bncTime epoTime = itTime.next();
1206 QVector<cmbCorr*>& corrVec = _buffer[epoTime].corrs;
[5584]1207 QMutableVectorIterator<cmbCorr*> it(corrVec);
[5583]1208 while (it.hasNext()) {
1209 cmbCorr* corr = it.next();
[6157]1210 if (acName == corr->_acName) {
[5584]1211 delete corr;
1212 it.remove();
[5583]1213 }
1214 }
1215 }
[5585]1216
1217 // Reset Satellite Offsets
1218 // -----------------------
1219 if (_method == filter) {
1220 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1221 cmbParam* pp = _params[iPar-1];
1222 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1223 pp->xx = 0.0;
1224 _QQ.Row(iPar) = 0.0;
1225 _QQ.Column(iPar) = 0.0;
1226 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
1227 }
1228 }
1229 }
[5583]1230}
Note: See TracBrowser for help on using the repository browser.