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