[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"
|
---|
| 22 | #include "bncapp.h"
|
---|
[3201] | 23 | #include "upload/bncrtnetdecoder.h"
|
---|
[2910] | 24 | #include "bncsettings.h"
|
---|
[2933] | 25 | #include "bncmodel.h"
|
---|
[2988] | 26 | #include "bncutils.h"
|
---|
[3027] | 27 | #include "bncpppclient.h"
|
---|
[3181] | 28 | #include "bncsp3.h"
|
---|
[3052] | 29 | #include "bncantex.h"
|
---|
[3055] | 30 | #include "bnctides.h"
|
---|
[2898] | 31 |
|
---|
| 32 | using namespace std;
|
---|
| 33 |
|
---|
[3134] | 34 | const int MAXPRN_GPS = 32;
|
---|
| 35 |
|
---|
[2898] | 36 | // Constructor
|
---|
| 37 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3032] | 38 | cmbParam::cmbParam(cmbParam::parType type_, int index_,
|
---|
| 39 | const QString& ac_, const QString& prn_,
|
---|
| 40 | double sig_0_, double sig_P_) {
|
---|
| 41 |
|
---|
| 42 | type = type_;
|
---|
| 43 | index = index_;
|
---|
| 44 | AC = ac_;
|
---|
| 45 | prn = prn_;
|
---|
| 46 | sig_0 = sig_0_;
|
---|
| 47 | sig_P = sig_P_;
|
---|
[2933] | 48 | xx = 0.0;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | // Destructor
|
---|
| 52 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 53 | cmbParam::~cmbParam() {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // Partial
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3032] | 58 | double cmbParam::partial(const QString& AC_, t_corr* corr) {
|
---|
[2933] | 59 |
|
---|
[2934] | 60 | if (type == AC_offset) {
|
---|
[3032] | 61 | if (AC == AC_) {
|
---|
[2934] | 62 | return 1.0;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | else if (type == Sat_offset) {
|
---|
[3032] | 66 | if (AC == AC_ && prn == corr->prn) {
|
---|
[2933] | 67 | return 1.0;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | else if (type == clk) {
|
---|
| 71 | if (prn == corr->prn) {
|
---|
| 72 | return 1.0;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | return 0.0;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[2990] | 79 | //
|
---|
| 80 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 81 | QString cmbParam::toString() const {
|
---|
[2933] | 82 |
|
---|
[2990] | 83 | QString outStr;
|
---|
| 84 |
|
---|
| 85 | if (type == AC_offset) {
|
---|
[2992] | 86 | outStr = "AC offset " + AC;
|
---|
[2990] | 87 | }
|
---|
| 88 | else if (type == Sat_offset) {
|
---|
[2992] | 89 | outStr = "Sat Offset " + AC + " " + prn;
|
---|
[2990] | 90 | }
|
---|
| 91 | else if (type == clk) {
|
---|
[2992] | 92 | outStr = "Clk Corr " + prn;
|
---|
[2990] | 93 | }
|
---|
[2933] | 94 |
|
---|
[2990] | 95 | return outStr;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[2933] | 98 | // Constructor
|
---|
| 99 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2898] | 100 | bncComb::bncComb() {
|
---|
[2910] | 101 |
|
---|
| 102 | bncSettings settings;
|
---|
| 103 |
|
---|
| 104 | QStringList combineStreams = settings.value("combineStreams").toStringList();
|
---|
[2918] | 105 |
|
---|
[3143] | 106 | if (combineStreams.size() >= 1 && !combineStreams[0].isEmpty()) {
|
---|
[2910] | 107 | QListIterator<QString> it(combineStreams);
|
---|
| 108 | while (it.hasNext()) {
|
---|
| 109 | QStringList hlp = it.next().split(" ");
|
---|
[2918] | 110 | cmbAC* newAC = new cmbAC();
|
---|
| 111 | newAC->mountPoint = hlp[0];
|
---|
| 112 | newAC->name = hlp[1];
|
---|
| 113 | newAC->weight = hlp[2].toDouble();
|
---|
[3064] | 114 | if (_masterAC.isEmpty()) {
|
---|
| 115 | _masterAC = newAC->name;
|
---|
| 116 | }
|
---|
[2918] | 117 | _ACs[newAC->mountPoint] = newAC;
|
---|
[2910] | 118 | }
|
---|
| 119 | }
|
---|
[2927] | 120 |
|
---|
[3211] | 121 | _rtnetDecoder = 0;
|
---|
[3201] | 122 |
|
---|
[2990] | 123 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 124 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
[2933] | 125 |
|
---|
[3032] | 126 |
|
---|
| 127 | // A Priori Sigmas (in Meters)
|
---|
| 128 | // ---------------------------
|
---|
| 129 | double sigAC_0 = 100.0;
|
---|
| 130 | double sigAC_P = 100.0;
|
---|
| 131 | double sigSat_0 = 100.0;
|
---|
| 132 | double sigSat_P = 0.0;
|
---|
| 133 | double sigClk_0 = 100.0;
|
---|
| 134 | double sigClk_P = 100.0;
|
---|
| 135 |
|
---|
| 136 | // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
|
---|
| 137 | // ----------------------------------------------------------------------
|
---|
[2933] | 138 | int nextPar = 0;
|
---|
[2991] | 139 | QMapIterator<QString, cmbAC*> it(_ACs);
|
---|
| 140 | while (it.hasNext()) {
|
---|
| 141 | it.next();
|
---|
| 142 | cmbAC* AC = it.value();
|
---|
[3134] | 143 | _params.push_back(new cmbParam(cmbParam::AC_offset, ++nextPar,
|
---|
| 144 | AC->name, "", sigAC_0, sigAC_P));
|
---|
| 145 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
| 146 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
| 147 | _params.push_back(new cmbParam(cmbParam::Sat_offset, ++nextPar,
|
---|
| 148 | AC->name, prn, sigSat_0, sigSat_P));
|
---|
[2991] | 149 | }
|
---|
| 150 | }
|
---|
[3134] | 151 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
[2933] | 152 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
[3032] | 153 | _params.push_back(new cmbParam(cmbParam::clk, ++nextPar, "", prn,
|
---|
| 154 | sigClk_0, sigClk_P));
|
---|
[2933] | 155 | }
|
---|
| 156 |
|
---|
[3032] | 157 | // Initialize Variance-Covariance Matrix
|
---|
| 158 | // -------------------------------------
|
---|
| 159 | _QQ.ReSize(_params.size());
|
---|
[2933] | 160 | _QQ = 0.0;
|
---|
| 161 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 162 | cmbParam* pp = _params[iPar-1];
|
---|
[3032] | 163 | _QQ(iPar,iPar) = pp->sig_0 * pp->sig_0;
|
---|
[2933] | 164 | }
|
---|
[3035] | 165 |
|
---|
[3052] | 166 | // ANTEX File
|
---|
| 167 | // ----------
|
---|
| 168 | _antex = 0;
|
---|
| 169 | QString antexFileName = settings.value("pppAntex").toString();
|
---|
| 170 | if (!antexFileName.isEmpty()) {
|
---|
| 171 | _antex = new bncAntex();
|
---|
| 172 | if (_antex->readFile(antexFileName) != success) {
|
---|
| 173 | emit newMessage("wrong ANTEX file", true);
|
---|
| 174 | delete _antex;
|
---|
| 175 | _antex = 0;
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
[3138] | 178 |
|
---|
| 179 | // Not yet regularized
|
---|
| 180 | // -------------------
|
---|
| 181 | _firstReg = false;
|
---|
[3329] | 182 |
|
---|
| 183 | // Maximal Residuum
|
---|
| 184 | // ----------------
|
---|
| 185 | _MAXRES = settings.value("cmbMaxres").toDouble();
|
---|
| 186 | if (_MAXRES <= 0.0) {
|
---|
| 187 | _MAXRES = 999.0;
|
---|
| 188 | }
|
---|
[2898] | 189 | }
|
---|
| 190 |
|
---|
| 191 | // Destructor
|
---|
| 192 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 193 | bncComb::~bncComb() {
|
---|
[2918] | 194 | QMapIterator<QString, cmbAC*> it(_ACs);
|
---|
| 195 | while (it.hasNext()) {
|
---|
| 196 | it.next();
|
---|
| 197 | delete it.value();
|
---|
| 198 | }
|
---|
[3201] | 199 | delete _rtnetDecoder;
|
---|
[3052] | 200 | delete _antex;
|
---|
[3296] | 201 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 202 | delete _params[iPar-1];
|
---|
| 203 | }
|
---|
[2898] | 204 | }
|
---|
| 205 |
|
---|
[2928] | 206 | // Read and store one correction line
|
---|
[2898] | 207 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 208 | void bncComb::processCorrLine(const QString& staID, const QString& line) {
|
---|
[2906] | 209 | QMutexLocker locker(&_mutex);
|
---|
[2913] | 210 |
|
---|
[2918] | 211 | // Find the relevant instance of cmbAC class
|
---|
| 212 | // -----------------------------------------
|
---|
| 213 | if (_ACs.find(staID) == _ACs.end()) {
|
---|
| 214 | return;
|
---|
| 215 | }
|
---|
| 216 | cmbAC* AC = _ACs[staID];
|
---|
| 217 |
|
---|
| 218 | // Read the Correction
|
---|
| 219 | // -------------------
|
---|
[2913] | 220 | t_corr* newCorr = new t_corr();
|
---|
| 221 | if (!newCorr->readLine(line) == success) {
|
---|
| 222 | delete newCorr;
|
---|
| 223 | return;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[3274] | 226 | // Check Modulo Time
|
---|
| 227 | // -----------------
|
---|
| 228 | const int moduloTime = 10;
|
---|
| 229 | if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
|
---|
| 230 | delete newCorr;
|
---|
| 231 | return;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[3299] | 234 | // Remember last correction time
|
---|
| 235 | // -----------------------------
|
---|
| 236 | if (!_lastCorrTime.valid() || _lastCorrTime < newCorr->tt) {
|
---|
| 237 | _lastCorrTime = newCorr->tt;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | bncTime processTime = _lastCorrTime - 1.5 * moduloTime;
|
---|
| 241 |
|
---|
| 242 | // Delete old corrections
|
---|
| 243 | // ----------------------
|
---|
| 244 | if (newCorr->tt < processTime) {
|
---|
[2924] | 245 | delete newCorr;
|
---|
| 246 | return;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[3029] | 249 | // Check the Ephemeris
|
---|
| 250 | //--------------------
|
---|
[2986] | 251 | if (_eph.find(newCorr->prn) == _eph.end()) {
|
---|
| 252 | delete newCorr;
|
---|
| 253 | return;
|
---|
| 254 | }
|
---|
| 255 | else {
|
---|
| 256 | t_eph* lastEph = _eph[newCorr->prn]->last;
|
---|
| 257 | t_eph* prevEph = _eph[newCorr->prn]->prev;
|
---|
[3029] | 258 | if (lastEph && lastEph->IOD() == newCorr->iod) {
|
---|
| 259 | newCorr->eph = lastEph;
|
---|
[2986] | 260 | }
|
---|
[3029] | 261 | else if (prevEph && prevEph->IOD() == newCorr->iod) {
|
---|
| 262 | newCorr->eph = prevEph;
|
---|
| 263 | }
|
---|
| 264 | else {
|
---|
[2986] | 265 | delete newCorr;
|
---|
| 266 | return;
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 |
|
---|
[2924] | 270 | // Process all older Epochs (if there are any)
|
---|
| 271 | // -------------------------------------------
|
---|
[2927] | 272 | QList<cmbEpoch*> epochsToProcess;
|
---|
| 273 | QMapIterator<QString, cmbAC*> itAC(_ACs);
|
---|
| 274 | while (itAC.hasNext()) {
|
---|
| 275 | itAC.next();
|
---|
| 276 | cmbAC* AC = itAC.value();
|
---|
| 277 | QMutableListIterator<cmbEpoch*> itEpo(AC->epochs);
|
---|
| 278 | while (itEpo.hasNext()) {
|
---|
| 279 | cmbEpoch* epoch = itEpo.next();
|
---|
[3299] | 280 | if (epoch->time <= processTime) {
|
---|
[2927] | 281 | epochsToProcess.append(epoch);
|
---|
| 282 | itEpo.remove();
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | if (epochsToProcess.size()) {
|
---|
| 288 | processEpochs(epochsToProcess);
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[2918] | 291 | // Find/Create the instance of cmbEpoch class
|
---|
| 292 | // ------------------------------------------
|
---|
| 293 | cmbEpoch* newEpoch = 0;
|
---|
| 294 | QListIterator<cmbEpoch*> it(AC->epochs);
|
---|
| 295 | while (it.hasNext()) {
|
---|
| 296 | cmbEpoch* hlpEpoch = it.next();
|
---|
| 297 | if (hlpEpoch->time == newCorr->tt) {
|
---|
| 298 | newEpoch = hlpEpoch;
|
---|
| 299 | break;
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | if (newEpoch == 0) {
|
---|
[2927] | 303 | newEpoch = new cmbEpoch(AC->name);
|
---|
[2918] | 304 | newEpoch->time = newCorr->tt;
|
---|
| 305 | AC->epochs.append(newEpoch);
|
---|
| 306 | }
|
---|
[2924] | 307 |
|
---|
| 308 | // Merge or add the correction
|
---|
| 309 | // ---------------------------
|
---|
[2918] | 310 | if (newEpoch->corr.find(newCorr->prn) != newEpoch->corr.end()) {
|
---|
[2919] | 311 | newEpoch->corr[newCorr->prn]->readLine(line); // merge (multiple messages)
|
---|
[3298] | 312 | delete newCorr;
|
---|
[2918] | 313 | }
|
---|
[2919] | 314 | else {
|
---|
| 315 | newEpoch->corr[newCorr->prn] = newCorr;
|
---|
| 316 | }
|
---|
[2898] | 317 | }
|
---|
| 318 |
|
---|
[2986] | 319 | // Change the correction so that it refers to last received ephemeris
|
---|
| 320 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3029] | 321 | void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
|
---|
[3028] | 322 |
|
---|
[2987] | 323 | ColumnVector oldXC(4);
|
---|
| 324 | ColumnVector oldVV(3);
|
---|
[3029] | 325 | corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
| 326 | oldXC.data(), oldVV.data());
|
---|
[2988] | 327 |
|
---|
[2987] | 328 | ColumnVector newXC(4);
|
---|
| 329 | ColumnVector newVV(3);
|
---|
[3029] | 330 | lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
[2987] | 331 | newXC.data(), newVV.data());
|
---|
[2988] | 332 |
|
---|
| 333 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
---|
[2989] | 334 | ColumnVector dV = newVV - oldVV;
|
---|
| 335 | double dC = newXC(4) - oldXC(4);
|
---|
| 336 |
|
---|
[2988] | 337 | ColumnVector dRAO(3);
|
---|
| 338 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
---|
[2989] | 339 |
|
---|
| 340 | ColumnVector dDotRAO(3);
|
---|
| 341 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
---|
| 342 |
|
---|
[3029] | 343 | QString msg = "switch " + corr->prn
|
---|
| 344 | + QString(" %1 -> %2 %3").arg(corr->iod,3)
|
---|
[3013] | 345 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
| 346 |
|
---|
[3029] | 347 | emit newMessage(msg.toAscii(), false);
|
---|
[3028] | 348 |
|
---|
[3029] | 349 | corr->iod = lastEph->IOD();
|
---|
| 350 | corr->eph = lastEph;
|
---|
[3031] | 351 | corr->rao += dRAO;
|
---|
| 352 | corr->dotRao += dDotRAO;
|
---|
[3029] | 353 | corr->dClk -= dC;
|
---|
[2986] | 354 | }
|
---|
| 355 |
|
---|
[2928] | 356 | // Process Epochs
|
---|
| 357 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2927] | 358 | void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
|
---|
[2918] | 359 |
|
---|
[2990] | 360 | _log.clear();
|
---|
| 361 |
|
---|
| 362 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
| 363 |
|
---|
[2991] | 364 | out << "Combination:" << endl
|
---|
[3275] | 365 | << "------------------------------" << endl;
|
---|
[2990] | 366 |
|
---|
[3277] | 367 | // Check whether master AC present
|
---|
| 368 | // -------------------------------
|
---|
| 369 | if (epochs.first()->acName != _masterAC) {
|
---|
[3339] | 370 | if (true) { // version with master switch
|
---|
| 371 | cmbEpoch* epo = epochs.first();
|
---|
[3277] | 372 | bncTime epoTime = epo->time;
|
---|
[3339] | 373 | out << "Switching Master AC "
|
---|
| 374 | << epo->acName.toAscii().data() << " --> "
|
---|
| 375 | << _masterAC.toAscii().data() << " "
|
---|
[3277] | 376 | << epoTime.datestr().c_str() << " "
|
---|
[3339] | 377 | << epoTime.timestr().c_str() << endl;
|
---|
| 378 | _masterAC = epo->acName;
|
---|
[3277] | 379 | }
|
---|
[3339] | 380 | else { // original version
|
---|
| 381 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 382 | while (itEpo.hasNext()) {
|
---|
| 383 | cmbEpoch* epo = itEpo.next();
|
---|
| 384 | bncTime epoTime = epo->time;
|
---|
| 385 | out << epo->acName.toAscii().data() << " "
|
---|
| 386 | << epoTime.datestr().c_str() << " "
|
---|
| 387 | << epoTime.timestr().c_str() << endl;
|
---|
| 388 | delete epo;
|
---|
| 389 | }
|
---|
| 390 | out << "Missing Master AC" << endl;
|
---|
| 391 | emit newMessage(_log, false);
|
---|
| 392 | return;
|
---|
| 393 | }
|
---|
[3277] | 394 | }
|
---|
| 395 |
|
---|
[2933] | 396 | // Predict Parameters Values, Add White Noise
|
---|
| 397 | // ------------------------------------------
|
---|
| 398 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 399 | cmbParam* pp = _params[iPar-1];
|
---|
[3032] | 400 | if (pp->sig_P != 0.0) {
|
---|
[2933] | 401 | pp->xx = 0.0;
|
---|
| 402 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 403 | _QQ(iPar, jj) = 0.0;
|
---|
| 404 | }
|
---|
[3032] | 405 | _QQ(iPar,iPar) = pp->sig_P * pp->sig_P;
|
---|
[2933] | 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
[2928] | 409 | bncTime resTime = epochs.first()->time;
|
---|
| 410 | QMap<QString, t_corr*> resCorr;
|
---|
| 411 |
|
---|
[2933] | 412 | int nPar = _params.size();
|
---|
| 413 | int nObs = 0;
|
---|
| 414 |
|
---|
| 415 | ColumnVector x0(nPar);
|
---|
| 416 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 417 | cmbParam* pp = _params[iPar-1];
|
---|
| 418 | x0(iPar) = pp->xx;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | // Count Observations
|
---|
| 422 | // ------------------
|
---|
[2927] | 423 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 424 | while (itEpo.hasNext()) {
|
---|
[3274] | 425 | cmbEpoch* epo = itEpo.next();
|
---|
| 426 | bncTime epoTime = epo->time;
|
---|
[3275] | 427 | out << epo->acName.toAscii().data() << " "
|
---|
| 428 | << epoTime.datestr().c_str() << " "
|
---|
| 429 | << epoTime.timestr().c_str() << endl;
|
---|
[3274] | 430 |
|
---|
[3029] | 431 | QMutableMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
[2927] | 432 | while (itCorr.hasNext()) {
|
---|
| 433 | itCorr.next();
|
---|
[3029] | 434 | t_corr* corr = itCorr.value();
|
---|
| 435 |
|
---|
[3032] | 436 | // Switch to last ephemeris
|
---|
| 437 | // ------------------------
|
---|
[3029] | 438 | t_eph* lastEph = _eph[corr->prn]->last;
|
---|
| 439 | if (lastEph == corr->eph) {
|
---|
| 440 | ++nObs;
|
---|
| 441 | }
|
---|
| 442 | else {
|
---|
| 443 | if (corr->eph == _eph[corr->prn]->prev) {
|
---|
| 444 | switchToLastEph(lastEph, corr);
|
---|
| 445 | ++nObs;
|
---|
| 446 | }
|
---|
| 447 | else {
|
---|
| 448 | itCorr.remove();
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
[2933] | 451 | }
|
---|
| 452 | }
|
---|
[2928] | 453 |
|
---|
[2933] | 454 | if (nObs > 0) {
|
---|
[3135] | 455 | const double Pl = 1.0 / (0.05 * 0.05);
|
---|
| 456 |
|
---|
[3140] | 457 | const int nCon = (_firstReg == false) ? 1 + MAXPRN_GPS : 1;
|
---|
[3134] | 458 | Matrix AA(nObs+nCon, nPar); AA = 0.0;
|
---|
| 459 | ColumnVector ll(nObs+nCon); ll = 0.0;
|
---|
[3135] | 460 | DiagonalMatrix PP(nObs+nCon); PP = Pl;
|
---|
[2933] | 461 |
|
---|
| 462 | int iObs = 0;
|
---|
| 463 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 464 | while (itEpo.hasNext()) {
|
---|
| 465 | cmbEpoch* epo = itEpo.next();
|
---|
| 466 | QMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
| 467 |
|
---|
| 468 | while (itCorr.hasNext()) {
|
---|
| 469 | itCorr.next();
|
---|
| 470 | ++iObs;
|
---|
| 471 | t_corr* corr = itCorr.value();
|
---|
| 472 |
|
---|
[3032] | 473 | if (epo->acName == _masterAC) {
|
---|
[2933] | 474 | resCorr[corr->prn] = new t_corr(*corr);
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 478 | cmbParam* pp = _params[iPar-1];
|
---|
| 479 | AA(iObs, iPar) = pp->partial(epo->acName, corr);
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
|
---|
[3034] | 483 | }
|
---|
[2933] | 484 | }
|
---|
[2928] | 485 |
|
---|
[3134] | 486 | // Regularization
|
---|
| 487 | // --------------
|
---|
| 488 | const double Ph = 1.e6;
|
---|
| 489 | int iCond = 1;
|
---|
| 490 | PP(nObs+iCond) = Ph;
|
---|
| 491 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 492 | cmbParam* pp = _params[iPar-1];
|
---|
[3136] | 493 | if (pp->type == cmbParam::clk &&
|
---|
| 494 | AA.Column(iPar).maximum_absolute_value() > 0.0) {
|
---|
| 495 | AA(nObs+iCond, iPar) = 1.0;
|
---|
[3134] | 496 | }
|
---|
| 497 | }
|
---|
| 498 |
|
---|
[3138] | 499 | if (!_firstReg) {
|
---|
| 500 | _firstReg = true;
|
---|
| 501 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
| 502 | ++iCond;
|
---|
| 503 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
| 504 | PP(nObs+1+iGps) = Ph;
|
---|
| 505 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 506 | cmbParam* pp = _params[iPar-1];
|
---|
| 507 | if (pp->type == cmbParam::Sat_offset && pp->prn == prn) {
|
---|
| 508 | AA(nObs+iCond, iPar) = 1.0;
|
---|
| 509 | }
|
---|
[3134] | 510 | }
|
---|
| 511 | }
|
---|
| 512 | }
|
---|
| 513 |
|
---|
[2933] | 514 | ColumnVector dx;
|
---|
[3080] | 515 | SymmetricMatrix QQ_sav = _QQ;
|
---|
[2933] | 516 |
|
---|
[3080] | 517 | for (int ii = 1; ii < 10; ii++) {
|
---|
| 518 | bncModel::kalman(AA, ll, PP, _QQ, dx);
|
---|
| 519 | ColumnVector vv = ll - AA * dx;
|
---|
| 520 |
|
---|
| 521 | int maxResIndex;
|
---|
| 522 | double maxRes = vv.maximum_absolute_value1(maxResIndex);
|
---|
| 523 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
| 524 | out.setRealNumberPrecision(3);
|
---|
| 525 | out << "Maximum Residuum " << maxRes << " (index " << maxResIndex << ")\n";
|
---|
| 526 |
|
---|
[3329] | 527 | if (maxRes > _MAXRES) {
|
---|
[3080] | 528 | out << "Outlier Detected" << endl;
|
---|
| 529 | _QQ = QQ_sav;
|
---|
| 530 | AA.Row(maxResIndex) = 0.0;
|
---|
| 531 | ll.Row(maxResIndex) = 0.0;
|
---|
| 532 | }
|
---|
| 533 | else {
|
---|
| 534 | break;
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 |
|
---|
[2933] | 538 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 539 | cmbParam* pp = _params[iPar-1];
|
---|
| 540 | pp->xx += dx(iPar);
|
---|
[2935] | 541 | if (pp->type == cmbParam::clk) {
|
---|
[2936] | 542 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
---|
| 543 | resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
|
---|
| 544 | }
|
---|
[2935] | 545 | }
|
---|
[3011] | 546 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
[2990] | 547 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
| 548 | out.setFieldWidth(8);
|
---|
| 549 | out.setRealNumberPrecision(4);
|
---|
| 550 | out << pp->toString() << " "
|
---|
[2991] | 551 | << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
|
---|
[2918] | 552 | }
|
---|
| 553 | }
|
---|
[2919] | 554 |
|
---|
[3015] | 555 | printResults(out, resTime, resCorr);
|
---|
[2928] | 556 | dumpResults(resTime, resCorr);
|
---|
| 557 |
|
---|
[2990] | 558 | emit newMessage(_log, false);
|
---|
[3296] | 559 |
|
---|
| 560 | QListIterator<cmbEpoch*> itEpo2(epochs);
|
---|
| 561 | while (itEpo2.hasNext()) {
|
---|
| 562 | cmbEpoch* epo = itEpo2.next();
|
---|
| 563 | delete epo;
|
---|
| 564 | }
|
---|
[2918] | 565 | }
|
---|
[3011] | 566 |
|
---|
[3201] | 567 | // Print results
|
---|
[3011] | 568 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3015] | 569 | void bncComb::printResults(QTextStream& out, const bncTime& resTime,
|
---|
[3011] | 570 | const QMap<QString, t_corr*>& resCorr) {
|
---|
| 571 |
|
---|
| 572 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
| 573 | while (it.hasNext()) {
|
---|
| 574 | it.next();
|
---|
| 575 | t_corr* corr = it.value();
|
---|
[3029] | 576 | const t_eph* eph = corr->eph;
|
---|
[3015] | 577 | if (eph) {
|
---|
| 578 | double xx, yy, zz, cc;
|
---|
| 579 | eph->position(resTime.gpsw(), resTime.gpssec(), xx, yy, zz, cc);
|
---|
| 580 |
|
---|
| 581 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
| 582 | out.setFieldWidth(3);
|
---|
| 583 | out << "Full Clock " << corr->prn << " " << corr->iod << " ";
|
---|
| 584 | out.setFieldWidth(14);
|
---|
| 585 | out << (cc + corr->dClk) * t_CST::c << endl;
|
---|
| 586 | }
|
---|
| 587 | else {
|
---|
| 588 | out << "bncComb::printResuls bug" << endl;
|
---|
| 589 | }
|
---|
[3011] | 590 | }
|
---|
| 591 | }
|
---|
[3202] | 592 |
|
---|
| 593 | // Send results to RTNet Decoder and directly to PPP Client
|
---|
| 594 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 595 | void bncComb::dumpResults(const bncTime& resTime,
|
---|
| 596 | const QMap<QString, t_corr*>& resCorr) {
|
---|
| 597 |
|
---|
[3214] | 598 | ostringstream out; out.setf(std::ios::fixed);
|
---|
[3216] | 599 | QStringList corrLines;
|
---|
[3214] | 600 |
|
---|
| 601 | unsigned year, month, day, hour, minute;
|
---|
| 602 | double sec;
|
---|
| 603 | resTime.civil_date(year, month, day);
|
---|
| 604 | resTime.civil_time(hour, minute, sec);
|
---|
| 605 |
|
---|
| 606 | out << "* "
|
---|
| 607 | << setw(4) << year << " "
|
---|
| 608 | << setw(2) << month << " "
|
---|
| 609 | << setw(2) << day << " "
|
---|
| 610 | << setw(2) << hour << " "
|
---|
| 611 | << setw(2) << minute << " "
|
---|
| 612 | << setw(12) << setprecision(8) << sec << " "
|
---|
| 613 | << endl;
|
---|
| 614 |
|
---|
[3202] | 615 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
| 616 | while (it.hasNext()) {
|
---|
| 617 | it.next();
|
---|
| 618 | t_corr* corr = it.value();
|
---|
| 619 |
|
---|
[3214] | 620 | double dT = 60.0;
|
---|
[3202] | 621 |
|
---|
[3214] | 622 | for (int iTime = 1; iTime <= 2; iTime++) {
|
---|
| 623 |
|
---|
| 624 | bncTime time12 = (iTime == 1) ? resTime : resTime + dT;
|
---|
| 625 |
|
---|
| 626 | ColumnVector xc(4);
|
---|
| 627 | ColumnVector vv(3);
|
---|
| 628 | corr->eph->position(time12.gpsw(), time12.gpssec(),
|
---|
| 629 | xc.data(), vv.data());
|
---|
| 630 | bncPPPclient::applyCorr(time12, corr, xc, vv);
|
---|
| 631 |
|
---|
| 632 | // Relativistic Correction
|
---|
| 633 | // -----------------------
|
---|
| 634 | double relCorr = - 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
|
---|
| 635 | xc(4) -= relCorr;
|
---|
| 636 |
|
---|
| 637 | // Code Biases
|
---|
| 638 | // -----------
|
---|
| 639 | double dcbP1C1 = 0.0;
|
---|
| 640 | double dcbP1P2 = 0.0;
|
---|
| 641 |
|
---|
| 642 | // Correction Phase Center --> CoM
|
---|
| 643 | // -------------------------------
|
---|
| 644 | ColumnVector dx(3); dx = 0.0;
|
---|
| 645 | if (_antex) {
|
---|
| 646 | double Mjd = time12.mjd() + time12.daysec()/86400.0;
|
---|
| 647 | if (_antex->satCoMcorrection(corr->prn, Mjd, xc.Rows(1,3), dx) == success) {
|
---|
| 648 | xc(1) -= dx(1);
|
---|
| 649 | xc(2) -= dx(2);
|
---|
| 650 | xc(3) -= dx(3);
|
---|
| 651 | }
|
---|
| 652 | else {
|
---|
| 653 | cout << "antenna not found" << endl;
|
---|
| 654 | }
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 | if (iTime == 1) {
|
---|
| 658 | out << 'P' << corr->prn.toAscii().data()
|
---|
| 659 | << setw(14) << setprecision(6) << xc(1) / 1000.0
|
---|
| 660 | << setw(14) << setprecision(6) << xc(2) / 1000.0
|
---|
| 661 | << setw(14) << setprecision(6) << xc(3) / 1000.0
|
---|
| 662 | << setw(14) << setprecision(6) << xc(4) * 1e6
|
---|
| 663 | << setw(14) << setprecision(6) << relCorr * 1e6
|
---|
| 664 | << setw(8) << setprecision(3) << dx(1)
|
---|
| 665 | << setw(8) << setprecision(3) << dx(2)
|
---|
| 666 | << setw(8) << setprecision(3) << dx(3)
|
---|
| 667 | << setw(8) << setprecision(3) << dcbP1C1
|
---|
| 668 | << setw(8) << setprecision(3) << dcbP1P2
|
---|
| 669 | << setw(6) << setprecision(1) << dT;
|
---|
[3216] | 670 |
|
---|
[3218] | 671 | QString line;
|
---|
[3217] | 672 | int messageType = COTYPE_GPSCOMBINED;
|
---|
[3218] | 673 | int updateInt = 0;
|
---|
| 674 | line.sprintf("%d %d %d %.1f %s"
|
---|
| 675 | " %3d"
|
---|
| 676 | " %8.3f %8.3f %8.3f %8.3f"
|
---|
| 677 | " %10.5f %10.5f %10.5f %10.5f"
|
---|
[3262] | 678 | " %10.5f %10.5f %10.5f %10.5f INTERNAL",
|
---|
[3218] | 679 | messageType, updateInt, time12.gpsw(), time12.gpssec(),
|
---|
| 680 | corr->prn.toAscii().data(),
|
---|
| 681 | corr->iod,
|
---|
[3219] | 682 | corr->dClk * t_CST::c,
|
---|
[3218] | 683 | corr->rao[0],
|
---|
| 684 | corr->rao[1],
|
---|
| 685 | corr->rao[2],
|
---|
[3219] | 686 | corr->dotDClk * t_CST::c,
|
---|
[3218] | 687 | corr->dotRao[0],
|
---|
| 688 | corr->dotRao[1],
|
---|
| 689 | corr->dotRao[2],
|
---|
[3262] | 690 | corr->dotDotDClk * t_CST::c,
|
---|
| 691 | corr->dotDotRao[0],
|
---|
| 692 | corr->dotDotRao[1],
|
---|
| 693 | corr->dotDotRao[2]);
|
---|
[3220] | 694 | corrLines << line;
|
---|
[3214] | 695 | }
|
---|
| 696 | else {
|
---|
| 697 | out << setw(14) << setprecision(6) << xc(1) / 1000.0
|
---|
| 698 | << setw(14) << setprecision(6) << xc(2) / 1000.0
|
---|
| 699 | << setw(14) << setprecision(6) << xc(3) / 1000.0 << endl;
|
---|
| 700 | }
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | delete corr;
|
---|
| 704 | }
|
---|
[3228] | 705 | out << "EOE" << endl; // End Of Epoch flag
|
---|
[3214] | 706 |
|
---|
[3215] | 707 | if (!_rtnetDecoder) {
|
---|
| 708 | _rtnetDecoder = new bncRtnetDecoder();
|
---|
| 709 | }
|
---|
[3221] | 710 |
|
---|
[3215] | 711 | vector<string> errmsg;
|
---|
[3221] | 712 | _rtnetDecoder->Decode((char*) out.str().data(), out.str().size(), errmsg);
|
---|
[3215] | 713 |
|
---|
[3216] | 714 | // Optionally send new Corrections to PPP
|
---|
| 715 | // --------------------------------------
|
---|
| 716 | bncApp* app = (bncApp*) qApp;
|
---|
| 717 | if (app->_bncPPPclient) {
|
---|
| 718 | app->_bncPPPclient->slotNewCorrections(corrLines);
|
---|
| 719 | }
|
---|
[3202] | 720 | }
|
---|