[2057] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncParam, bncModel
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Model for PPP
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 01-Dec-2009
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iomanip>
|
---|
[2063] | 42 | #include <cmath>
|
---|
[2060] | 43 | #include <newmatio.h>
|
---|
[2113] | 44 | #include <sstream>
|
---|
[2057] | 45 |
|
---|
| 46 | #include "bncmodel.h"
|
---|
[2113] | 47 | #include "bncapp.h"
|
---|
[2058] | 48 | #include "bncpppclient.h"
|
---|
| 49 | #include "bancroft.h"
|
---|
[2063] | 50 | #include "bncutils.h"
|
---|
[2077] | 51 | #include "bncsettings.h"
|
---|
[2580] | 52 | #include "bnctides.h"
|
---|
[2881] | 53 | #include "bncantex.h"
|
---|
[3375] | 54 | #include "bnccomb.h"
|
---|
[2057] | 55 |
|
---|
| 56 | using namespace std;
|
---|
| 57 |
|
---|
[3383] | 58 | const unsigned MINOBS = 5;
|
---|
| 59 | const double MINELE = 10.0 * M_PI / 180.0;
|
---|
| 60 | const double MAXRES_CODE = 10.0;
|
---|
| 61 | const double MAXRES_PHASE = 0.04;
|
---|
[2070] | 62 |
|
---|
[2057] | 63 | // Constructor
|
---|
| 64 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 65 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
| 66 | const QString& prnIn) {
|
---|
| 67 | type = typeIn;
|
---|
| 68 | index = indexIn;
|
---|
| 69 | prn = prnIn;
|
---|
| 70 | index_old = 0;
|
---|
| 71 | xx = 0.0;
|
---|
[3330] | 72 | numEpo = 0;
|
---|
[2057] | 73 | }
|
---|
| 74 |
|
---|
| 75 | // Destructor
|
---|
| 76 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 77 | bncParam::~bncParam() {
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[2060] | 80 | // Partial
|
---|
| 81 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2239] | 82 | double bncParam::partial(t_satData* satData, bool phase) {
|
---|
| 83 |
|
---|
[3312] | 84 | Tracer tracer("bncParam::partial");
|
---|
| 85 |
|
---|
[2239] | 86 | // Coordinates
|
---|
| 87 | // -----------
|
---|
[2060] | 88 | if (type == CRD_X) {
|
---|
[2109] | 89 | return (xx - satData->xx(1)) / satData->rho;
|
---|
[2060] | 90 | }
|
---|
| 91 | else if (type == CRD_Y) {
|
---|
[2109] | 92 | return (xx - satData->xx(2)) / satData->rho;
|
---|
[2060] | 93 | }
|
---|
| 94 | else if (type == CRD_Z) {
|
---|
[2109] | 95 | return (xx - satData->xx(3)) / satData->rho;
|
---|
[2060] | 96 | }
|
---|
[2239] | 97 |
|
---|
| 98 | // Receiver Clocks
|
---|
| 99 | // ---------------
|
---|
[2265] | 100 | else if (type == RECCLK) {
|
---|
| 101 | return 1.0;
|
---|
[2060] | 102 | }
|
---|
[2239] | 103 |
|
---|
| 104 | // Troposphere
|
---|
| 105 | // -----------
|
---|
[2084] | 106 | else if (type == TROPO) {
|
---|
| 107 | return 1.0 / sin(satData->eleSat);
|
---|
| 108 | }
|
---|
[2239] | 109 |
|
---|
[2782] | 110 | // Galileo Offset
|
---|
| 111 | // --------------
|
---|
| 112 | else if (type == GALILEO_OFFSET) {
|
---|
| 113 | if (satData->prn[0] == 'E') {
|
---|
| 114 | return 1.0;
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | return 0.0;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[2239] | 121 | // Ambiguities
|
---|
| 122 | // -----------
|
---|
[2080] | 123 | else if (type == AMB_L3) {
|
---|
[2239] | 124 | if (phase && satData->prn == prn) {
|
---|
[2080] | 125 | return 1.0;
|
---|
| 126 | }
|
---|
| 127 | else {
|
---|
| 128 | return 0.0;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
[2239] | 131 |
|
---|
| 132 | // Default return
|
---|
| 133 | // --------------
|
---|
[2060] | 134 | return 0.0;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[2058] | 137 | // Constructor
|
---|
| 138 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2113] | 139 | bncModel::bncModel(QByteArray staID) {
|
---|
[2084] | 140 |
|
---|
[2113] | 141 | _staID = staID;
|
---|
| 142 |
|
---|
[3107] | 143 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 144 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 145 |
|
---|
[2648] | 146 | bncSettings settings;
|
---|
| 147 |
|
---|
[2720] | 148 | // Observation Sigmas
|
---|
| 149 | // ------------------
|
---|
| 150 | _sigP3 = 5.0;
|
---|
| 151 | if (!settings.value("pppSigmaCode").toString().isEmpty()) {
|
---|
| 152 | _sigP3 = settings.value("pppSigmaCode").toDouble();
|
---|
| 153 | }
|
---|
| 154 | _sigL3 = 0.02;
|
---|
| 155 | if (!settings.value("pppSigmaPhase").toString().isEmpty()) {
|
---|
[2741] | 156 | _sigL3 = settings.value("pppSigmaPhase").toDouble();
|
---|
[2720] | 157 | }
|
---|
[2648] | 158 |
|
---|
[2720] | 159 | // Parameter Sigmas
|
---|
| 160 | // ----------------
|
---|
| 161 | _sigCrd0 = 100.0;
|
---|
| 162 | if (!settings.value("pppSigCrd0").toString().isEmpty()) {
|
---|
| 163 | _sigCrd0 = settings.value("pppSigCrd0").toDouble();
|
---|
| 164 | }
|
---|
| 165 | _sigCrdP = 100.0;
|
---|
| 166 | if (!settings.value("pppSigCrdP").toString().isEmpty()) {
|
---|
| 167 | _sigCrdP = settings.value("pppSigCrdP").toDouble();
|
---|
| 168 | }
|
---|
| 169 | _sigTrp0 = 0.1;
|
---|
| 170 | if (!settings.value("pppSigTrp0").toString().isEmpty()) {
|
---|
| 171 | _sigTrp0 = settings.value("pppSigTrp0").toDouble();
|
---|
| 172 | }
|
---|
| 173 | _sigTrpP = 1e-6;
|
---|
| 174 | if (!settings.value("pppSigTrpP").toString().isEmpty()) {
|
---|
| 175 | _sigTrpP = settings.value("pppSigTrpP").toDouble();
|
---|
| 176 | }
|
---|
[2782] | 177 | _sigClk0 = 1000.0;
|
---|
| 178 | _sigAmb0 = 1000.0;
|
---|
| 179 | _sigGalileoOffset0 = 1000.0;
|
---|
[2784] | 180 | _sigGalileoOffsetP = 0.0;
|
---|
[2648] | 181 |
|
---|
[2720] | 182 | // Quick-Start Mode
|
---|
| 183 | // ----------------
|
---|
| 184 | _quickStart = 0;
|
---|
[2726] | 185 | if (settings.value("pppRefCrdX").toString() != "" &&
|
---|
| 186 | settings.value("pppRefCrdY").toString() != "" &&
|
---|
| 187 | settings.value("pppRefCrdZ").toString() != "" &&
|
---|
[2720] | 188 | !settings.value("pppQuickStart").toString().isEmpty()) {
|
---|
[2745] | 189 | _quickStart = settings.value("pppQuickStart").toDouble();
|
---|
[2720] | 190 | }
|
---|
| 191 |
|
---|
[3107] | 192 | // Several options
|
---|
| 193 | // ---------------
|
---|
[2084] | 194 | _usePhase = false;
|
---|
| 195 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
|
---|
| 196 | _usePhase = true;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | _estTropo = false;
|
---|
| 200 | if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
|
---|
| 201 | _estTropo = true;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[3107] | 204 | _useGalileo = false;
|
---|
[2799] | 205 | if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
|
---|
[3107] | 206 | _useGalileo = true;
|
---|
[2782] | 207 | }
|
---|
[2073] | 208 |
|
---|
[2125] | 209 | // NMEA Output
|
---|
| 210 | // -----------
|
---|
| 211 | QString nmeaFileName = settings.value("nmeaFile").toString();
|
---|
| 212 | if (nmeaFileName.isEmpty()) {
|
---|
| 213 | _nmeaFile = 0;
|
---|
| 214 | _nmeaStream = 0;
|
---|
| 215 | }
|
---|
| 216 | else {
|
---|
| 217 | expandEnvVar(nmeaFileName);
|
---|
| 218 | _nmeaFile = new QFile(nmeaFileName);
|
---|
| 219 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 220 | _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 221 | }
|
---|
| 222 | else {
|
---|
| 223 | _nmeaFile->open(QIODevice::WriteOnly);
|
---|
| 224 | }
|
---|
| 225 | _nmeaStream = new QTextStream();
|
---|
| 226 | _nmeaStream->setDevice(_nmeaFile);
|
---|
| 227 | }
|
---|
[2881] | 228 |
|
---|
[3107] | 229 | // Antenna Name, ANTEX File
|
---|
| 230 | // ------------------------
|
---|
[2896] | 231 | _antex = 0;
|
---|
[2881] | 232 | QString antexFileName = settings.value("pppAntex").toString();
|
---|
| 233 | if (!antexFileName.isEmpty()) {
|
---|
| 234 | _antex = new bncAntex();
|
---|
[2883] | 235 | if (_antex->readFile(antexFileName) != success) {
|
---|
[2938] | 236 | emit newMessage("wrong ANTEX file", true);
|
---|
[2887] | 237 | delete _antex;
|
---|
| 238 | _antex = 0;
|
---|
[2883] | 239 | }
|
---|
[2938] | 240 | else {
|
---|
| 241 | _antennaName = settings.value("pppAntenna").toString();
|
---|
| 242 | }
|
---|
[2881] | 243 | }
|
---|
[3107] | 244 |
|
---|
[3286] | 245 | // Antenna Eccentricities
|
---|
| 246 | // ----------------------
|
---|
| 247 | _dN = settings.value("pppRefdN").toDouble();
|
---|
| 248 | _dE = settings.value("pppRefdE").toDouble();
|
---|
| 249 | _dU = settings.value("pppRefdU").toDouble();
|
---|
| 250 |
|
---|
[3107] | 251 | // Bancroft Coordinates
|
---|
| 252 | // --------------------
|
---|
| 253 | _xcBanc.ReSize(4); _xcBanc = 0.0;
|
---|
| 254 | _ellBanc.ReSize(3); _ellBanc = 0.0;
|
---|
[3375] | 255 |
|
---|
[3382] | 256 | // Save copy of data (used in outlier detection)
|
---|
| 257 | // ---------------------------------------------
|
---|
| 258 | _epoData_sav = new t_epoData();
|
---|
[2058] | 259 | }
|
---|
| 260 |
|
---|
[3108] | 261 | // Destructor
|
---|
[3107] | 262 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3108] | 263 | bncModel::~bncModel() {
|
---|
| 264 | delete _nmeaStream;
|
---|
| 265 | delete _nmeaFile;
|
---|
| 266 | for (int ii = 0; ii < _posAverage.size(); ++ii) {
|
---|
| 267 | delete _posAverage[ii];
|
---|
| 268 | }
|
---|
| 269 | delete _antex;
|
---|
| 270 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 271 | delete _params[iPar-1];
|
---|
| 272 | }
|
---|
[3386] | 273 | delete _epoData_sav;
|
---|
[3108] | 274 | }
|
---|
| 275 |
|
---|
| 276 | // Reset Parameters and Variance-Covariance Matrix
|
---|
| 277 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3107] | 278 | void bncModel::reset() {
|
---|
| 279 |
|
---|
[3312] | 280 | Tracer tracer("bncModel::reset");
|
---|
| 281 |
|
---|
[3107] | 282 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 283 | delete _params[iPar-1];
|
---|
| 284 | }
|
---|
| 285 | _params.clear();
|
---|
| 286 |
|
---|
| 287 | int nextPar = 0;
|
---|
| 288 | _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
|
---|
| 289 | _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
|
---|
| 290 | _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
|
---|
| 291 | _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
|
---|
| 292 | if (_estTropo) {
|
---|
| 293 | _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
|
---|
| 294 | }
|
---|
| 295 | if (_useGalileo) {
|
---|
| 296 | _params.push_back(new bncParam(bncParam::GALILEO_OFFSET, ++nextPar, ""));
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | _QQ.ReSize(_params.size());
|
---|
| 300 | _QQ = 0.0;
|
---|
| 301 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 302 | bncParam* pp = _params[iPar-1];
|
---|
| 303 | pp->xx = 0.0;
|
---|
| 304 | if (pp->isCrd()) {
|
---|
| 305 | _QQ(iPar,iPar) = _sigCrd0 * _sigCrd0;
|
---|
| 306 | }
|
---|
| 307 | else if (pp->type == bncParam::RECCLK) {
|
---|
| 308 | _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
|
---|
| 309 | }
|
---|
| 310 | else if (pp->type == bncParam::TROPO) {
|
---|
| 311 | _QQ(iPar,iPar) = _sigTrp0 * _sigTrp0;
|
---|
| 312 | }
|
---|
| 313 | else if (pp->type == bncParam::GALILEO_OFFSET) {
|
---|
| 314 | _QQ(iPar,iPar) = _sigGalileoOffset0 * _sigGalileoOffset0;
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[2058] | 319 | // Bancroft Solution
|
---|
| 320 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 321 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
---|
| 322 |
|
---|
[3312] | 323 | Tracer tracer("bncModel::cmpBancroft");
|
---|
| 324 |
|
---|
[3383] | 325 | if (epoData->sizeSys('G') < MINOBS) {
|
---|
[2547] | 326 | _log += "bncModel::cmpBancroft: not enough data\n";
|
---|
[2058] | 327 | return failure;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[3383] | 330 | Matrix BB(epoData->sizeSys('G'), 4);
|
---|
[2058] | 331 |
|
---|
[3383] | 332 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
[2791] | 333 | int iObsBanc = 0;
|
---|
[2058] | 334 | while (it.hasNext()) {
|
---|
| 335 | it.next();
|
---|
| 336 | t_satData* satData = it.value();
|
---|
[3383] | 337 | if (satData->system() == 'G') {
|
---|
| 338 | ++iObsBanc;
|
---|
| 339 | QString prn = it.key();
|
---|
| 340 | BB(iObsBanc, 1) = satData->xx(1);
|
---|
| 341 | BB(iObsBanc, 2) = satData->xx(2);
|
---|
| 342 | BB(iObsBanc, 3) = satData->xx(3);
|
---|
| 343 | BB(iObsBanc, 4) = satData->P3 + satData->clk;
|
---|
| 344 | }
|
---|
[2058] | 345 | }
|
---|
| 346 |
|
---|
| 347 | bancroft(BB, _xcBanc);
|
---|
| 348 |
|
---|
[2064] | 349 | // Ellipsoidal Coordinates
|
---|
| 350 | // ------------------------
|
---|
| 351 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
---|
[2063] | 352 |
|
---|
[2064] | 353 | // Compute Satellite Elevations
|
---|
| 354 | // ----------------------------
|
---|
[3383] | 355 | QMutableMapIterator<QString, t_satData*> im(epoData->satData);
|
---|
| 356 | while (im.hasNext()) {
|
---|
| 357 | im.next();
|
---|
| 358 | t_satData* satData = im.value();
|
---|
[2789] | 359 | cmpEle(satData);
|
---|
[3383] | 360 | if (satData->eleSat < MINELE) {
|
---|
[2070] | 361 | delete satData;
|
---|
[3383] | 362 | im.remove();
|
---|
[2070] | 363 | }
|
---|
[2064] | 364 | }
|
---|
| 365 |
|
---|
[2058] | 366 | return success;
|
---|
| 367 | }
|
---|
[2060] | 368 |
|
---|
| 369 | // Computed Value
|
---|
| 370 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2583] | 371 | double bncModel::cmpValue(t_satData* satData, bool phase) {
|
---|
[2060] | 372 |
|
---|
[3312] | 373 | Tracer tracer("bncModel::cmpValue");
|
---|
| 374 |
|
---|
[2073] | 375 | ColumnVector xRec(3);
|
---|
| 376 | xRec(1) = x();
|
---|
| 377 | xRec(2) = y();
|
---|
| 378 | xRec(3) = z();
|
---|
[2060] | 379 |
|
---|
[2073] | 380 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
---|
[2060] | 381 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
---|
| 382 |
|
---|
[2073] | 383 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
---|
| 384 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
---|
| 385 | xRec(3) = z();
|
---|
| 386 |
|
---|
[2580] | 387 | tides(_time, xRec);
|
---|
| 388 |
|
---|
[2060] | 389 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
---|
| 390 |
|
---|
[2084] | 391 | double tropDelay = delay_saast(satData->eleSat) +
|
---|
| 392 | trp() / sin(satData->eleSat);
|
---|
[2060] | 393 |
|
---|
[2583] | 394 | double wind = 0.0;
|
---|
| 395 | if (phase) {
|
---|
| 396 | wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
[2783] | 399 | double offset = 0.0;
|
---|
| 400 | if (satData->prn[0] == 'E') {
|
---|
| 401 | offset = Galileo_offset();
|
---|
| 402 | }
|
---|
| 403 |
|
---|
[2894] | 404 | double phaseCenter = 0.0;
|
---|
[2938] | 405 | if (_antex) {
|
---|
| 406 | bool found;
|
---|
| 407 | phaseCenter = _antex->pco(_antennaName, satData->eleSat, found);
|
---|
| 408 | if (!found) {
|
---|
| 409 | emit newMessage("ANTEX: antenna >"
|
---|
| 410 | + _antennaName.toAscii() + "< not found", true);
|
---|
| 411 | }
|
---|
[2894] | 412 | }
|
---|
| 413 |
|
---|
[3286] | 414 | double antennaOffset = 0.0;
|
---|
| 415 | if (_dN != 0.0 || _dE != 0.0 || _dU != 0.0) {
|
---|
[3287] | 416 | double cosa = cos(satData->azSat);
|
---|
| 417 | double sina = sin(satData->azSat);
|
---|
| 418 | double cose = cos(satData->eleSat);
|
---|
| 419 | double sine = sin(satData->eleSat);
|
---|
| 420 | antennaOffset = -_dN * cosa*cose - _dE * sina*cose - _dU * sine;
|
---|
[3286] | 421 | }
|
---|
| 422 |
|
---|
| 423 | return satData->rho + phaseCenter + antennaOffset + clk()
|
---|
[2894] | 424 | + offset - satData->clk + tropDelay + wind;
|
---|
[2060] | 425 | }
|
---|
| 426 |
|
---|
[2063] | 427 | // Tropospheric Model (Saastamoinen)
|
---|
| 428 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2065] | 429 | double bncModel::delay_saast(double Ele) {
|
---|
[2063] | 430 |
|
---|
[3312] | 431 | Tracer tracer("bncModel::delay_saast");
|
---|
| 432 |
|
---|
[2769] | 433 | double xyz[3];
|
---|
| 434 | xyz[0] = x();
|
---|
| 435 | xyz[1] = y();
|
---|
| 436 | xyz[2] = z();
|
---|
| 437 | double ell[3];
|
---|
| 438 | xyz2ell(xyz, ell);
|
---|
| 439 | double height = ell[2];
|
---|
[2063] | 440 |
|
---|
[2064] | 441 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
---|
| 442 | double TT = 18.0 - height * 0.0065 + 273.15;
|
---|
| 443 | double hh = 50.0 * exp(-6.396e-4 * height);
|
---|
[2063] | 444 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
---|
| 445 |
|
---|
[2064] | 446 | double h_km = height / 1000.0;
|
---|
[2063] | 447 |
|
---|
| 448 | if (h_km < 0.0) h_km = 0.0;
|
---|
| 449 | if (h_km > 5.0) h_km = 5.0;
|
---|
| 450 | int ii = int(h_km + 1);
|
---|
| 451 | double href = ii - 1;
|
---|
| 452 |
|
---|
| 453 | double bCor[6];
|
---|
| 454 | bCor[0] = 1.156;
|
---|
| 455 | bCor[1] = 1.006;
|
---|
| 456 | bCor[2] = 0.874;
|
---|
| 457 | bCor[3] = 0.757;
|
---|
| 458 | bCor[4] = 0.654;
|
---|
| 459 | bCor[5] = 0.563;
|
---|
| 460 |
|
---|
| 461 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
---|
| 462 |
|
---|
| 463 | double zen = M_PI/2.0 - Ele;
|
---|
| 464 |
|
---|
| 465 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
---|
| 466 | }
|
---|
| 467 |
|
---|
[2073] | 468 | // Prediction Step of the Filter
|
---|
| 469 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3309] | 470 | void bncModel::predict(int iPhase, t_epoData* epoData) {
|
---|
[2073] | 471 |
|
---|
[3312] | 472 | Tracer tracer("bncModel::predict");
|
---|
| 473 |
|
---|
[3310] | 474 | if (iPhase == 0) {
|
---|
[2244] | 475 |
|
---|
[3310] | 476 | bncSettings settings;
|
---|
| 477 |
|
---|
| 478 | _time = epoData->tt; // current epoch time
|
---|
| 479 |
|
---|
| 480 | _maxSolGap = settings.value("pppMaxSolGap").toDouble();
|
---|
| 481 |
|
---|
| 482 | bool firstCrd = false;
|
---|
| 483 | if (!_lastTimeOK.valid() || (_maxSolGap > 0 && _time - _lastTimeOK > _maxSolGap)) {
|
---|
| 484 | firstCrd = true;
|
---|
| 485 | _startTime = epoData->tt;
|
---|
| 486 | reset();
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | // Use different white noise for Quick-Start mode
|
---|
| 490 | // ----------------------------------------------
|
---|
| 491 | double sigCrdP_used = _sigCrdP;
|
---|
| 492 | if ( _quickStart > 0.0 && _quickStart > (epoData->tt - _startTime) ) {
|
---|
| 493 | sigCrdP_used = 0.0;
|
---|
| 494 | }
|
---|
[3106] | 495 |
|
---|
[3310] | 496 | // Predict Parameter values, add white noise
|
---|
| 497 | // -----------------------------------------
|
---|
| 498 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 499 | bncParam* pp = _params[iPar-1];
|
---|
| 500 |
|
---|
| 501 | // Coordinates
|
---|
| 502 | // -----------
|
---|
| 503 | if (pp->type == bncParam::CRD_X) {
|
---|
| 504 | if (firstCrd) {
|
---|
| 505 | if (settings.value("pppRefCrdX").toString() != "" &&
|
---|
| 506 | settings.value("pppRefCrdY").toString() != "" &&
|
---|
| 507 | settings.value("pppRefCrdZ").toString() != "") {
|
---|
| 508 | pp->xx = settings.value("pppRefCrdX").toDouble();
|
---|
| 509 | }
|
---|
| 510 | else {
|
---|
| 511 | pp->xx = _xcBanc(1);
|
---|
| 512 | }
|
---|
[2648] | 513 | }
|
---|
[3310] | 514 | _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
|
---|
[2244] | 515 | }
|
---|
[3310] | 516 | else if (pp->type == bncParam::CRD_Y) {
|
---|
| 517 | if (firstCrd) {
|
---|
| 518 | if (settings.value("pppRefCrdX").toString() != "" &&
|
---|
| 519 | settings.value("pppRefCrdY").toString() != "" &&
|
---|
| 520 | settings.value("pppRefCrdZ").toString() != "") {
|
---|
| 521 | pp->xx = settings.value("pppRefCrdY").toDouble();
|
---|
| 522 | }
|
---|
| 523 | else {
|
---|
| 524 | pp->xx = _xcBanc(2);
|
---|
| 525 | }
|
---|
[2648] | 526 | }
|
---|
[3310] | 527 | _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
|
---|
[2244] | 528 | }
|
---|
[3310] | 529 | else if (pp->type == bncParam::CRD_Z) {
|
---|
| 530 | if (firstCrd) {
|
---|
| 531 | if (settings.value("pppRefCrdX").toString() != "" &&
|
---|
| 532 | settings.value("pppRefCrdY").toString() != "" &&
|
---|
| 533 | settings.value("pppRefCrdZ").toString() != "") {
|
---|
| 534 | pp->xx = settings.value("pppRefCrdZ").toDouble();
|
---|
| 535 | }
|
---|
| 536 | else {
|
---|
| 537 | pp->xx = _xcBanc(3);
|
---|
| 538 | }
|
---|
[2648] | 539 | }
|
---|
[3310] | 540 | _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
|
---|
| 541 | }
|
---|
| 542 |
|
---|
| 543 | // Receiver Clocks
|
---|
| 544 | // ---------------
|
---|
| 545 | else if (pp->type == bncParam::RECCLK) {
|
---|
| 546 | pp->xx = _xcBanc(4);
|
---|
| 547 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 548 | _QQ(iPar, jj) = 0.0;
|
---|
[2648] | 549 | }
|
---|
[3310] | 550 | _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
|
---|
[2244] | 551 | }
|
---|
[3310] | 552 |
|
---|
| 553 | // Tropospheric Delay
|
---|
| 554 | // ------------------
|
---|
| 555 | else if (pp->type == bncParam::TROPO) {
|
---|
| 556 | _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
|
---|
[2244] | 557 | }
|
---|
[3310] | 558 |
|
---|
| 559 | // Galileo Offset
|
---|
| 560 | // --------------
|
---|
| 561 | else if (pp->type == bncParam::GALILEO_OFFSET) {
|
---|
| 562 | _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
|
---|
| 563 | }
|
---|
[2244] | 564 | }
|
---|
| 565 | }
|
---|
| 566 |
|
---|
| 567 | // Add New Ambiguities if necessary
|
---|
| 568 | // --------------------------------
|
---|
[2083] | 569 | if (_usePhase) {
|
---|
[2080] | 570 |
|
---|
[2083] | 571 | // Make a copy of QQ and xx, set parameter indices
|
---|
| 572 | // -----------------------------------------------
|
---|
| 573 | SymmetricMatrix QQ_old = _QQ;
|
---|
| 574 |
|
---|
| 575 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 576 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
---|
| 577 | _params[iPar-1]->index = 0;
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | // Remove Ambiguity Parameters without observations
|
---|
| 581 | // ------------------------------------------------
|
---|
| 582 | int iPar = 0;
|
---|
[3383] | 583 | QMutableVectorIterator<bncParam*> im(_params);
|
---|
| 584 | while (im.hasNext()) {
|
---|
| 585 | bncParam* par = im.next();
|
---|
[2083] | 586 | bool removed = false;
|
---|
| 587 | if (par->type == bncParam::AMB_L3) {
|
---|
[3383] | 588 | if (epoData->satData.find(par->prn) == epoData->satData.end()) {
|
---|
[2083] | 589 | removed = true;
|
---|
| 590 | delete par;
|
---|
[3383] | 591 | im.remove();
|
---|
[2083] | 592 | }
|
---|
[2080] | 593 | }
|
---|
[2083] | 594 | if (! removed) {
|
---|
| 595 | ++iPar;
|
---|
| 596 | par->index = iPar;
|
---|
| 597 | }
|
---|
[2080] | 598 | }
|
---|
[2083] | 599 |
|
---|
| 600 | // Add new ambiguity parameters
|
---|
| 601 | // ----------------------------
|
---|
[3383] | 602 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 603 | while (it.hasNext()) {
|
---|
| 604 | it.next();
|
---|
| 605 | t_satData* satData = it.value();
|
---|
[2789] | 606 | addAmb(satData);
|
---|
[2080] | 607 | }
|
---|
[2083] | 608 |
|
---|
| 609 | int nPar = _params.size();
|
---|
| 610 | _QQ.ReSize(nPar); _QQ = 0.0;
|
---|
| 611 | for (int i1 = 1; i1 <= nPar; i1++) {
|
---|
| 612 | bncParam* p1 = _params[i1-1];
|
---|
| 613 | if (p1->index_old != 0) {
|
---|
| 614 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
---|
| 615 | for (int i2 = 1; i2 <= nPar; i2++) {
|
---|
| 616 | bncParam* p2 = _params[i2-1];
|
---|
| 617 | if (p2->index_old != 0) {
|
---|
| 618 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
---|
| 619 | }
|
---|
[2080] | 620 | }
|
---|
| 621 | }
|
---|
| 622 | }
|
---|
[2083] | 623 |
|
---|
| 624 | for (int ii = 1; ii <= nPar; ii++) {
|
---|
| 625 | bncParam* par = _params[ii-1];
|
---|
| 626 | if (par->index_old == 0) {
|
---|
[2720] | 627 | _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
|
---|
[2083] | 628 | }
|
---|
| 629 | par->index_old = par->index;
|
---|
[2080] | 630 | }
|
---|
| 631 | }
|
---|
[2073] | 632 | }
|
---|
| 633 |
|
---|
[2060] | 634 | // Update Step of the Filter (currently just a single-epoch solution)
|
---|
| 635 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 636 | t_irc bncModel::update(t_epoData* epoData) {
|
---|
| 637 |
|
---|
[3312] | 638 | Tracer tracer("bncModel::update");
|
---|
| 639 |
|
---|
[2473] | 640 | bncSettings settings;
|
---|
| 641 |
|
---|
[2248] | 642 | _log.clear();
|
---|
[2124] | 643 |
|
---|
[2827] | 644 | if (settings.value("pppSPP").toString() == "PPP") {
|
---|
| 645 | _log += "Precise Point Positioning of Epoch "
|
---|
| 646 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
| 647 | "\n---------------------------------------------------------------\n";
|
---|
| 648 | }
|
---|
| 649 | else {
|
---|
| 650 | _log += "Single Point Positioning of Epoch "
|
---|
| 651 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
[2547] | 652 | "\n--------------------------------------------------------------\n";
|
---|
[2827] | 653 | }
|
---|
[2547] | 654 |
|
---|
[3307] | 655 | // Outlier Detection Loop
|
---|
[2113] | 656 | // ----------------------
|
---|
[3321] | 657 | if (update_p(epoData) != success) {
|
---|
[3375] | 658 | emit newMessage(_log, false);
|
---|
[3307] | 659 | return failure;
|
---|
| 660 | }
|
---|
[2080] | 661 |
|
---|
[2670] | 662 | // Remember the Epoch-specific Results for the computation of means
|
---|
| 663 | // ----------------------------------------------------------------
|
---|
| 664 | pppPos* newPos = new pppPos;
|
---|
| 665 | newPos->time = epoData->tt;
|
---|
| 666 |
|
---|
[2109] | 667 | // Set Solution Vector
|
---|
| 668 | // -------------------
|
---|
[2265] | 669 | ostringstream strB;
|
---|
| 670 | strB.setf(ios::fixed);
|
---|
[2073] | 671 | QVectorIterator<bncParam*> itPar(_params);
|
---|
[2060] | 672 | while (itPar.hasNext()) {
|
---|
| 673 | bncParam* par = itPar.next();
|
---|
[2265] | 674 |
|
---|
| 675 | if (par->type == bncParam::RECCLK) {
|
---|
[2798] | 676 | strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
|
---|
[2124] | 677 | << " +- " << setw(6) << setprecision(3)
|
---|
| 678 | << sqrt(_QQ(par->index,par->index));
|
---|
| 679 | }
|
---|
| 680 | else if (par->type == bncParam::AMB_L3) {
|
---|
[3330] | 681 | ++par->numEpo;
|
---|
[2265] | 682 | strB << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
[2798] | 683 | << setw(10) << setprecision(3) << par->xx
|
---|
[2124] | 684 | << " +- " << setw(6) << setprecision(3)
|
---|
[3330] | 685 | << sqrt(_QQ(par->index,par->index))
|
---|
| 686 | << " nEpo = " << par->numEpo;
|
---|
[2124] | 687 | }
|
---|
[2212] | 688 | else if (par->type == bncParam::TROPO) {
|
---|
[2670] | 689 | double aprTrp = delay_saast(M_PI/2.0);
|
---|
[2547] | 690 | strB << "\n trp = " << par->prn.toAscii().data()
|
---|
[2670] | 691 | << setw(7) << setprecision(3) << aprTrp << " "
|
---|
[2213] | 692 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
---|
[2212] | 693 | << " +- " << setw(6) << setprecision(3)
|
---|
| 694 | << sqrt(_QQ(par->index,par->index));
|
---|
[2670] | 695 | newPos->xnt[6] = aprTrp + par->xx;
|
---|
[2212] | 696 | }
|
---|
[2782] | 697 | else if (par->type == bncParam::GALILEO_OFFSET) {
|
---|
[2798] | 698 | strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
|
---|
[2782] | 699 | << " +- " << setw(6) << setprecision(3)
|
---|
| 700 | << sqrt(_QQ(par->index,par->index));
|
---|
| 701 | }
|
---|
[2060] | 702 | }
|
---|
[2265] | 703 | strB << '\n';
|
---|
[2547] | 704 | _log += strB.str().c_str();
|
---|
| 705 | emit newMessage(_log, false);
|
---|
[2060] | 706 |
|
---|
[2547] | 707 | // Final Message (both log file and screen)
|
---|
| 708 | // ----------------------------------------
|
---|
| 709 | ostringstream strC;
|
---|
| 710 | strC.setf(ios::fixed);
|
---|
| 711 | strC << _staID.data() << " PPP "
|
---|
[2599] | 712 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
[2231] | 713 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
| 714 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
| 715 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
| 716 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
| 717 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
[2124] | 718 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
[2113] | 719 |
|
---|
[2370] | 720 | // NEU Output
|
---|
| 721 | // ----------
|
---|
[2862] | 722 | double xyzRef[3];
|
---|
| 723 |
|
---|
[2726] | 724 | if (settings.value("pppRefCrdX").toString() != "" &&
|
---|
| 725 | settings.value("pppRefCrdY").toString() != "" &&
|
---|
| 726 | settings.value("pppRefCrdZ").toString() != "") {
|
---|
[2649] | 727 |
|
---|
[2370] | 728 | xyzRef[0] = settings.value("pppRefCrdX").toDouble();
|
---|
| 729 | xyzRef[1] = settings.value("pppRefCrdY").toDouble();
|
---|
| 730 | xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
|
---|
[2649] | 731 |
|
---|
[2670] | 732 | newPos->xnt[0] = x() - xyzRef[0];
|
---|
| 733 | newPos->xnt[1] = y() - xyzRef[1];
|
---|
| 734 | newPos->xnt[2] = z() - xyzRef[2];
|
---|
[2649] | 735 |
|
---|
| 736 | double ellRef[3];
|
---|
[2370] | 737 | xyz2ell(xyzRef, ellRef);
|
---|
[2670] | 738 | xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
|
---|
[2649] | 739 |
|
---|
[2547] | 740 | strC << " NEU "
|
---|
[2670] | 741 | << setw(8) << setprecision(3) << newPos->xnt[3] << " "
|
---|
| 742 | << setw(8) << setprecision(3) << newPos->xnt[4] << " "
|
---|
[2797] | 743 | << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
|
---|
[2649] | 744 |
|
---|
[2370] | 745 | }
|
---|
| 746 |
|
---|
[2547] | 747 | emit newMessage(QByteArray(strC.str().c_str()), true);
|
---|
| 748 |
|
---|
[2671] | 749 | if (settings.value("pppAverage").toString() == "") {
|
---|
| 750 | delete newPos;
|
---|
| 751 | }
|
---|
| 752 | else {
|
---|
| 753 |
|
---|
| 754 | _posAverage.push_back(newPos);
|
---|
[2599] | 755 |
|
---|
[2648] | 756 | // Time Span for Average Computation
|
---|
| 757 | // ---------------------------------
|
---|
| 758 | double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
|
---|
| 759 | if (tRangeAverage < 0) {
|
---|
| 760 | tRangeAverage = 0;
|
---|
| 761 | }
|
---|
| 762 | if (tRangeAverage > 86400) {
|
---|
| 763 | tRangeAverage = 86400;
|
---|
| 764 | }
|
---|
[2599] | 765 |
|
---|
[2648] | 766 | // Compute the Mean
|
---|
| 767 | // ----------------
|
---|
[2670] | 768 | ColumnVector mean(7); mean = 0.0;
|
---|
[2648] | 769 |
|
---|
[2599] | 770 | QMutableVectorIterator<pppPos*> it(_posAverage);
|
---|
| 771 | while (it.hasNext()) {
|
---|
| 772 | pppPos* pp = it.next();
|
---|
[2648] | 773 | if ( (epoData->tt - pp->time) >= tRangeAverage ) {
|
---|
[2599] | 774 | delete pp;
|
---|
| 775 | it.remove();
|
---|
| 776 | }
|
---|
[2648] | 777 | else {
|
---|
[2670] | 778 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 779 | mean[ii] += pp->xnt[ii];
|
---|
[2649] | 780 | }
|
---|
[2648] | 781 | }
|
---|
[2599] | 782 | }
|
---|
[2648] | 783 |
|
---|
| 784 | int nn = _posAverage.size();
|
---|
| 785 |
|
---|
[2649] | 786 | if (nn > 0) {
|
---|
[2648] | 787 |
|
---|
[2649] | 788 | mean /= nn;
|
---|
| 789 |
|
---|
| 790 | // Compute the Deviation
|
---|
| 791 | // ---------------------
|
---|
[2670] | 792 | ColumnVector std(7); std = 0.0;
|
---|
[2649] | 793 | QVectorIterator<pppPos*> it2(_posAverage);
|
---|
| 794 | while (it2.hasNext()) {
|
---|
| 795 | pppPos* pp = it2.next();
|
---|
[2670] | 796 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 797 | std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
|
---|
[2649] | 798 | }
|
---|
| 799 | }
|
---|
[2670] | 800 | for (int ii = 0; ii < 7; ++ii) {
|
---|
[2649] | 801 | std[ii] = sqrt(std[ii] / nn);
|
---|
| 802 | }
|
---|
[3169] | 803 |
|
---|
| 804 | if (settings.value("pppRefCrdX").toString() != "" &&
|
---|
| 805 | settings.value("pppRefCrdY").toString() != "" &&
|
---|
| 806 | settings.value("pppRefCrdZ").toString() != "") {
|
---|
[2649] | 807 |
|
---|
[3169] | 808 | ostringstream strD; strD.setf(ios::fixed);
|
---|
| 809 | strD << _staID.data() << " AVE-XYZ "
|
---|
| 810 | << epoData->tt.timestr(1) << " "
|
---|
| 811 | << setw(13) << setprecision(3) << mean[0] + xyzRef[0] << " +- "
|
---|
| 812 | << setw(6) << setprecision(3) << std[0] << " "
|
---|
| 813 | << setw(14) << setprecision(3) << mean[1] + xyzRef[1] << " +- "
|
---|
| 814 | << setw(6) << setprecision(3) << std[1] << " "
|
---|
| 815 | << setw(14) << setprecision(3) << mean[2] + xyzRef[2] << " +- "
|
---|
| 816 | << setw(6) << setprecision(3) << std[2];
|
---|
| 817 | emit newMessage(QByteArray(strD.str().c_str()), true);
|
---|
[2649] | 818 |
|
---|
[3169] | 819 | ostringstream strE; strE.setf(ios::fixed);
|
---|
| 820 | strE << _staID.data() << " AVE-NEU "
|
---|
| 821 | << epoData->tt.timestr(1) << " "
|
---|
| 822 | << setw(13) << setprecision(3) << mean[3] << " +- "
|
---|
| 823 | << setw(6) << setprecision(3) << std[3] << " "
|
---|
| 824 | << setw(14) << setprecision(3) << mean[4] << " +- "
|
---|
| 825 | << setw(6) << setprecision(3) << std[4] << " "
|
---|
| 826 | << setw(14) << setprecision(3) << mean[5] << " +- "
|
---|
| 827 | << setw(6) << setprecision(3) << std[5];
|
---|
| 828 | emit newMessage(QByteArray(strE.str().c_str()), true);
|
---|
[2649] | 829 |
|
---|
[3169] | 830 | if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
|
---|
| 831 | ostringstream strF; strF.setf(ios::fixed);
|
---|
| 832 | strF << _staID.data() << " AVE-TRP "
|
---|
| 833 | << epoData->tt.timestr(1) << " "
|
---|
| 834 | << setw(13) << setprecision(3) << mean[6] << " +- "
|
---|
| 835 | << setw(6) << setprecision(3) << std[6] << endl;
|
---|
| 836 | emit newMessage(QByteArray(strF.str().c_str()), true);
|
---|
| 837 | }
|
---|
[2726] | 838 | }
|
---|
[2599] | 839 | }
|
---|
| 840 | }
|
---|
| 841 |
|
---|
[2131] | 842 | // NMEA Output
|
---|
| 843 | // -----------
|
---|
[2181] | 844 | double xyz[3];
|
---|
| 845 | xyz[0] = x();
|
---|
| 846 | xyz[1] = y();
|
---|
| 847 | xyz[2] = z();
|
---|
| 848 | double ell[3];
|
---|
| 849 | xyz2ell(xyz, ell);
|
---|
| 850 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
| 851 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
[2132] | 852 |
|
---|
[2181] | 853 | char phiCh = 'N';
|
---|
| 854 | if (phiDeg < 0) {
|
---|
| 855 | phiDeg = -phiDeg;
|
---|
| 856 | phiCh = 'S';
|
---|
| 857 | }
|
---|
| 858 | char lamCh = 'E';
|
---|
| 859 | if (lamDeg < 0) {
|
---|
[2563] | 860 | lamDeg = -lamDeg;
|
---|
| 861 | lamCh = 'W';
|
---|
[2181] | 862 | }
|
---|
[2132] | 863 |
|
---|
[2566] | 864 | string datestr = epoData->tt.datestr(0); // yyyymmdd
|
---|
| 865 | ostringstream strRMC;
|
---|
| 866 | strRMC.setf(ios::fixed);
|
---|
| 867 | strRMC << "GPRMC,"
|
---|
| 868 | << epoData->tt.timestr(0,0) << ",A,"
|
---|
| 869 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
| 870 | << setw(6) << setprecision(3) << setfill('0')
|
---|
| 871 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
| 872 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
| 873 | << setw(6) << setprecision(3) << setfill('0')
|
---|
| 874 | << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
|
---|
[2569] | 875 | << datestr[6] << datestr[7] << datestr[4] << datestr[5]
|
---|
| 876 | << datestr[2] << datestr[3] << ",,";
|
---|
[2566] | 877 |
|
---|
| 878 | writeNMEAstr(QString(strRMC.str().c_str()));
|
---|
| 879 |
|
---|
[2181] | 880 | double dop = 2.0; // TODO
|
---|
[2133] | 881 |
|
---|
[2566] | 882 | ostringstream strGGA;
|
---|
| 883 | strGGA.setf(ios::fixed);
|
---|
| 884 | strGGA << "GPGGA,"
|
---|
| 885 | << epoData->tt.timestr(0,0) << ','
|
---|
| 886 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
| 887 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 888 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
| 889 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
| 890 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 891 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
| 892 | << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
|
---|
| 893 | << setw(3) << setprecision(1) << dop << ','
|
---|
[2569] | 894 | << setprecision(3) << ell[2] << ",M,0.0,M,,";
|
---|
[2181] | 895 |
|
---|
[2566] | 896 | writeNMEAstr(QString(strGGA.str().c_str()));
|
---|
[2131] | 897 |
|
---|
[3106] | 898 | _lastTimeOK = _time; // remember time of last successful update
|
---|
[2060] | 899 | return success;
|
---|
| 900 | }
|
---|
[2112] | 901 |
|
---|
| 902 | // Outlier Detection
|
---|
| 903 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3375] | 904 | bool bncModel::outlierDetection(int iPhase, const ColumnVector& vv,
|
---|
[3383] | 905 | QMap<QString, t_satData*>& satData) {
|
---|
[2112] | 906 |
|
---|
[3312] | 907 | Tracer tracer("bncModel::outlierDetection");
|
---|
| 908 |
|
---|
[3386] | 909 | QString prn;
|
---|
| 910 | double maxRes = 0.0;
|
---|
| 911 | findMaxRes(vv, satData, prn, maxRes);
|
---|
[2231] | 912 |
|
---|
[3386] | 913 | if ( maxRes > (iPhase == 1 ? MAXRES_PHASE : MAXRES_CODE) ) {
|
---|
| 914 | _log += "Outlier " + prn + " "
|
---|
| 915 | + QByteArray::number(maxRes, 'f', 3) + "\n";
|
---|
| 916 | return true;
|
---|
[2792] | 917 | }
|
---|
[3308] | 918 | else {
|
---|
[3386] | 919 | return false;
|
---|
[2780] | 920 | }
|
---|
[2112] | 921 | }
|
---|
[2130] | 922 |
|
---|
| 923 | //
|
---|
| 924 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 925 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
---|
| 926 |
|
---|
[3312] | 927 | Tracer tracer("bncModel::writeNMEAstr");
|
---|
| 928 |
|
---|
[2130] | 929 | unsigned char XOR = 0;
|
---|
| 930 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
| 931 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
| 932 | }
|
---|
[2181] | 933 |
|
---|
| 934 | QString outStr = '$' + nmStr
|
---|
| 935 | + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
---|
[2130] | 936 |
|
---|
[2178] | 937 | if (_nmeaStream) {
|
---|
[2181] | 938 | *_nmeaStream << outStr;
|
---|
[2178] | 939 | _nmeaStream->flush();
|
---|
| 940 | }
|
---|
[2130] | 941 |
|
---|
[2181] | 942 | emit newNMEAstr(outStr.toAscii());
|
---|
[2130] | 943 | }
|
---|
[2283] | 944 |
|
---|
[3386] | 945 | //
|
---|
[2283] | 946 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 947 | void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
|
---|
| 948 | const DiagonalMatrix& PP,
|
---|
| 949 | SymmetricMatrix& QQ, ColumnVector& dx) {
|
---|
| 950 |
|
---|
[3312] | 951 | Tracer tracer("bncModel::kalman");
|
---|
| 952 |
|
---|
[2283] | 953 | int nObs = AA.Nrows();
|
---|
| 954 | int nPar = AA.Ncols();
|
---|
| 955 |
|
---|
| 956 | UpperTriangularMatrix SS = Cholesky(QQ).t();
|
---|
| 957 |
|
---|
| 958 | Matrix SA = SS*AA.t();
|
---|
| 959 | Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
|
---|
| 960 | for (int ii = 1; ii <= nObs; ++ii) {
|
---|
| 961 | SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
|
---|
| 962 | }
|
---|
| 963 |
|
---|
| 964 | SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
|
---|
| 965 | SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
|
---|
| 966 |
|
---|
| 967 | UpperTriangularMatrix UU;
|
---|
| 968 | QRZ(SRF, UU);
|
---|
| 969 |
|
---|
| 970 | SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
|
---|
| 971 | UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
|
---|
| 972 | Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
|
---|
| 973 |
|
---|
| 974 | UpperTriangularMatrix SHi = SH_rt.i();
|
---|
| 975 |
|
---|
| 976 | Matrix KT = SHi * YY;
|
---|
| 977 | SymmetricMatrix Hi; Hi << SHi * SHi.t();
|
---|
| 978 |
|
---|
| 979 | dx = KT.t() * ll;
|
---|
| 980 | QQ << (SS.t() * SS);
|
---|
| 981 | }
|
---|
[2582] | 982 |
|
---|
| 983 | // Phase Wind-Up Correction
|
---|
| 984 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 985 | double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
|
---|
| 986 | const ColumnVector& rRec) {
|
---|
| 987 |
|
---|
[3312] | 988 | Tracer tracer("bncModel::windUp");
|
---|
| 989 |
|
---|
[2582] | 990 | double Mjd = _time.mjd() + _time.daysec() / 86400.0;
|
---|
| 991 |
|
---|
| 992 | // First time - initialize to zero
|
---|
| 993 | // -------------------------------
|
---|
| 994 | if (!_windUpTime.contains(prn)) {
|
---|
| 995 | _windUpSum[prn] = 0.0;
|
---|
| 996 | }
|
---|
| 997 |
|
---|
| 998 | // Compute the correction for new time
|
---|
| 999 | // -----------------------------------
|
---|
[2942] | 1000 | if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
|
---|
[2582] | 1001 | _windUpTime[prn] = Mjd;
|
---|
| 1002 |
|
---|
| 1003 | // Unit Vector GPS Satellite --> Receiver
|
---|
| 1004 | // --------------------------------------
|
---|
| 1005 | ColumnVector rho = rRec - rSat;
|
---|
| 1006 | rho /= rho.norm_Frobenius();
|
---|
| 1007 |
|
---|
| 1008 | // GPS Satellite unit Vectors sz, sy, sx
|
---|
| 1009 | // -------------------------------------
|
---|
| 1010 | ColumnVector sz = -rSat / rSat.norm_Frobenius();
|
---|
| 1011 |
|
---|
| 1012 | ColumnVector xSun = Sun(Mjd);
|
---|
| 1013 | xSun /= xSun.norm_Frobenius();
|
---|
| 1014 |
|
---|
| 1015 | ColumnVector sy = crossproduct(sz, xSun);
|
---|
| 1016 | ColumnVector sx = crossproduct(sy, sz);
|
---|
| 1017 |
|
---|
| 1018 | // Effective Dipole of the GPS Satellite Antenna
|
---|
| 1019 | // ---------------------------------------------
|
---|
| 1020 | ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
|
---|
| 1021 | - crossproduct(rho, sy);
|
---|
| 1022 |
|
---|
| 1023 | // Receiver unit Vectors rx, ry
|
---|
| 1024 | // ----------------------------
|
---|
| 1025 | ColumnVector rx(3);
|
---|
| 1026 | ColumnVector ry(3);
|
---|
| 1027 |
|
---|
| 1028 | double recEll[3]; xyz2ell(rRec.data(), recEll) ;
|
---|
| 1029 | double neu[3];
|
---|
| 1030 |
|
---|
| 1031 | neu[0] = 1.0;
|
---|
| 1032 | neu[1] = 0.0;
|
---|
| 1033 | neu[2] = 0.0;
|
---|
| 1034 | neu2xyz(recEll, neu, rx.data());
|
---|
| 1035 |
|
---|
| 1036 | neu[0] = 0.0;
|
---|
| 1037 | neu[1] = -1.0;
|
---|
| 1038 | neu[2] = 0.0;
|
---|
| 1039 | neu2xyz(recEll, neu, ry.data());
|
---|
| 1040 |
|
---|
| 1041 | // Effective Dipole of the Receiver Antenna
|
---|
| 1042 | // ----------------------------------------
|
---|
| 1043 | ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
|
---|
| 1044 | + crossproduct(rho, ry);
|
---|
| 1045 |
|
---|
| 1046 | // Resulting Effect
|
---|
| 1047 | // ----------------
|
---|
| 1048 | double alpha = DotProduct(dipSat,dipRec) /
|
---|
| 1049 | (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
|
---|
| 1050 |
|
---|
| 1051 | if (alpha > 1.0) alpha = 1.0;
|
---|
| 1052 | if (alpha < -1.0) alpha = -1.0;
|
---|
| 1053 |
|
---|
| 1054 | double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
|
---|
| 1055 |
|
---|
| 1056 | if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
|
---|
| 1057 | dphi = -dphi;
|
---|
| 1058 | }
|
---|
| 1059 |
|
---|
| 1060 | _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
| 1063 | return _windUpSum[prn];
|
---|
| 1064 | }
|
---|
[2789] | 1065 |
|
---|
| 1066 | //
|
---|
| 1067 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1068 | void bncModel::cmpEle(t_satData* satData) {
|
---|
[3312] | 1069 | Tracer tracer("bncModel::cmpEle");
|
---|
[2789] | 1070 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 1071 | double rho = rr.norm_Frobenius();
|
---|
| 1072 |
|
---|
| 1073 | double neu[3];
|
---|
| 1074 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
| 1075 |
|
---|
| 1076 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 1077 | if (neu[2] < 0) {
|
---|
| 1078 | satData->eleSat *= -1.0;
|
---|
| 1079 | }
|
---|
| 1080 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
| 1083 | //
|
---|
| 1084 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1085 | void bncModel::addAmb(t_satData* satData) {
|
---|
[3312] | 1086 | Tracer tracer("bncModel::addAmb");
|
---|
[2789] | 1087 | bool found = false;
|
---|
| 1088 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 1089 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 1090 | _params[iPar-1]->prn == satData->prn) {
|
---|
| 1091 | found = true;
|
---|
| 1092 | break;
|
---|
| 1093 | }
|
---|
| 1094 | }
|
---|
| 1095 | if (!found) {
|
---|
| 1096 | bncParam* par = new bncParam(bncParam::AMB_L3,
|
---|
| 1097 | _params.size()+1, satData->prn);
|
---|
| 1098 | _params.push_back(par);
|
---|
| 1099 | par->xx = satData->L3 - cmpValue(satData, true);
|
---|
| 1100 | }
|
---|
| 1101 | }
|
---|
[2790] | 1102 |
|
---|
| 1103 | //
|
---|
| 1104 | ///////////////////////////////////////////////////////////////////////////
|
---|
[3309] | 1105 | void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
|
---|
[2790] | 1106 | Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
|
---|
| 1107 |
|
---|
[3312] | 1108 | Tracer tracer("bncModel::addObs");
|
---|
| 1109 |
|
---|
[3316] | 1110 | const double ELEWGHT = 20.0;
|
---|
[3314] | 1111 | double ellWgtCoef = 1.0;
|
---|
| 1112 | double eleD = satData->eleSat * 180.0 / M_PI;
|
---|
| 1113 | if (eleD < ELEWGHT) {
|
---|
[3317] | 1114 | ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
|
---|
[3314] | 1115 | }
|
---|
| 1116 |
|
---|
[3386] | 1117 | // Remember Observation Index
|
---|
| 1118 | // --------------------------
|
---|
| 1119 | ++iObs;
|
---|
| 1120 | satData->index = iObs;
|
---|
| 1121 |
|
---|
[2791] | 1122 | // Phase Observations
|
---|
| 1123 | // ------------------
|
---|
[3309] | 1124 | if (iPhase == 1) {
|
---|
[2790] | 1125 | ll(iObs) = satData->L3 - cmpValue(satData, true);
|
---|
[3314] | 1126 | PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3) / (ellWgtCoef * ellWgtCoef);
|
---|
[3319] | 1127 | if (satData->system() == 'R') {
|
---|
[3320] | 1128 | PP(iObs,iObs) /= 25.0;
|
---|
[3319] | 1129 | }
|
---|
[2790] | 1130 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 1131 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 1132 | _params[iPar-1]->prn == satData->prn) {
|
---|
| 1133 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
| 1134 | }
|
---|
| 1135 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
| 1136 | }
|
---|
| 1137 | }
|
---|
[3307] | 1138 |
|
---|
| 1139 | // Code Observations
|
---|
| 1140 | // -----------------
|
---|
| 1141 | else {
|
---|
| 1142 | ll(iObs) = satData->P3 - cmpValue(satData, false);
|
---|
[3314] | 1143 | PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3) / (ellWgtCoef * ellWgtCoef);
|
---|
[3307] | 1144 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 1145 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
|
---|
| 1146 | }
|
---|
| 1147 | }
|
---|
[2790] | 1148 | }
|
---|
[2791] | 1149 |
|
---|
| 1150 | //
|
---|
| 1151 | ///////////////////////////////////////////////////////////////////////////
|
---|
[3309] | 1152 | void bncModel::printRes(int iPhase, const ColumnVector& vv,
|
---|
[2791] | 1153 | ostringstream& str, t_satData* satData) {
|
---|
[3312] | 1154 | Tracer tracer("bncModel::printRes");
|
---|
[3386] | 1155 |
|
---|
| 1156 | if (satData->index != 0) {
|
---|
[2797] | 1157 | str << _time.timestr(1)
|
---|
[3386] | 1158 | << " RES " << satData->prn.toAscii().data()
|
---|
| 1159 | << (iPhase ? " L3 " : " P3 ")
|
---|
| 1160 | << setw(9) << setprecision(4) << vv(satData->index) << endl;
|
---|
[2791] | 1161 | }
|
---|
| 1162 | }
|
---|
[2792] | 1163 |
|
---|
| 1164 | //
|
---|
| 1165 | ///////////////////////////////////////////////////////////////////////////
|
---|
[3386] | 1166 | void bncModel::findMaxRes(const ColumnVector& vv,
|
---|
[2792] | 1167 | const QMap<QString, t_satData*>& satData,
|
---|
[3386] | 1168 | QString& prn, double& maxRes) {
|
---|
| 1169 |
|
---|
[3312] | 1170 | Tracer tracer("bncModel::findMaxRes");
|
---|
[2792] | 1171 |
|
---|
[3386] | 1172 | maxRes = 0.0;
|
---|
| 1173 |
|
---|
[2792] | 1174 | QMapIterator<QString, t_satData*> it(satData);
|
---|
| 1175 | while (it.hasNext()) {
|
---|
| 1176 | it.next();
|
---|
| 1177 | t_satData* satData = it.value();
|
---|
[3386] | 1178 | if (satData->index != 0 && fabs(vv(satData->index)) > maxRes) {
|
---|
| 1179 | maxRes = fabs(vv(satData->index));
|
---|
| 1180 | prn = satData->prn;
|
---|
[2792] | 1181 | }
|
---|
| 1182 | }
|
---|
| 1183 | }
|
---|
| 1184 |
|
---|
[3375] | 1185 | bool findInVector(const std::vector<QString>& vv, const QString& str) {
|
---|
| 1186 | std::vector<QString>::const_iterator it;
|
---|
| 1187 | for (it = vv.begin(); it != vv.end(); ++it) {
|
---|
| 1188 | if ( (*it) == str) {
|
---|
| 1189 | return true;
|
---|
| 1190 | }
|
---|
| 1191 | }
|
---|
| 1192 | return false;
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[3307] | 1195 | // Update Step (private - loop over outliers)
|
---|
| 1196 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3321] | 1197 | t_irc bncModel::update_p(t_epoData* epoData) {
|
---|
[3307] | 1198 |
|
---|
[3312] | 1199 | Tracer tracer("bncModel::update_p");
|
---|
| 1200 |
|
---|
[3384] | 1201 | // Bancroft Solution
|
---|
| 1202 | // -----------------
|
---|
| 1203 | if (cmpBancroft(epoData) != success) {
|
---|
| 1204 | return failure;
|
---|
| 1205 | }
|
---|
| 1206 |
|
---|
[3375] | 1207 | rememberState(epoData);
|
---|
[3307] | 1208 |
|
---|
[3375] | 1209 | ColumnVector dx;
|
---|
[3307] | 1210 |
|
---|
[3375] | 1211 | std::vector<QString> allPrns;
|
---|
[3383] | 1212 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 1213 | while (it.hasNext()) {
|
---|
| 1214 | it.next();
|
---|
| 1215 | t_satData* satData = it.value();
|
---|
| 1216 | allPrns.push_back(satData->prn);
|
---|
| 1217 | }
|
---|
[3375] | 1218 | std::vector<QString> usedPrns;
|
---|
| 1219 |
|
---|
| 1220 | // Try with all satellites, then with all minus one, etc.
|
---|
| 1221 | // ------------------------------------------------------
|
---|
[3385] | 1222 | for (unsigned nNeglected = 0; nNeglected <= allPrns.size() - MINOBS; nNeglected++) {
|
---|
[3375] | 1223 | usedPrns = allPrns;
|
---|
| 1224 |
|
---|
| 1225 | for (unsigned ii = 0; ii < nNeglected && usedPrns.size() > 0; ii++) {
|
---|
| 1226 | usedPrns.pop_back();
|
---|
| 1227 | }
|
---|
| 1228 |
|
---|
| 1229 | bool outlierDetected = false;
|
---|
| 1230 |
|
---|
| 1231 | // Loop over all Combinations of "nUsed" Satellites
|
---|
| 1232 | // ------------------------------------------------
|
---|
[3307] | 1233 | do {
|
---|
| 1234 |
|
---|
[3375] | 1235 | if (outlierDetected) {
|
---|
| 1236 | _log += "TRY WITH PRNs: ";
|
---|
| 1237 | for (unsigned ip = 0; ip < usedPrns.size(); ip++) {
|
---|
| 1238 | _log += usedPrns[ip] + ' ';
|
---|
[3307] | 1239 | }
|
---|
[3375] | 1240 | _log += '\n';
|
---|
[3307] | 1241 | }
|
---|
[3375] | 1242 |
|
---|
[3386] | 1243 | // Remove Neglected Satellites from epoData
|
---|
[3384] | 1244 | // ----------------------------------------
|
---|
[3375] | 1245 | for (unsigned ip = 0; ip < allPrns.size(); ip++) {
|
---|
| 1246 | QString prn = allPrns[ip];
|
---|
| 1247 | if ( !findInVector(usedPrns, prn) ) {
|
---|
[3383] | 1248 | epoData->satData.remove(prn);
|
---|
[3322] | 1249 | }
|
---|
[3375] | 1250 | }
|
---|
[3384] | 1251 | if (epoData->sizeSys('G') < MINOBS) {
|
---|
| 1252 | continue;
|
---|
| 1253 | }
|
---|
[3375] | 1254 |
|
---|
| 1255 | // First update using code observations, then phase observations
|
---|
| 1256 | // -------------------------------------------------------------
|
---|
| 1257 | for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++) {
|
---|
| 1258 |
|
---|
| 1259 | // Status Prediction
|
---|
| 1260 | // -----------------
|
---|
| 1261 | predict(iPhase, epoData);
|
---|
| 1262 |
|
---|
| 1263 | // Create First-Design Matrix
|
---|
| 1264 | // --------------------------
|
---|
| 1265 | unsigned nPar = _params.size();
|
---|
| 1266 | unsigned nObs = 0;
|
---|
| 1267 | if (iPhase == 0) {
|
---|
[3383] | 1268 | nObs = epoData->sizeAll() - epoData->sizeSys('R'); // Glonass code not used
|
---|
[3331] | 1269 | }
|
---|
[3375] | 1270 | else {
|
---|
[3383] | 1271 | nObs = epoData->sizeAll();
|
---|
[3308] | 1272 | }
|
---|
[3375] | 1273 |
|
---|
| 1274 | Matrix AA(nObs, nPar); // first design matrix
|
---|
| 1275 | ColumnVector ll(nObs); // tems observed-computed
|
---|
| 1276 | DiagonalMatrix PP(nObs); PP = 0.0;
|
---|
| 1277 |
|
---|
| 1278 | unsigned iObs = 0;
|
---|
| 1279 |
|
---|
| 1280 | // GPS
|
---|
| 1281 | // ---
|
---|
[3383] | 1282 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 1283 | while (it.hasNext()) {
|
---|
| 1284 | it.next();
|
---|
| 1285 | t_satData* satData = it.value();
|
---|
| 1286 | if (iPhase == 1 || satData->system() != 'R') {
|
---|
| 1287 | QString prn = satData->prn;
|
---|
[3387] | 1288 | addObs(iPhase, iObs, satData, AA, ll, PP);
|
---|
[3308] | 1289 | }
|
---|
[3307] | 1290 | }
|
---|
[3383] | 1291 |
|
---|
[3375] | 1292 | // Compute Filter Update
|
---|
| 1293 | // ---------------------
|
---|
| 1294 | kalman(AA, ll, PP, _QQ, dx);
|
---|
| 1295 |
|
---|
| 1296 | ColumnVector vv = ll - AA * dx;
|
---|
| 1297 |
|
---|
| 1298 | // Print Residuals
|
---|
| 1299 | // ---------------
|
---|
| 1300 | if (true) {
|
---|
| 1301 | ostringstream str;
|
---|
| 1302 | str.setf(ios::fixed);
|
---|
| 1303 |
|
---|
[3383] | 1304 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 1305 | while (it.hasNext()) {
|
---|
| 1306 | it.next();
|
---|
| 1307 | t_satData* satData = it.value();
|
---|
| 1308 | if (iPhase == 1 || satData->system() != 'R') {
|
---|
[3375] | 1309 | printRes(iPhase, vv, str, satData);
|
---|
| 1310 | }
|
---|
| 1311 | }
|
---|
| 1312 | _log += str.str().c_str();
|
---|
| 1313 | }
|
---|
| 1314 |
|
---|
| 1315 | // Check the residuals
|
---|
| 1316 | // -------------------
|
---|
[3383] | 1317 | outlierDetected = outlierDetection(iPhase, vv, epoData->satData);
|
---|
| 1318 |
|
---|
[3375] | 1319 | if (outlierDetected) {
|
---|
| 1320 | restoreState(epoData);
|
---|
| 1321 | break;
|
---|
| 1322 | }
|
---|
| 1323 |
|
---|
| 1324 | } // for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++)
|
---|
| 1325 |
|
---|
| 1326 | // Update Parameters
|
---|
| 1327 | // -----------------
|
---|
| 1328 | if (!outlierDetected) {
|
---|
| 1329 | QVectorIterator<bncParam*> itPar(_params);
|
---|
| 1330 | while (itPar.hasNext()) {
|
---|
| 1331 | bncParam* par = itPar.next();
|
---|
| 1332 | par->xx += dx(par->index);
|
---|
| 1333 | }
|
---|
| 1334 | return success;
|
---|
[3307] | 1335 | }
|
---|
[3321] | 1336 |
|
---|
[3375] | 1337 | } while ( next_combination(allPrns.begin(), allPrns.end(),
|
---|
| 1338 | usedPrns.begin(), usedPrns.end()) );
|
---|
[3307] | 1339 |
|
---|
[3388] | 1340 | } // for (unsigned nNeglected
|
---|
[3375] | 1341 |
|
---|
| 1342 | return failure;
|
---|
[3323] | 1343 | }
|
---|
| 1344 |
|
---|
| 1345 | // Remeber Original State Vector and Variance-Covariance Matrix
|
---|
| 1346 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3375] | 1347 | void bncModel::rememberState(t_epoData* epoData) {
|
---|
[3323] | 1348 |
|
---|
| 1349 | _QQ_sav = _QQ;
|
---|
| 1350 |
|
---|
| 1351 | QVectorIterator<bncParam*> itSav(_params_sav);
|
---|
| 1352 | while (itSav.hasNext()) {
|
---|
| 1353 | bncParam* par = itSav.next();
|
---|
[3322] | 1354 | delete par;
|
---|
| 1355 | }
|
---|
[3323] | 1356 | _params_sav.clear();
|
---|
| 1357 |
|
---|
| 1358 | QVectorIterator<bncParam*> it(_params);
|
---|
| 1359 | while (it.hasNext()) {
|
---|
| 1360 | bncParam* par = it.next();
|
---|
| 1361 | _params_sav.push_back(new bncParam(*par));
|
---|
| 1362 | }
|
---|
[3375] | 1363 |
|
---|
[3382] | 1364 | _epoData_sav->deepCopy(epoData);
|
---|
[3307] | 1365 | }
|
---|
[3323] | 1366 |
|
---|
| 1367 | // Restore Original State Vector and Variance-Covariance Matrix
|
---|
| 1368 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3375] | 1369 | void bncModel::restoreState(t_epoData* epoData) {
|
---|
[3323] | 1370 |
|
---|
| 1371 | _QQ = _QQ_sav;
|
---|
| 1372 |
|
---|
| 1373 | QVectorIterator<bncParam*> it(_params);
|
---|
| 1374 | while (it.hasNext()) {
|
---|
| 1375 | bncParam* par = it.next();
|
---|
| 1376 | delete par;
|
---|
| 1377 | }
|
---|
| 1378 | _params.clear();
|
---|
| 1379 |
|
---|
| 1380 | QVectorIterator<bncParam*> itSav(_params_sav);
|
---|
| 1381 | while (itSav.hasNext()) {
|
---|
| 1382 | bncParam* par = itSav.next();
|
---|
| 1383 | _params.push_back(new bncParam(*par));
|
---|
| 1384 | }
|
---|
[3375] | 1385 |
|
---|
[3382] | 1386 | epoData->deepCopy(_epoData_sav);
|
---|
[3323] | 1387 | }
|
---|