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

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