[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;
|
---|
[2898] | 182 | }
|
---|
| 183 |
|
---|
| 184 | // Destructor
|
---|
| 185 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 186 | bncComb::~bncComb() {
|
---|
[2918] | 187 | QMapIterator<QString, cmbAC*> it(_ACs);
|
---|
| 188 | while (it.hasNext()) {
|
---|
| 189 | it.next();
|
---|
| 190 | delete it.value();
|
---|
| 191 | }
|
---|
[3201] | 192 | delete _rtnetDecoder;
|
---|
[3052] | 193 | delete _antex;
|
---|
[3296] | 194 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 195 | delete _params[iPar-1];
|
---|
| 196 | }
|
---|
[2898] | 197 | }
|
---|
| 198 |
|
---|
[2928] | 199 | // Read and store one correction line
|
---|
[2898] | 200 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 201 | void bncComb::processCorrLine(const QString& staID, const QString& line) {
|
---|
[2906] | 202 | QMutexLocker locker(&_mutex);
|
---|
[2913] | 203 |
|
---|
[2918] | 204 | // Find the relevant instance of cmbAC class
|
---|
| 205 | // -----------------------------------------
|
---|
| 206 | if (_ACs.find(staID) == _ACs.end()) {
|
---|
| 207 | return;
|
---|
| 208 | }
|
---|
| 209 | cmbAC* AC = _ACs[staID];
|
---|
| 210 |
|
---|
| 211 | // Read the Correction
|
---|
| 212 | // -------------------
|
---|
[2913] | 213 | t_corr* newCorr = new t_corr();
|
---|
| 214 | if (!newCorr->readLine(line) == success) {
|
---|
| 215 | delete newCorr;
|
---|
| 216 | return;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
[3274] | 219 | // Check Modulo Time
|
---|
| 220 | // -----------------
|
---|
| 221 | const int moduloTime = 10;
|
---|
| 222 | if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
|
---|
| 223 | delete newCorr;
|
---|
| 224 | return;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
[3299] | 227 | // Remember last correction time
|
---|
| 228 | // -----------------------------
|
---|
| 229 | if (!_lastCorrTime.valid() || _lastCorrTime < newCorr->tt) {
|
---|
| 230 | _lastCorrTime = newCorr->tt;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | bncTime processTime = _lastCorrTime - 1.5 * moduloTime;
|
---|
| 234 |
|
---|
| 235 | // Delete old corrections
|
---|
| 236 | // ----------------------
|
---|
| 237 | if (newCorr->tt < processTime) {
|
---|
[2924] | 238 | delete newCorr;
|
---|
| 239 | return;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[3029] | 242 | // Check the Ephemeris
|
---|
| 243 | //--------------------
|
---|
[2986] | 244 | if (_eph.find(newCorr->prn) == _eph.end()) {
|
---|
| 245 | delete newCorr;
|
---|
| 246 | return;
|
---|
| 247 | }
|
---|
| 248 | else {
|
---|
| 249 | t_eph* lastEph = _eph[newCorr->prn]->last;
|
---|
| 250 | t_eph* prevEph = _eph[newCorr->prn]->prev;
|
---|
[3029] | 251 | if (lastEph && lastEph->IOD() == newCorr->iod) {
|
---|
| 252 | newCorr->eph = lastEph;
|
---|
[2986] | 253 | }
|
---|
[3029] | 254 | else if (prevEph && prevEph->IOD() == newCorr->iod) {
|
---|
| 255 | newCorr->eph = prevEph;
|
---|
| 256 | }
|
---|
| 257 | else {
|
---|
[2986] | 258 | delete newCorr;
|
---|
| 259 | return;
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[2924] | 263 | // Process all older Epochs (if there are any)
|
---|
| 264 | // -------------------------------------------
|
---|
[2927] | 265 | QList<cmbEpoch*> epochsToProcess;
|
---|
| 266 | QMapIterator<QString, cmbAC*> itAC(_ACs);
|
---|
| 267 | while (itAC.hasNext()) {
|
---|
| 268 | itAC.next();
|
---|
| 269 | cmbAC* AC = itAC.value();
|
---|
| 270 | QMutableListIterator<cmbEpoch*> itEpo(AC->epochs);
|
---|
| 271 | while (itEpo.hasNext()) {
|
---|
| 272 | cmbEpoch* epoch = itEpo.next();
|
---|
[3299] | 273 | if (epoch->time <= processTime) {
|
---|
[2927] | 274 | epochsToProcess.append(epoch);
|
---|
| 275 | itEpo.remove();
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | if (epochsToProcess.size()) {
|
---|
| 281 | processEpochs(epochsToProcess);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[2918] | 284 | // Find/Create the instance of cmbEpoch class
|
---|
| 285 | // ------------------------------------------
|
---|
| 286 | cmbEpoch* newEpoch = 0;
|
---|
| 287 | QListIterator<cmbEpoch*> it(AC->epochs);
|
---|
| 288 | while (it.hasNext()) {
|
---|
| 289 | cmbEpoch* hlpEpoch = it.next();
|
---|
| 290 | if (hlpEpoch->time == newCorr->tt) {
|
---|
| 291 | newEpoch = hlpEpoch;
|
---|
| 292 | break;
|
---|
| 293 | }
|
---|
| 294 | }
|
---|
| 295 | if (newEpoch == 0) {
|
---|
[2927] | 296 | newEpoch = new cmbEpoch(AC->name);
|
---|
[2918] | 297 | newEpoch->time = newCorr->tt;
|
---|
| 298 | AC->epochs.append(newEpoch);
|
---|
| 299 | }
|
---|
[2924] | 300 |
|
---|
| 301 | // Merge or add the correction
|
---|
| 302 | // ---------------------------
|
---|
[2918] | 303 | if (newEpoch->corr.find(newCorr->prn) != newEpoch->corr.end()) {
|
---|
[2919] | 304 | newEpoch->corr[newCorr->prn]->readLine(line); // merge (multiple messages)
|
---|
[3298] | 305 | delete newCorr;
|
---|
[2918] | 306 | }
|
---|
[2919] | 307 | else {
|
---|
| 308 | newEpoch->corr[newCorr->prn] = newCorr;
|
---|
| 309 | }
|
---|
[2898] | 310 | }
|
---|
| 311 |
|
---|
[2986] | 312 | // Change the correction so that it refers to last received ephemeris
|
---|
| 313 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3029] | 314 | void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
|
---|
[3028] | 315 |
|
---|
[2987] | 316 | ColumnVector oldXC(4);
|
---|
| 317 | ColumnVector oldVV(3);
|
---|
[3029] | 318 | corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
| 319 | oldXC.data(), oldVV.data());
|
---|
[2988] | 320 |
|
---|
[2987] | 321 | ColumnVector newXC(4);
|
---|
| 322 | ColumnVector newVV(3);
|
---|
[3029] | 323 | lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
[2987] | 324 | newXC.data(), newVV.data());
|
---|
[2988] | 325 |
|
---|
| 326 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
---|
[2989] | 327 | ColumnVector dV = newVV - oldVV;
|
---|
| 328 | double dC = newXC(4) - oldXC(4);
|
---|
| 329 |
|
---|
[2988] | 330 | ColumnVector dRAO(3);
|
---|
| 331 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
---|
[2989] | 332 |
|
---|
| 333 | ColumnVector dDotRAO(3);
|
---|
| 334 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
---|
| 335 |
|
---|
[3029] | 336 | QString msg = "switch " + corr->prn
|
---|
| 337 | + QString(" %1 -> %2 %3").arg(corr->iod,3)
|
---|
[3013] | 338 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
| 339 |
|
---|
[3029] | 340 | emit newMessage(msg.toAscii(), false);
|
---|
[3028] | 341 |
|
---|
[3029] | 342 | corr->iod = lastEph->IOD();
|
---|
| 343 | corr->eph = lastEph;
|
---|
[3031] | 344 | corr->rao += dRAO;
|
---|
| 345 | corr->dotRao += dDotRAO;
|
---|
[3029] | 346 | corr->dClk -= dC;
|
---|
[2986] | 347 | }
|
---|
| 348 |
|
---|
[2928] | 349 | // Process Epochs
|
---|
| 350 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2927] | 351 | void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
|
---|
[2918] | 352 |
|
---|
[2990] | 353 | _log.clear();
|
---|
| 354 |
|
---|
| 355 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
| 356 |
|
---|
[2991] | 357 | out << "Combination:" << endl
|
---|
[3275] | 358 | << "------------------------------" << endl;
|
---|
[2990] | 359 |
|
---|
[3277] | 360 | // Check whether master AC present
|
---|
| 361 | // -------------------------------
|
---|
| 362 | if (epochs.first()->acName != _masterAC) {
|
---|
| 363 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 364 | while (itEpo.hasNext()) {
|
---|
| 365 | cmbEpoch* epo = itEpo.next();
|
---|
| 366 | bncTime epoTime = epo->time;
|
---|
| 367 | out << epo->acName.toAscii().data() << " "
|
---|
| 368 | << epoTime.datestr().c_str() << " "
|
---|
| 369 | << epoTime.timestr().c_str() << endl;
|
---|
| 370 | delete epo;
|
---|
| 371 | }
|
---|
| 372 | out << "Missing Master AC" << endl;
|
---|
| 373 | emit newMessage(_log, false);
|
---|
| 374 | return;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[2933] | 377 | // Predict Parameters Values, Add White Noise
|
---|
| 378 | // ------------------------------------------
|
---|
| 379 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 380 | cmbParam* pp = _params[iPar-1];
|
---|
[3032] | 381 | if (pp->sig_P != 0.0) {
|
---|
[2933] | 382 | pp->xx = 0.0;
|
---|
| 383 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 384 | _QQ(iPar, jj) = 0.0;
|
---|
| 385 | }
|
---|
[3032] | 386 | _QQ(iPar,iPar) = pp->sig_P * pp->sig_P;
|
---|
[2933] | 387 | }
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[2928] | 390 | bncTime resTime = epochs.first()->time;
|
---|
| 391 | QMap<QString, t_corr*> resCorr;
|
---|
| 392 |
|
---|
[2933] | 393 | int nPar = _params.size();
|
---|
| 394 | int nObs = 0;
|
---|
| 395 |
|
---|
| 396 | ColumnVector x0(nPar);
|
---|
| 397 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 398 | cmbParam* pp = _params[iPar-1];
|
---|
| 399 | x0(iPar) = pp->xx;
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | // Count Observations
|
---|
| 403 | // ------------------
|
---|
[2927] | 404 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 405 | while (itEpo.hasNext()) {
|
---|
[3274] | 406 | cmbEpoch* epo = itEpo.next();
|
---|
| 407 | bncTime epoTime = epo->time;
|
---|
[3275] | 408 | out << epo->acName.toAscii().data() << " "
|
---|
| 409 | << epoTime.datestr().c_str() << " "
|
---|
| 410 | << epoTime.timestr().c_str() << endl;
|
---|
[3274] | 411 |
|
---|
[3029] | 412 | QMutableMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
[2927] | 413 | while (itCorr.hasNext()) {
|
---|
| 414 | itCorr.next();
|
---|
[3029] | 415 | t_corr* corr = itCorr.value();
|
---|
| 416 |
|
---|
[3032] | 417 | // Switch to last ephemeris
|
---|
| 418 | // ------------------------
|
---|
[3029] | 419 | t_eph* lastEph = _eph[corr->prn]->last;
|
---|
| 420 | if (lastEph == corr->eph) {
|
---|
| 421 | ++nObs;
|
---|
| 422 | }
|
---|
| 423 | else {
|
---|
| 424 | if (corr->eph == _eph[corr->prn]->prev) {
|
---|
| 425 | switchToLastEph(lastEph, corr);
|
---|
| 426 | ++nObs;
|
---|
| 427 | }
|
---|
| 428 | else {
|
---|
| 429 | itCorr.remove();
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
[2933] | 432 | }
|
---|
| 433 | }
|
---|
[2928] | 434 |
|
---|
[2933] | 435 | if (nObs > 0) {
|
---|
[3135] | 436 | const double Pl = 1.0 / (0.05 * 0.05);
|
---|
| 437 |
|
---|
[3140] | 438 | const int nCon = (_firstReg == false) ? 1 + MAXPRN_GPS : 1;
|
---|
[3134] | 439 | Matrix AA(nObs+nCon, nPar); AA = 0.0;
|
---|
| 440 | ColumnVector ll(nObs+nCon); ll = 0.0;
|
---|
[3135] | 441 | DiagonalMatrix PP(nObs+nCon); PP = Pl;
|
---|
[2933] | 442 |
|
---|
| 443 | int iObs = 0;
|
---|
| 444 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 445 | while (itEpo.hasNext()) {
|
---|
| 446 | cmbEpoch* epo = itEpo.next();
|
---|
| 447 | QMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
| 448 |
|
---|
| 449 | while (itCorr.hasNext()) {
|
---|
| 450 | itCorr.next();
|
---|
| 451 | ++iObs;
|
---|
| 452 | t_corr* corr = itCorr.value();
|
---|
| 453 |
|
---|
[3032] | 454 | if (epo->acName == _masterAC) {
|
---|
[2933] | 455 | resCorr[corr->prn] = new t_corr(*corr);
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 459 | cmbParam* pp = _params[iPar-1];
|
---|
| 460 | AA(iObs, iPar) = pp->partial(epo->acName, corr);
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
|
---|
[3034] | 464 | }
|
---|
[2933] | 465 | }
|
---|
[2928] | 466 |
|
---|
[3134] | 467 | // Regularization
|
---|
| 468 | // --------------
|
---|
| 469 | const double Ph = 1.e6;
|
---|
| 470 | int iCond = 1;
|
---|
| 471 | PP(nObs+iCond) = Ph;
|
---|
| 472 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 473 | cmbParam* pp = _params[iPar-1];
|
---|
[3136] | 474 | if (pp->type == cmbParam::clk &&
|
---|
| 475 | AA.Column(iPar).maximum_absolute_value() > 0.0) {
|
---|
| 476 | AA(nObs+iCond, iPar) = 1.0;
|
---|
[3134] | 477 | }
|
---|
| 478 | }
|
---|
| 479 |
|
---|
[3138] | 480 | if (!_firstReg) {
|
---|
| 481 | _firstReg = true;
|
---|
| 482 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
| 483 | ++iCond;
|
---|
| 484 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
| 485 | PP(nObs+1+iGps) = Ph;
|
---|
| 486 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 487 | cmbParam* pp = _params[iPar-1];
|
---|
| 488 | if (pp->type == cmbParam::Sat_offset && pp->prn == prn) {
|
---|
| 489 | AA(nObs+iCond, iPar) = 1.0;
|
---|
| 490 | }
|
---|
[3134] | 491 | }
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 |
|
---|
[3081] | 495 | const double MAXRES = 999.10; // TODO: make it an option
|
---|
[3080] | 496 |
|
---|
[2933] | 497 | ColumnVector dx;
|
---|
[3080] | 498 | SymmetricMatrix QQ_sav = _QQ;
|
---|
[2933] | 499 |
|
---|
[3080] | 500 | for (int ii = 1; ii < 10; ii++) {
|
---|
| 501 | bncModel::kalman(AA, ll, PP, _QQ, dx);
|
---|
| 502 | ColumnVector vv = ll - AA * dx;
|
---|
| 503 |
|
---|
| 504 | int maxResIndex;
|
---|
| 505 | double maxRes = vv.maximum_absolute_value1(maxResIndex);
|
---|
| 506 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
| 507 | out.setRealNumberPrecision(3);
|
---|
| 508 | out << "Maximum Residuum " << maxRes << " (index " << maxResIndex << ")\n";
|
---|
| 509 |
|
---|
| 510 | if (maxRes > MAXRES) {
|
---|
| 511 | out << "Outlier Detected" << endl;
|
---|
| 512 | _QQ = QQ_sav;
|
---|
| 513 | AA.Row(maxResIndex) = 0.0;
|
---|
| 514 | ll.Row(maxResIndex) = 0.0;
|
---|
| 515 | }
|
---|
| 516 | else {
|
---|
| 517 | break;
|
---|
| 518 | }
|
---|
| 519 | }
|
---|
| 520 |
|
---|
[2933] | 521 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 522 | cmbParam* pp = _params[iPar-1];
|
---|
| 523 | pp->xx += dx(iPar);
|
---|
[2935] | 524 | if (pp->type == cmbParam::clk) {
|
---|
[2936] | 525 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
---|
| 526 | resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
|
---|
| 527 | }
|
---|
[2935] | 528 | }
|
---|
[3011] | 529 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
[2990] | 530 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
| 531 | out.setFieldWidth(8);
|
---|
| 532 | out.setRealNumberPrecision(4);
|
---|
| 533 | out << pp->toString() << " "
|
---|
[2991] | 534 | << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
|
---|
[2918] | 535 | }
|
---|
| 536 | }
|
---|
[2919] | 537 |
|
---|
[3015] | 538 | printResults(out, resTime, resCorr);
|
---|
[2928] | 539 | dumpResults(resTime, resCorr);
|
---|
| 540 |
|
---|
[2990] | 541 | emit newMessage(_log, false);
|
---|
[3296] | 542 |
|
---|
| 543 | QListIterator<cmbEpoch*> itEpo2(epochs);
|
---|
| 544 | while (itEpo2.hasNext()) {
|
---|
| 545 | cmbEpoch* epo = itEpo2.next();
|
---|
| 546 | delete epo;
|
---|
| 547 | }
|
---|
[2918] | 548 | }
|
---|
[3011] | 549 |
|
---|
[3201] | 550 | // Print results
|
---|
[3011] | 551 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3015] | 552 | void bncComb::printResults(QTextStream& out, const bncTime& resTime,
|
---|
[3011] | 553 | const QMap<QString, t_corr*>& resCorr) {
|
---|
| 554 |
|
---|
| 555 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
| 556 | while (it.hasNext()) {
|
---|
| 557 | it.next();
|
---|
| 558 | t_corr* corr = it.value();
|
---|
[3029] | 559 | const t_eph* eph = corr->eph;
|
---|
[3015] | 560 | if (eph) {
|
---|
| 561 | double xx, yy, zz, cc;
|
---|
| 562 | eph->position(resTime.gpsw(), resTime.gpssec(), xx, yy, zz, cc);
|
---|
| 563 |
|
---|
| 564 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
| 565 | out.setFieldWidth(3);
|
---|
| 566 | out << "Full Clock " << corr->prn << " " << corr->iod << " ";
|
---|
| 567 | out.setFieldWidth(14);
|
---|
| 568 | out << (cc + corr->dClk) * t_CST::c << endl;
|
---|
| 569 | }
|
---|
| 570 | else {
|
---|
| 571 | out << "bncComb::printResuls bug" << endl;
|
---|
| 572 | }
|
---|
[3011] | 573 | }
|
---|
| 574 | }
|
---|
[3202] | 575 |
|
---|
| 576 | // Send results to RTNet Decoder and directly to PPP Client
|
---|
| 577 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 578 | void bncComb::dumpResults(const bncTime& resTime,
|
---|
| 579 | const QMap<QString, t_corr*>& resCorr) {
|
---|
| 580 |
|
---|
[3214] | 581 | ostringstream out; out.setf(std::ios::fixed);
|
---|
[3216] | 582 | QStringList corrLines;
|
---|
[3214] | 583 |
|
---|
| 584 | unsigned year, month, day, hour, minute;
|
---|
| 585 | double sec;
|
---|
| 586 | resTime.civil_date(year, month, day);
|
---|
| 587 | resTime.civil_time(hour, minute, sec);
|
---|
| 588 |
|
---|
| 589 | out << "* "
|
---|
| 590 | << setw(4) << year << " "
|
---|
| 591 | << setw(2) << month << " "
|
---|
| 592 | << setw(2) << day << " "
|
---|
| 593 | << setw(2) << hour << " "
|
---|
| 594 | << setw(2) << minute << " "
|
---|
| 595 | << setw(12) << setprecision(8) << sec << " "
|
---|
| 596 | << endl;
|
---|
| 597 |
|
---|
[3202] | 598 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
| 599 | while (it.hasNext()) {
|
---|
| 600 | it.next();
|
---|
| 601 | t_corr* corr = it.value();
|
---|
| 602 |
|
---|
[3214] | 603 | double dT = 60.0;
|
---|
[3202] | 604 |
|
---|
[3214] | 605 | for (int iTime = 1; iTime <= 2; iTime++) {
|
---|
| 606 |
|
---|
| 607 | bncTime time12 = (iTime == 1) ? resTime : resTime + dT;
|
---|
| 608 |
|
---|
| 609 | ColumnVector xc(4);
|
---|
| 610 | ColumnVector vv(3);
|
---|
| 611 | corr->eph->position(time12.gpsw(), time12.gpssec(),
|
---|
| 612 | xc.data(), vv.data());
|
---|
| 613 | bncPPPclient::applyCorr(time12, corr, xc, vv);
|
---|
| 614 |
|
---|
| 615 | // Relativistic Correction
|
---|
| 616 | // -----------------------
|
---|
| 617 | double relCorr = - 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
|
---|
| 618 | xc(4) -= relCorr;
|
---|
| 619 |
|
---|
| 620 | // Code Biases
|
---|
| 621 | // -----------
|
---|
| 622 | double dcbP1C1 = 0.0;
|
---|
| 623 | double dcbP1P2 = 0.0;
|
---|
| 624 |
|
---|
| 625 | // Correction Phase Center --> CoM
|
---|
| 626 | // -------------------------------
|
---|
| 627 | ColumnVector dx(3); dx = 0.0;
|
---|
| 628 | if (_antex) {
|
---|
| 629 | double Mjd = time12.mjd() + time12.daysec()/86400.0;
|
---|
| 630 | if (_antex->satCoMcorrection(corr->prn, Mjd, xc.Rows(1,3), dx) == success) {
|
---|
| 631 | xc(1) -= dx(1);
|
---|
| 632 | xc(2) -= dx(2);
|
---|
| 633 | xc(3) -= dx(3);
|
---|
| 634 | }
|
---|
| 635 | else {
|
---|
| 636 | cout << "antenna not found" << endl;
|
---|
| 637 | }
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | if (iTime == 1) {
|
---|
| 641 | out << 'P' << corr->prn.toAscii().data()
|
---|
| 642 | << setw(14) << setprecision(6) << xc(1) / 1000.0
|
---|
| 643 | << setw(14) << setprecision(6) << xc(2) / 1000.0
|
---|
| 644 | << setw(14) << setprecision(6) << xc(3) / 1000.0
|
---|
| 645 | << setw(14) << setprecision(6) << xc(4) * 1e6
|
---|
| 646 | << setw(14) << setprecision(6) << relCorr * 1e6
|
---|
| 647 | << setw(8) << setprecision(3) << dx(1)
|
---|
| 648 | << setw(8) << setprecision(3) << dx(2)
|
---|
| 649 | << setw(8) << setprecision(3) << dx(3)
|
---|
| 650 | << setw(8) << setprecision(3) << dcbP1C1
|
---|
| 651 | << setw(8) << setprecision(3) << dcbP1P2
|
---|
| 652 | << setw(6) << setprecision(1) << dT;
|
---|
[3216] | 653 |
|
---|
[3218] | 654 | QString line;
|
---|
[3217] | 655 | int messageType = COTYPE_GPSCOMBINED;
|
---|
[3218] | 656 | int updateInt = 0;
|
---|
| 657 | line.sprintf("%d %d %d %.1f %s"
|
---|
| 658 | " %3d"
|
---|
| 659 | " %8.3f %8.3f %8.3f %8.3f"
|
---|
| 660 | " %10.5f %10.5f %10.5f %10.5f"
|
---|
[3262] | 661 | " %10.5f %10.5f %10.5f %10.5f INTERNAL",
|
---|
[3218] | 662 | messageType, updateInt, time12.gpsw(), time12.gpssec(),
|
---|
| 663 | corr->prn.toAscii().data(),
|
---|
| 664 | corr->iod,
|
---|
[3219] | 665 | corr->dClk * t_CST::c,
|
---|
[3218] | 666 | corr->rao[0],
|
---|
| 667 | corr->rao[1],
|
---|
| 668 | corr->rao[2],
|
---|
[3219] | 669 | corr->dotDClk * t_CST::c,
|
---|
[3218] | 670 | corr->dotRao[0],
|
---|
| 671 | corr->dotRao[1],
|
---|
| 672 | corr->dotRao[2],
|
---|
[3262] | 673 | corr->dotDotDClk * t_CST::c,
|
---|
| 674 | corr->dotDotRao[0],
|
---|
| 675 | corr->dotDotRao[1],
|
---|
| 676 | corr->dotDotRao[2]);
|
---|
[3220] | 677 | corrLines << line;
|
---|
[3214] | 678 | }
|
---|
| 679 | else {
|
---|
| 680 | out << setw(14) << setprecision(6) << xc(1) / 1000.0
|
---|
| 681 | << setw(14) << setprecision(6) << xc(2) / 1000.0
|
---|
| 682 | << setw(14) << setprecision(6) << xc(3) / 1000.0 << endl;
|
---|
| 683 | }
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | delete corr;
|
---|
| 687 | }
|
---|
[3228] | 688 | out << "EOE" << endl; // End Of Epoch flag
|
---|
[3214] | 689 |
|
---|
[3215] | 690 | if (!_rtnetDecoder) {
|
---|
| 691 | _rtnetDecoder = new bncRtnetDecoder();
|
---|
| 692 | }
|
---|
[3221] | 693 |
|
---|
[3215] | 694 | vector<string> errmsg;
|
---|
[3221] | 695 | _rtnetDecoder->Decode((char*) out.str().data(), out.str().size(), errmsg);
|
---|
[3215] | 696 |
|
---|
[3216] | 697 | // Optionally send new Corrections to PPP
|
---|
| 698 | // --------------------------------------
|
---|
| 699 | bncApp* app = (bncApp*) qApp;
|
---|
| 700 | if (app->_bncPPPclient) {
|
---|
| 701 | app->_bncPPPclient->slotNewCorrections(corrLines);
|
---|
| 702 | }
|
---|
[3202] | 703 | }
|
---|