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

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