[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"
|
---|
[2057] | 53 |
|
---|
| 54 | using namespace std;
|
---|
| 55 |
|
---|
[2243] | 56 | const unsigned MINOBS = 4;
|
---|
[2287] | 57 | const double MINELE_GPS = 10.0 * M_PI / 180.0;
|
---|
| 58 | const double MINELE_GLO = 10.0 * M_PI / 180.0;
|
---|
[2243] | 59 | const double MAXRES_CODE_GPS = 10.0;
|
---|
| 60 | const double MAXRES_PHASE_GPS = 0.10;
|
---|
[2539] | 61 | const double MAXRES_PHASE_GLO = 0.05;
|
---|
[2648] | 62 | const double QUICKSTART = 120.0;
|
---|
[2283] | 63 | const double sig_clk_0 = 1000.0;
|
---|
[2489] | 64 | const double sig_trp_0 = 0.10;
|
---|
| 65 | const double sig_trp_p = 1e-8;
|
---|
[2540] | 66 | const double sig_amb_0_GPS = 1000.0;
|
---|
[2265] | 67 | const double sig_amb_0_GLO = 1000.0;
|
---|
[2286] | 68 | const double sig_L3_GPS = 0.02;
|
---|
[2538] | 69 | const double sig_L3_GLO = 0.05;
|
---|
[2070] | 70 |
|
---|
[2057] | 71 | // Constructor
|
---|
| 72 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 73 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
| 74 | const QString& prnIn) {
|
---|
| 75 | type = typeIn;
|
---|
| 76 | index = indexIn;
|
---|
| 77 | prn = prnIn;
|
---|
| 78 | index_old = 0;
|
---|
| 79 | xx = 0.0;
|
---|
[2473] | 80 |
|
---|
[2057] | 81 | }
|
---|
| 82 |
|
---|
| 83 | // Destructor
|
---|
| 84 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 85 | bncParam::~bncParam() {
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[2060] | 88 | // Partial
|
---|
| 89 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2239] | 90 | double bncParam::partial(t_satData* satData, bool phase) {
|
---|
| 91 |
|
---|
| 92 | // Coordinates
|
---|
| 93 | // -----------
|
---|
[2060] | 94 | if (type == CRD_X) {
|
---|
[2109] | 95 | return (xx - satData->xx(1)) / satData->rho;
|
---|
[2060] | 96 | }
|
---|
| 97 | else if (type == CRD_Y) {
|
---|
[2109] | 98 | return (xx - satData->xx(2)) / satData->rho;
|
---|
[2060] | 99 | }
|
---|
| 100 | else if (type == CRD_Z) {
|
---|
[2109] | 101 | return (xx - satData->xx(3)) / satData->rho;
|
---|
[2060] | 102 | }
|
---|
[2239] | 103 |
|
---|
| 104 | // Receiver Clocks
|
---|
| 105 | // ---------------
|
---|
[2265] | 106 | else if (type == RECCLK) {
|
---|
| 107 | return 1.0;
|
---|
[2060] | 108 | }
|
---|
[2239] | 109 |
|
---|
| 110 | // Troposphere
|
---|
| 111 | // -----------
|
---|
[2084] | 112 | else if (type == TROPO) {
|
---|
| 113 | return 1.0 / sin(satData->eleSat);
|
---|
| 114 | }
|
---|
[2239] | 115 |
|
---|
| 116 | // Ambiguities
|
---|
| 117 | // -----------
|
---|
[2080] | 118 | else if (type == AMB_L3) {
|
---|
[2239] | 119 | if (phase && satData->prn == prn) {
|
---|
[2080] | 120 | return 1.0;
|
---|
| 121 | }
|
---|
| 122 | else {
|
---|
| 123 | return 0.0;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
[2239] | 126 |
|
---|
| 127 | // Default return
|
---|
| 128 | // --------------
|
---|
[2060] | 129 | return 0.0;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[2058] | 132 | // Constructor
|
---|
| 133 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2113] | 134 | bncModel::bncModel(QByteArray staID) {
|
---|
[2084] | 135 |
|
---|
[2113] | 136 | _staID = staID;
|
---|
| 137 |
|
---|
[2648] | 138 | _startTime = QDateTime::currentDateTime();
|
---|
| 139 |
|
---|
| 140 | bncSettings settings;
|
---|
| 141 |
|
---|
| 142 | double sig_crd_0 = 100.0;
|
---|
| 143 |
|
---|
| 144 | if (settings.value("pppOrigin").toString() == "QuickStart - Static" ||
|
---|
| 145 | settings.value("pppOrigin").toString() == "QuickStart - Mobile") {
|
---|
| 146 | sig_crd_0 = 000.01;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[2113] | 149 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
[2548] | 150 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
[2113] | 151 |
|
---|
[2084] | 152 | _static = false;
|
---|
| 153 | if ( Qt::CheckState(settings.value("pppStatic").toInt()) == Qt::Checked) {
|
---|
| 154 | _static = true;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | _usePhase = false;
|
---|
| 158 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
|
---|
| 159 | _usePhase = true;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | _estTropo = false;
|
---|
| 163 | if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
|
---|
| 164 | _estTropo = true;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | _xcBanc.ReSize(4); _xcBanc = 0.0;
|
---|
| 168 | _ellBanc.ReSize(3); _ellBanc = 0.0;
|
---|
| 169 |
|
---|
[2265] | 170 | if (_usePhase &&
|
---|
| 171 | Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
|
---|
[2239] | 172 | _useGlonass = true;
|
---|
| 173 | }
|
---|
| 174 | else {
|
---|
| 175 | _useGlonass = false;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | int nextPar = 0;
|
---|
[2265] | 179 | _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
|
---|
| 180 | _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
|
---|
| 181 | _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
|
---|
| 182 | _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
|
---|
[2084] | 183 | if (_estTropo) {
|
---|
[2239] | 184 | _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
|
---|
[2084] | 185 | }
|
---|
[2073] | 186 |
|
---|
| 187 | unsigned nPar = _params.size();
|
---|
[2084] | 188 |
|
---|
[2073] | 189 | _QQ.ReSize(nPar);
|
---|
[2239] | 190 |
|
---|
[2073] | 191 | _QQ = 0.0;
|
---|
| 192 |
|
---|
[2239] | 193 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 194 | bncParam* pp = _params[iPar-1];
|
---|
| 195 | if (pp->isCrd()) {
|
---|
| 196 | _QQ(iPar,iPar) = sig_crd_0 * sig_crd_0;
|
---|
| 197 | }
|
---|
[2265] | 198 | else if (pp->type == bncParam::RECCLK) {
|
---|
[2239] | 199 | _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
|
---|
| 200 | }
|
---|
| 201 | else if (pp->type == bncParam::TROPO) {
|
---|
| 202 | _QQ(iPar,iPar) = sig_trp_0 * sig_trp_0;
|
---|
| 203 | }
|
---|
[2077] | 204 | }
|
---|
[2125] | 205 |
|
---|
| 206 | // NMEA Output
|
---|
| 207 | // -----------
|
---|
| 208 | QString nmeaFileName = settings.value("nmeaFile").toString();
|
---|
| 209 | if (nmeaFileName.isEmpty()) {
|
---|
| 210 | _nmeaFile = 0;
|
---|
| 211 | _nmeaStream = 0;
|
---|
| 212 | }
|
---|
| 213 | else {
|
---|
| 214 | expandEnvVar(nmeaFileName);
|
---|
| 215 | _nmeaFile = new QFile(nmeaFileName);
|
---|
| 216 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 217 | _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 218 | }
|
---|
| 219 | else {
|
---|
| 220 | _nmeaFile->open(QIODevice::WriteOnly);
|
---|
| 221 | }
|
---|
| 222 | _nmeaStream = new QTextStream();
|
---|
| 223 | _nmeaStream->setDevice(_nmeaFile);
|
---|
| 224 | }
|
---|
[2058] | 225 | }
|
---|
| 226 |
|
---|
| 227 | // Destructor
|
---|
| 228 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 229 | bncModel::~bncModel() {
|
---|
[2126] | 230 | delete _nmeaStream;
|
---|
| 231 | delete _nmeaFile;
|
---|
[2648] | 232 | for (int ii = 0; ii < _posAverage.size(); ++ii) {
|
---|
| 233 | delete _posAverage[ii];
|
---|
| 234 | }
|
---|
[2058] | 235 | }
|
---|
| 236 |
|
---|
| 237 | // Bancroft Solution
|
---|
| 238 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 239 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
---|
| 240 |
|
---|
[2231] | 241 | if (epoData->sizeGPS() < MINOBS) {
|
---|
[2547] | 242 | _log += "bncModel::cmpBancroft: not enough data\n";
|
---|
[2058] | 243 | return failure;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[2231] | 246 | Matrix BB(epoData->sizeGPS(), 4);
|
---|
[2058] | 247 |
|
---|
[2231] | 248 | QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
|
---|
[2058] | 249 | int iObs = 0;
|
---|
| 250 | while (it.hasNext()) {
|
---|
[2060] | 251 | ++iObs;
|
---|
[2058] | 252 | it.next();
|
---|
| 253 | QString prn = it.key();
|
---|
| 254 | t_satData* satData = it.value();
|
---|
| 255 | BB(iObs, 1) = satData->xx(1);
|
---|
| 256 | BB(iObs, 2) = satData->xx(2);
|
---|
| 257 | BB(iObs, 3) = satData->xx(3);
|
---|
| 258 | BB(iObs, 4) = satData->P3 + satData->clk;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | bancroft(BB, _xcBanc);
|
---|
| 262 |
|
---|
[2064] | 263 | // Ellipsoidal Coordinates
|
---|
| 264 | // ------------------------
|
---|
| 265 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
---|
[2063] | 266 |
|
---|
[2064] | 267 | // Compute Satellite Elevations
|
---|
| 268 | // ----------------------------
|
---|
[2231] | 269 | QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
---|
| 270 | while (iGPS.hasNext()) {
|
---|
| 271 | iGPS.next();
|
---|
| 272 | QString prn = iGPS.key();
|
---|
| 273 | t_satData* satData = iGPS.value();
|
---|
[2063] | 274 |
|
---|
[2109] | 275 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 276 | double rho = rr.norm_Frobenius();
|
---|
[2064] | 277 |
|
---|
| 278 | double neu[3];
|
---|
[2109] | 279 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
[2064] | 280 |
|
---|
| 281 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 282 | if (neu[2] < 0) {
|
---|
| 283 | satData->eleSat *= -1.0;
|
---|
| 284 | }
|
---|
| 285 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
[2070] | 286 |
|
---|
[2287] | 287 | if (satData->eleSat < MINELE_GPS) {
|
---|
[2070] | 288 | delete satData;
|
---|
[2231] | 289 | iGPS.remove();
|
---|
[2070] | 290 | }
|
---|
[2064] | 291 | }
|
---|
| 292 |
|
---|
[2231] | 293 | QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
---|
| 294 | while (iGlo.hasNext()) {
|
---|
| 295 | iGlo.next();
|
---|
| 296 | QString prn = iGlo.key();
|
---|
| 297 | t_satData* satData = iGlo.value();
|
---|
| 298 |
|
---|
| 299 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 300 | double rho = rr.norm_Frobenius();
|
---|
| 301 |
|
---|
| 302 | double neu[3];
|
---|
| 303 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
| 304 |
|
---|
| 305 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 306 | if (neu[2] < 0) {
|
---|
| 307 | satData->eleSat *= -1.0;
|
---|
| 308 | }
|
---|
| 309 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
| 310 |
|
---|
[2287] | 311 | if (satData->eleSat < MINELE_GLO) {
|
---|
[2231] | 312 | delete satData;
|
---|
| 313 | iGlo.remove();
|
---|
| 314 | }
|
---|
| 315 | }
|
---|
| 316 |
|
---|
[2058] | 317 | return success;
|
---|
| 318 | }
|
---|
[2060] | 319 |
|
---|
| 320 | // Computed Value
|
---|
| 321 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2583] | 322 | double bncModel::cmpValue(t_satData* satData, bool phase) {
|
---|
[2060] | 323 |
|
---|
[2073] | 324 | ColumnVector xRec(3);
|
---|
| 325 | xRec(1) = x();
|
---|
| 326 | xRec(2) = y();
|
---|
| 327 | xRec(3) = z();
|
---|
[2060] | 328 |
|
---|
[2073] | 329 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
---|
[2060] | 330 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
---|
| 331 |
|
---|
[2073] | 332 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
---|
| 333 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
---|
| 334 | xRec(3) = z();
|
---|
| 335 |
|
---|
[2580] | 336 | tides(_time, xRec);
|
---|
| 337 |
|
---|
[2060] | 338 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
---|
| 339 |
|
---|
[2084] | 340 | double tropDelay = delay_saast(satData->eleSat) +
|
---|
| 341 | trp() / sin(satData->eleSat);
|
---|
[2060] | 342 |
|
---|
[2583] | 343 | double wind = 0.0;
|
---|
| 344 | if (phase) {
|
---|
| 345 | wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | return satData->rho + clk() - satData->clk + tropDelay + wind;
|
---|
[2060] | 349 | }
|
---|
| 350 |
|
---|
[2063] | 351 | // Tropospheric Model (Saastamoinen)
|
---|
| 352 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2065] | 353 | double bncModel::delay_saast(double Ele) {
|
---|
[2063] | 354 |
|
---|
[2064] | 355 | double height = _ellBanc(3);
|
---|
[2063] | 356 |
|
---|
[2064] | 357 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
---|
| 358 | double TT = 18.0 - height * 0.0065 + 273.15;
|
---|
| 359 | double hh = 50.0 * exp(-6.396e-4 * height);
|
---|
[2063] | 360 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
---|
| 361 |
|
---|
[2064] | 362 | double h_km = height / 1000.0;
|
---|
[2063] | 363 |
|
---|
| 364 | if (h_km < 0.0) h_km = 0.0;
|
---|
| 365 | if (h_km > 5.0) h_km = 5.0;
|
---|
| 366 | int ii = int(h_km + 1);
|
---|
| 367 | double href = ii - 1;
|
---|
| 368 |
|
---|
| 369 | double bCor[6];
|
---|
| 370 | bCor[0] = 1.156;
|
---|
| 371 | bCor[1] = 1.006;
|
---|
| 372 | bCor[2] = 0.874;
|
---|
| 373 | bCor[3] = 0.757;
|
---|
| 374 | bCor[4] = 0.654;
|
---|
| 375 | bCor[5] = 0.563;
|
---|
| 376 |
|
---|
| 377 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
---|
| 378 |
|
---|
| 379 | double zen = M_PI/2.0 - Ele;
|
---|
| 380 |
|
---|
| 381 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[2073] | 384 | // Prediction Step of the Filter
|
---|
| 385 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 386 | void bncModel::predict(t_epoData* epoData) {
|
---|
[2073] | 387 |
|
---|
[2648] | 388 | bncSettings settings;
|
---|
[2244] | 389 |
|
---|
[2648] | 390 | bool firstCrd = false;
|
---|
| 391 | if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
|
---|
| 392 | firstCrd = true;
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | bool quickStartInit = false;
|
---|
| 396 | double sig_crd_p = 100.0;
|
---|
| 397 |
|
---|
| 398 | if ( (settings.value("pppOrigin").toString() == "QuickStart - Static" ||
|
---|
| 399 | settings.value("pppOrigin").toString() == "QuickStart - Mobile") &&
|
---|
| 400 | _startTime.secsTo(QDateTime::currentDateTime()) < QUICKSTART ) {
|
---|
| 401 | quickStartInit = true;
|
---|
| 402 | sig_crd_p = 0.0;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
[2244] | 405 | // Predict Parameter values, add white noise
|
---|
| 406 | // -----------------------------------------
|
---|
| 407 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 408 | bncParam* pp = _params[iPar-1];
|
---|
| 409 |
|
---|
| 410 | // Coordinates
|
---|
| 411 | // -----------
|
---|
| 412 | if (pp->type == bncParam::CRD_X) {
|
---|
| 413 | if (firstCrd || !_static) {
|
---|
[2648] | 414 | if (quickStartInit) {
|
---|
| 415 | pp->xx = settings.value("pppRefCrdX").toDouble();
|
---|
| 416 | }
|
---|
| 417 | else {
|
---|
| 418 | pp->xx = _xcBanc(1);
|
---|
| 419 | }
|
---|
[2244] | 420 | }
|
---|
| 421 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
| 422 | }
|
---|
| 423 | else if (pp->type == bncParam::CRD_Y) {
|
---|
| 424 | if (firstCrd || !_static) {
|
---|
[2648] | 425 | if (quickStartInit) {
|
---|
| 426 | pp->xx = settings.value("pppRefCrdY").toDouble();
|
---|
| 427 | }
|
---|
| 428 | else {
|
---|
| 429 | pp->xx = _xcBanc(2);
|
---|
| 430 | }
|
---|
[2244] | 431 | }
|
---|
| 432 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
| 433 | }
|
---|
| 434 | else if (pp->type == bncParam::CRD_Z) {
|
---|
| 435 | if (firstCrd || !_static) {
|
---|
[2648] | 436 | if (quickStartInit) {
|
---|
| 437 | pp->xx = settings.value("pppRefCrdZ").toDouble();
|
---|
| 438 | }
|
---|
| 439 | else {
|
---|
| 440 | pp->xx = _xcBanc(3);
|
---|
| 441 | }
|
---|
[2244] | 442 | }
|
---|
| 443 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | // Receiver Clocks
|
---|
| 447 | // ---------------
|
---|
[2265] | 448 | else if (pp->type == bncParam::RECCLK) {
|
---|
[2244] | 449 | pp->xx = _xcBanc(4);
|
---|
| 450 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 451 | _QQ(iPar, jj) = 0.0;
|
---|
| 452 | }
|
---|
| 453 | _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | // Tropospheric Delay
|
---|
| 457 | // ------------------
|
---|
| 458 | else if (pp->type == bncParam::TROPO) {
|
---|
| 459 | _QQ(iPar,iPar) += sig_trp_p * sig_trp_p;
|
---|
| 460 | }
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | // Add New Ambiguities if necessary
|
---|
| 464 | // --------------------------------
|
---|
[2083] | 465 | if (_usePhase) {
|
---|
[2080] | 466 |
|
---|
[2083] | 467 | // Make a copy of QQ and xx, set parameter indices
|
---|
| 468 | // -----------------------------------------------
|
---|
| 469 | SymmetricMatrix QQ_old = _QQ;
|
---|
| 470 |
|
---|
| 471 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 472 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
---|
| 473 | _params[iPar-1]->index = 0;
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | // Remove Ambiguity Parameters without observations
|
---|
| 477 | // ------------------------------------------------
|
---|
| 478 | int iPar = 0;
|
---|
| 479 | QMutableVectorIterator<bncParam*> it(_params);
|
---|
| 480 | while (it.hasNext()) {
|
---|
| 481 | bncParam* par = it.next();
|
---|
| 482 | bool removed = false;
|
---|
| 483 | if (par->type == bncParam::AMB_L3) {
|
---|
[2231] | 484 | if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
|
---|
| 485 | epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() ) {
|
---|
[2083] | 486 | removed = true;
|
---|
| 487 | delete par;
|
---|
| 488 | it.remove();
|
---|
| 489 | }
|
---|
[2080] | 490 | }
|
---|
[2083] | 491 | if (! removed) {
|
---|
| 492 | ++iPar;
|
---|
| 493 | par->index = iPar;
|
---|
| 494 | }
|
---|
[2080] | 495 | }
|
---|
[2083] | 496 |
|
---|
| 497 | // Add new ambiguity parameters
|
---|
| 498 | // ----------------------------
|
---|
[2231] | 499 | QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
---|
| 500 | while (iGPS.hasNext()) {
|
---|
| 501 | iGPS.next();
|
---|
[2233] | 502 | QString prn = iGPS.key();
|
---|
[2244] | 503 | t_satData* satData = iGPS.value();
|
---|
[2231] | 504 | bool found = false;
|
---|
[2083] | 505 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 506 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 507 | _params[iPar-1]->prn == prn) {
|
---|
| 508 | found = true;
|
---|
| 509 | break;
|
---|
| 510 | }
|
---|
[2080] | 511 | }
|
---|
[2083] | 512 | if (!found) {
|
---|
| 513 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
| 514 | _params.push_back(par);
|
---|
[2583] | 515 | par->xx = satData->L3 - cmpValue(satData, true);
|
---|
[2083] | 516 | }
|
---|
[2080] | 517 | }
|
---|
[2231] | 518 |
|
---|
| 519 | QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
---|
| 520 | while (iGlo.hasNext()) {
|
---|
| 521 | iGlo.next();
|
---|
[2233] | 522 | QString prn = iGlo.key();
|
---|
| 523 | t_satData* satData = iGlo.value();
|
---|
[2231] | 524 | bool found = false;
|
---|
| 525 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 526 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 527 | _params[iPar-1]->prn == prn) {
|
---|
| 528 | found = true;
|
---|
| 529 | break;
|
---|
| 530 | }
|
---|
| 531 | }
|
---|
| 532 | if (!found) {
|
---|
| 533 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
| 534 | _params.push_back(par);
|
---|
[2583] | 535 | par->xx = satData->L3 - cmpValue(satData, true);
|
---|
[2231] | 536 | }
|
---|
| 537 | }
|
---|
[2083] | 538 |
|
---|
| 539 | int nPar = _params.size();
|
---|
| 540 | _QQ.ReSize(nPar); _QQ = 0.0;
|
---|
| 541 | for (int i1 = 1; i1 <= nPar; i1++) {
|
---|
| 542 | bncParam* p1 = _params[i1-1];
|
---|
| 543 | if (p1->index_old != 0) {
|
---|
| 544 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
---|
| 545 | for (int i2 = 1; i2 <= nPar; i2++) {
|
---|
| 546 | bncParam* p2 = _params[i2-1];
|
---|
| 547 | if (p2->index_old != 0) {
|
---|
| 548 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
---|
| 549 | }
|
---|
[2080] | 550 | }
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
[2083] | 553 |
|
---|
| 554 | for (int ii = 1; ii <= nPar; ii++) {
|
---|
| 555 | bncParam* par = _params[ii-1];
|
---|
| 556 | if (par->index_old == 0) {
|
---|
[2265] | 557 | if (par->prn[0] == 'R') {
|
---|
| 558 | _QQ(par->index, par->index) = sig_amb_0_GLO * sig_amb_0_GLO;
|
---|
| 559 | }
|
---|
| 560 | else {
|
---|
| 561 | _QQ(par->index, par->index) = sig_amb_0_GPS * sig_amb_0_GPS;
|
---|
| 562 | }
|
---|
[2083] | 563 | }
|
---|
| 564 | par->index_old = par->index;
|
---|
[2080] | 565 | }
|
---|
| 566 | }
|
---|
| 567 |
|
---|
[2073] | 568 | }
|
---|
| 569 |
|
---|
[2060] | 570 | // Update Step of the Filter (currently just a single-epoch solution)
|
---|
| 571 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 572 | t_irc bncModel::update(t_epoData* epoData) {
|
---|
| 573 |
|
---|
[2473] | 574 | bncSettings settings;
|
---|
| 575 | double sig_P3;
|
---|
| 576 | sig_P3 = 5.0;
|
---|
| 577 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked ) {
|
---|
[2482] | 578 | sig_P3 = settings.value("pppSigmaCode").toDouble();
|
---|
[2473] | 579 | if (sig_P3 < 0.3 || sig_P3 > 50.0) {
|
---|
| 580 | sig_P3 = 5.0;
|
---|
| 581 | }
|
---|
| 582 | }
|
---|
| 583 |
|
---|
[2248] | 584 | _log.clear();
|
---|
[2124] | 585 |
|
---|
[2143] | 586 | _time = epoData->tt;
|
---|
| 587 |
|
---|
[2547] | 588 | _log += "Single Point Positioning of Epoch "
|
---|
| 589 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
| 590 | "\n--------------------------------------------------------------\n";
|
---|
| 591 |
|
---|
[2112] | 592 | SymmetricMatrix QQsav;
|
---|
[2109] | 593 | ColumnVector dx;
|
---|
[2112] | 594 | ColumnVector vv;
|
---|
[2073] | 595 |
|
---|
[2113] | 596 | // Loop over all outliers
|
---|
| 597 | // ----------------------
|
---|
[2108] | 598 | do {
|
---|
| 599 |
|
---|
| 600 | // Bancroft Solution
|
---|
| 601 | // -----------------
|
---|
| 602 | if (cmpBancroft(epoData) != success) {
|
---|
[2124] | 603 | emit newMessage(_log, false);
|
---|
[2108] | 604 | return failure;
|
---|
| 605 | }
|
---|
[2080] | 606 |
|
---|
[2108] | 607 | // Status Prediction
|
---|
| 608 | // -----------------
|
---|
| 609 | predict(epoData);
|
---|
| 610 |
|
---|
[2109] | 611 | // Create First-Design Matrix
|
---|
| 612 | // --------------------------
|
---|
[2108] | 613 | unsigned nPar = _params.size();
|
---|
[2231] | 614 | unsigned nObs = 0;
|
---|
| 615 | if (_usePhase) {
|
---|
[2238] | 616 | nObs = 2 * epoData->sizeGPS() + epoData->sizeGlo();
|
---|
[2231] | 617 | }
|
---|
| 618 | else {
|
---|
| 619 | nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
|
---|
| 620 | }
|
---|
[2108] | 621 |
|
---|
[2540] | 622 | if (nObs < nPar) {
|
---|
[2547] | 623 | _log += "bncModel::update: nObs < nPar\n";
|
---|
[2540] | 624 | emit newMessage(_log, false);
|
---|
| 625 | return failure;
|
---|
| 626 | }
|
---|
| 627 |
|
---|
[2108] | 628 | Matrix AA(nObs, nPar); // first design matrix
|
---|
| 629 | ColumnVector ll(nObs); // tems observed-computed
|
---|
[2283] | 630 | DiagonalMatrix PP(nObs); PP = 0.0;
|
---|
[2108] | 631 |
|
---|
| 632 | unsigned iObs = 0;
|
---|
[2231] | 633 |
|
---|
| 634 | // GPS code and (optionally) phase observations
|
---|
| 635 | // --------------------------------------------
|
---|
| 636 | QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
|
---|
| 637 | while (itGPS.hasNext()) {
|
---|
[2083] | 638 | ++iObs;
|
---|
[2231] | 639 | itGPS.next();
|
---|
| 640 | QString prn = itGPS.key();
|
---|
| 641 | t_satData* satData = itGPS.value();
|
---|
[2108] | 642 |
|
---|
[2583] | 643 | ll(iObs) = satData->P3 - cmpValue(satData, false);
|
---|
[2244] | 644 | PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3);
|
---|
[2083] | 645 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
[2239] | 646 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
|
---|
[2083] | 647 | }
|
---|
[2108] | 648 |
|
---|
| 649 | if (_usePhase) {
|
---|
| 650 | ++iObs;
|
---|
[2583] | 651 | ll(iObs) = satData->L3 - cmpValue(satData, true);
|
---|
[2244] | 652 | PP(iObs,iObs) = 1.0 / (sig_L3_GPS * sig_L3_GPS);
|
---|
[2108] | 653 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 654 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 655 | _params[iPar-1]->prn == prn) {
|
---|
[2109] | 656 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
[2108] | 657 | }
|
---|
[2239] | 658 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
[2108] | 659 | }
|
---|
| 660 | }
|
---|
[2080] | 661 | }
|
---|
[2231] | 662 |
|
---|
| 663 | // Glonass phase observations
|
---|
| 664 | // --------------------------
|
---|
| 665 | if (_usePhase) {
|
---|
| 666 | QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
|
---|
| 667 | while (itGlo.hasNext()) {
|
---|
[2238] | 668 | ++iObs;
|
---|
[2231] | 669 | itGlo.next();
|
---|
| 670 | QString prn = itGlo.key();
|
---|
| 671 | t_satData* satData = itGlo.value();
|
---|
[2238] | 672 |
|
---|
[2583] | 673 | ll(iObs) = satData->L3 - cmpValue(satData, true);
|
---|
[2244] | 674 | PP(iObs,iObs) = 1.0 / (sig_L3_GLO * sig_L3_GLO);
|
---|
[2238] | 675 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 676 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 677 | _params[iPar-1]->prn == prn) {
|
---|
| 678 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
| 679 | }
|
---|
[2239] | 680 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
[2238] | 681 | }
|
---|
[2231] | 682 | }
|
---|
| 683 | }
|
---|
| 684 |
|
---|
[2112] | 685 | // Compute Filter Update
|
---|
[2108] | 686 | // ---------------------
|
---|
[2112] | 687 | QQsav = _QQ;
|
---|
| 688 |
|
---|
[2283] | 689 | kalman(AA, ll, PP, _QQ, dx);
|
---|
| 690 |
|
---|
| 691 | vv = ll - AA * dx;
|
---|
| 692 |
|
---|
[2547] | 693 | ostringstream strA;
|
---|
| 694 | strA.setf(ios::fixed);
|
---|
[2265] | 695 | ColumnVector vv_code(epoData->sizeGPS());
|
---|
| 696 | ColumnVector vv_phase(epoData->sizeGPS());
|
---|
| 697 | ColumnVector vv_glo(epoData->sizeGlo());
|
---|
[2245] | 698 |
|
---|
[2265] | 699 | for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
|
---|
| 700 | if (_usePhase) {
|
---|
[2246] | 701 | vv_code(iobs) = vv(2*iobs-1);
|
---|
| 702 | vv_phase(iobs) = vv(2*iobs);
|
---|
| 703 | }
|
---|
[2265] | 704 | else {
|
---|
| 705 | vv_code(iobs) = vv(iobs);
|
---|
| 706 | }
|
---|
| 707 | }
|
---|
| 708 | if (_useGlonass) {
|
---|
[2246] | 709 | for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
|
---|
| 710 | vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
|
---|
| 711 | }
|
---|
[2265] | 712 | }
|
---|
[2246] | 713 |
|
---|
[2547] | 714 | strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
|
---|
[2265] | 715 | if (_usePhase) {
|
---|
[2547] | 716 | strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
|
---|
[2265] | 717 | }
|
---|
| 718 | if (_useGlonass) {
|
---|
[2547] | 719 | strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
|
---|
[2246] | 720 | }
|
---|
[2547] | 721 | _log += strA.str().c_str();
|
---|
[2246] | 722 |
|
---|
[2231] | 723 | } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
|
---|
[2233] | 724 | epoData->satDataGlo) != 0);
|
---|
[2111] | 725 |
|
---|
[2670] | 726 | // Remember the Epoch-specific Results for the computation of means
|
---|
| 727 | // ----------------------------------------------------------------
|
---|
| 728 | pppPos* newPos = new pppPos;
|
---|
| 729 | newPos->time = epoData->tt;
|
---|
| 730 |
|
---|
[2109] | 731 | // Set Solution Vector
|
---|
| 732 | // -------------------
|
---|
[2265] | 733 | ostringstream strB;
|
---|
| 734 | strB.setf(ios::fixed);
|
---|
[2073] | 735 | QVectorIterator<bncParam*> itPar(_params);
|
---|
[2060] | 736 | while (itPar.hasNext()) {
|
---|
| 737 | bncParam* par = itPar.next();
|
---|
[2109] | 738 | par->xx += dx(par->index);
|
---|
[2265] | 739 |
|
---|
| 740 | if (par->type == bncParam::RECCLK) {
|
---|
[2547] | 741 | strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
|
---|
[2124] | 742 | << " +- " << setw(6) << setprecision(3)
|
---|
| 743 | << sqrt(_QQ(par->index,par->index));
|
---|
| 744 | }
|
---|
| 745 | else if (par->type == bncParam::AMB_L3) {
|
---|
[2265] | 746 | strB << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
[2124] | 747 | << setw(6) << setprecision(3) << par->xx
|
---|
| 748 | << " +- " << setw(6) << setprecision(3)
|
---|
| 749 | << sqrt(_QQ(par->index,par->index));
|
---|
| 750 | }
|
---|
[2212] | 751 | else if (par->type == bncParam::TROPO) {
|
---|
[2670] | 752 | double aprTrp = delay_saast(M_PI/2.0);
|
---|
[2547] | 753 | strB << "\n trp = " << par->prn.toAscii().data()
|
---|
[2670] | 754 | << setw(7) << setprecision(3) << aprTrp << " "
|
---|
[2213] | 755 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
---|
[2212] | 756 | << " +- " << setw(6) << setprecision(3)
|
---|
| 757 | << sqrt(_QQ(par->index,par->index));
|
---|
[2670] | 758 | newPos->xnt[6] = aprTrp + par->xx;
|
---|
[2212] | 759 | }
|
---|
[2060] | 760 | }
|
---|
[2265] | 761 | strB << '\n';
|
---|
[2547] | 762 | _log += strB.str().c_str();
|
---|
| 763 | emit newMessage(_log, false);
|
---|
[2060] | 764 |
|
---|
[2547] | 765 | // Final Message (both log file and screen)
|
---|
| 766 | // ----------------------------------------
|
---|
| 767 | ostringstream strC;
|
---|
| 768 | strC.setf(ios::fixed);
|
---|
| 769 | strC << _staID.data() << " PPP "
|
---|
[2599] | 770 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
[2231] | 771 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
| 772 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
| 773 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
| 774 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
| 775 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
[2124] | 776 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
[2113] | 777 |
|
---|
[2370] | 778 | // NEU Output
|
---|
| 779 | // ----------
|
---|
[2648] | 780 | if (settings.value("pppOrigin").toString() == "Plot - X Y Z" ||
|
---|
| 781 | settings.value("pppOrigin").toString() == "QuickStart - Static") {
|
---|
[2649] | 782 |
|
---|
[2370] | 783 | double xyzRef[3];
|
---|
| 784 | xyzRef[0] = settings.value("pppRefCrdX").toDouble();
|
---|
| 785 | xyzRef[1] = settings.value("pppRefCrdY").toDouble();
|
---|
| 786 | xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
|
---|
[2649] | 787 |
|
---|
[2670] | 788 | newPos->xnt[0] = x() - xyzRef[0];
|
---|
| 789 | newPos->xnt[1] = y() - xyzRef[1];
|
---|
| 790 | newPos->xnt[2] = z() - xyzRef[2];
|
---|
[2649] | 791 |
|
---|
| 792 | double ellRef[3];
|
---|
[2370] | 793 | xyz2ell(xyzRef, ellRef);
|
---|
[2670] | 794 | xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
|
---|
[2649] | 795 |
|
---|
[2547] | 796 | strC << " NEU "
|
---|
[2670] | 797 | << setw(8) << setprecision(3) << newPos->xnt[3] << " "
|
---|
| 798 | << setw(8) << setprecision(3) << newPos->xnt[4] << " "
|
---|
| 799 | << setw(8) << setprecision(3) << newPos->xnt[5];
|
---|
[2649] | 800 |
|
---|
[2370] | 801 | }
|
---|
| 802 |
|
---|
[2547] | 803 | emit newMessage(QByteArray(strC.str().c_str()), true);
|
---|
| 804 |
|
---|
[2671] | 805 | if (settings.value("pppAverage").toString() == "") {
|
---|
| 806 | delete newPos;
|
---|
| 807 | }
|
---|
| 808 | else {
|
---|
| 809 |
|
---|
| 810 | _posAverage.push_back(newPos);
|
---|
[2599] | 811 |
|
---|
[2648] | 812 | // Time Span for Average Computation
|
---|
| 813 | // ---------------------------------
|
---|
| 814 | double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
|
---|
| 815 | if (tRangeAverage < 0) {
|
---|
| 816 | tRangeAverage = 0;
|
---|
| 817 | }
|
---|
| 818 | if (tRangeAverage > 86400) {
|
---|
| 819 | tRangeAverage = 86400;
|
---|
| 820 | }
|
---|
[2599] | 821 |
|
---|
[2648] | 822 | // Compute the Mean
|
---|
| 823 | // ----------------
|
---|
[2670] | 824 | ColumnVector mean(7); mean = 0.0;
|
---|
[2648] | 825 |
|
---|
[2599] | 826 | QMutableVectorIterator<pppPos*> it(_posAverage);
|
---|
| 827 | while (it.hasNext()) {
|
---|
| 828 | pppPos* pp = it.next();
|
---|
[2648] | 829 | if ( (epoData->tt - pp->time) >= tRangeAverage ) {
|
---|
[2599] | 830 | delete pp;
|
---|
| 831 | it.remove();
|
---|
| 832 | }
|
---|
[2648] | 833 | else {
|
---|
[2670] | 834 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 835 | mean[ii] += pp->xnt[ii];
|
---|
[2649] | 836 | }
|
---|
[2648] | 837 | }
|
---|
[2599] | 838 | }
|
---|
[2648] | 839 |
|
---|
| 840 | int nn = _posAverage.size();
|
---|
| 841 |
|
---|
[2649] | 842 | if (nn > 0) {
|
---|
[2648] | 843 |
|
---|
[2649] | 844 | mean /= nn;
|
---|
| 845 |
|
---|
| 846 | // Compute the Deviation
|
---|
| 847 | // ---------------------
|
---|
[2670] | 848 | ColumnVector std(7); std = 0.0;
|
---|
[2649] | 849 | QVectorIterator<pppPos*> it2(_posAverage);
|
---|
| 850 | while (it2.hasNext()) {
|
---|
| 851 | pppPos* pp = it2.next();
|
---|
[2670] | 852 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 853 | std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
|
---|
[2649] | 854 | }
|
---|
| 855 | }
|
---|
[2670] | 856 | for (int ii = 0; ii < 7; ++ii) {
|
---|
[2649] | 857 | std[ii] = sqrt(std[ii] / nn);
|
---|
| 858 | }
|
---|
| 859 |
|
---|
| 860 | ostringstream strD; strD.setf(ios::fixed);
|
---|
| 861 | strD << _staID.data() << " AVE-XYZ "
|
---|
| 862 | << epoData->tt.timestr(1) << " "
|
---|
| 863 | << setw(13) << setprecision(3) << mean[0] << " +- "
|
---|
| 864 | << setw(6) << setprecision(3) << std[0] << " "
|
---|
| 865 | << setw(14) << setprecision(3) << mean[1] << " +- "
|
---|
| 866 | << setw(6) << setprecision(3) << std[1] << " "
|
---|
| 867 | << setw(14) << setprecision(3) << mean[2] << " +- "
|
---|
[2650] | 868 | << setw(6) << setprecision(3) << std[2];
|
---|
| 869 | emit newMessage(QByteArray(strD.str().c_str()), true);
|
---|
[2649] | 870 |
|
---|
[2650] | 871 | ostringstream strE; strE.setf(ios::fixed);
|
---|
| 872 | strE << _staID.data() << " AVE-NEU "
|
---|
[2649] | 873 | << epoData->tt.timestr(1) << " "
|
---|
| 874 | << setw(13) << setprecision(3) << mean[3] << " +- "
|
---|
| 875 | << setw(6) << setprecision(3) << std[3] << " "
|
---|
| 876 | << setw(14) << setprecision(3) << mean[4] << " +- "
|
---|
| 877 | << setw(6) << setprecision(3) << std[4] << " "
|
---|
| 878 | << setw(14) << setprecision(3) << mean[5] << " +- "
|
---|
[2670] | 879 | << setw(6) << setprecision(3) << std[5];
|
---|
[2649] | 880 |
|
---|
[2650] | 881 | emit newMessage(QByteArray(strE.str().c_str()), true);
|
---|
[2670] | 882 |
|
---|
| 883 | ostringstream strF; strF.setf(ios::fixed);
|
---|
| 884 | strF << _staID.data() << " AVE-TRP "
|
---|
| 885 | << epoData->tt.timestr(1) << " "
|
---|
| 886 | << setw(13) << setprecision(3) << mean[6] << " +- "
|
---|
| 887 | << setw(6) << setprecision(3) << std[6] << endl;
|
---|
| 888 |
|
---|
| 889 | emit newMessage(QByteArray(strF.str().c_str()), true);
|
---|
[2599] | 890 | }
|
---|
| 891 | }
|
---|
| 892 |
|
---|
[2131] | 893 | // NMEA Output
|
---|
| 894 | // -----------
|
---|
[2181] | 895 | double xyz[3];
|
---|
| 896 | xyz[0] = x();
|
---|
| 897 | xyz[1] = y();
|
---|
| 898 | xyz[2] = z();
|
---|
| 899 | double ell[3];
|
---|
| 900 | xyz2ell(xyz, ell);
|
---|
| 901 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
| 902 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
[2132] | 903 |
|
---|
[2181] | 904 | char phiCh = 'N';
|
---|
| 905 | if (phiDeg < 0) {
|
---|
| 906 | phiDeg = -phiDeg;
|
---|
| 907 | phiCh = 'S';
|
---|
| 908 | }
|
---|
| 909 | char lamCh = 'E';
|
---|
| 910 | if (lamDeg < 0) {
|
---|
[2563] | 911 | lamDeg = -lamDeg;
|
---|
| 912 | lamCh = 'W';
|
---|
[2181] | 913 | }
|
---|
[2132] | 914 |
|
---|
[2566] | 915 | string datestr = epoData->tt.datestr(0); // yyyymmdd
|
---|
| 916 | ostringstream strRMC;
|
---|
| 917 | strRMC.setf(ios::fixed);
|
---|
| 918 | strRMC << "GPRMC,"
|
---|
| 919 | << epoData->tt.timestr(0,0) << ",A,"
|
---|
| 920 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
| 921 | << setw(6) << setprecision(3) << setfill('0')
|
---|
| 922 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
| 923 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
| 924 | << setw(6) << setprecision(3) << setfill('0')
|
---|
| 925 | << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
|
---|
[2569] | 926 | << datestr[6] << datestr[7] << datestr[4] << datestr[5]
|
---|
| 927 | << datestr[2] << datestr[3] << ",,";
|
---|
[2566] | 928 |
|
---|
| 929 | writeNMEAstr(QString(strRMC.str().c_str()));
|
---|
| 930 |
|
---|
[2181] | 931 | double dop = 2.0; // TODO
|
---|
[2133] | 932 |
|
---|
[2566] | 933 | ostringstream strGGA;
|
---|
| 934 | strGGA.setf(ios::fixed);
|
---|
| 935 | strGGA << "GPGGA,"
|
---|
| 936 | << epoData->tt.timestr(0,0) << ','
|
---|
| 937 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
| 938 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 939 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
| 940 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
| 941 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 942 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
| 943 | << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
|
---|
| 944 | << setw(3) << setprecision(1) << dop << ','
|
---|
[2569] | 945 | << setprecision(3) << ell[2] << ",M,0.0,M,,";
|
---|
[2181] | 946 |
|
---|
[2566] | 947 | writeNMEAstr(QString(strGGA.str().c_str()));
|
---|
[2131] | 948 |
|
---|
[2060] | 949 | return success;
|
---|
| 950 | }
|
---|
[2112] | 951 |
|
---|
| 952 | // Outlier Detection
|
---|
| 953 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 954 | int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
|
---|
| 955 | const ColumnVector& vv,
|
---|
[2231] | 956 | QMap<QString, t_satData*>& satDataGPS,
|
---|
| 957 | QMap<QString, t_satData*>& satDataGlo) {
|
---|
[2112] | 958 |
|
---|
[2231] | 959 | double vvMaxCodeGPS = 0.0;
|
---|
| 960 | double vvMaxPhaseGPS = 0.0;
|
---|
| 961 | double vvMaxPhaseGlo = 0.0;
|
---|
| 962 | QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
|
---|
| 963 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
|
---|
| 964 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
|
---|
[2112] | 965 |
|
---|
| 966 | int ii = 0;
|
---|
[2231] | 967 |
|
---|
| 968 | // GPS code and (optionally) phase residuals
|
---|
| 969 | // -----------------------------------------
|
---|
| 970 | QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
|
---|
| 971 | while (itGPS.hasNext()) {
|
---|
| 972 | itGPS.next();
|
---|
[2112] | 973 | ++ii;
|
---|
| 974 |
|
---|
[2231] | 975 | if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
|
---|
| 976 | vvMaxCodeGPS = fabs(vv(ii));
|
---|
| 977 | itMaxCodeGPS = itGPS;
|
---|
[2112] | 978 | }
|
---|
| 979 |
|
---|
| 980 | if (_usePhase) {
|
---|
| 981 | ++ii;
|
---|
[2231] | 982 | if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
|
---|
| 983 | vvMaxPhaseGPS = fabs(vv(ii));
|
---|
| 984 | itMaxPhaseGPS = itGPS;
|
---|
[2112] | 985 | }
|
---|
| 986 | }
|
---|
| 987 | }
|
---|
[2231] | 988 |
|
---|
[2238] | 989 | // Glonass phase residuals
|
---|
| 990 | // -----------------------
|
---|
| 991 | if (_usePhase) {
|
---|
| 992 | QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
|
---|
| 993 | while (itGlo.hasNext()) {
|
---|
| 994 | itGlo.next();
|
---|
| 995 | ++ii;
|
---|
| 996 | if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
|
---|
| 997 | vvMaxPhaseGlo = fabs(vv(ii));
|
---|
| 998 | itMaxPhaseGlo = itGlo;
|
---|
| 999 | }
|
---|
| 1000 | }
|
---|
| 1001 | }
|
---|
[2112] | 1002 |
|
---|
[2248] | 1003 | if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
|
---|
| 1004 | QString prn = itMaxPhaseGlo.key();
|
---|
| 1005 | t_satData* satData = itMaxPhaseGlo.value();
|
---|
| 1006 | delete satData;
|
---|
| 1007 | itMaxPhaseGlo.remove();
|
---|
| 1008 | _QQ = QQsav;
|
---|
| 1009 |
|
---|
[2547] | 1010 | _log += "Outlier Phase " + prn.toAscii() + " "
|
---|
| 1011 | + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
|
---|
[2248] | 1012 |
|
---|
| 1013 | return 1;
|
---|
| 1014 | }
|
---|
| 1015 |
|
---|
| 1016 | else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
|
---|
[2231] | 1017 | QString prn = itMaxCodeGPS.key();
|
---|
| 1018 | t_satData* satData = itMaxCodeGPS.value();
|
---|
[2112] | 1019 | delete satData;
|
---|
[2231] | 1020 | itMaxCodeGPS.remove();
|
---|
[2112] | 1021 | _QQ = QQsav;
|
---|
[2114] | 1022 |
|
---|
[2547] | 1023 | _log += "Outlier Code " + prn.toAscii() + " "
|
---|
| 1024 | + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
|
---|
[2114] | 1025 |
|
---|
[2112] | 1026 | return 1;
|
---|
| 1027 | }
|
---|
[2243] | 1028 | else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
|
---|
[2231] | 1029 | QString prn = itMaxPhaseGPS.key();
|
---|
| 1030 | t_satData* satData = itMaxPhaseGPS.value();
|
---|
[2112] | 1031 | delete satData;
|
---|
[2231] | 1032 | itMaxPhaseGPS.remove();
|
---|
[2112] | 1033 | _QQ = QQsav;
|
---|
[2114] | 1034 |
|
---|
[2547] | 1035 | _log += "Outlier Phase " + prn.toAscii() + " "
|
---|
| 1036 | + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
|
---|
[2114] | 1037 |
|
---|
[2112] | 1038 | return 1;
|
---|
| 1039 | }
|
---|
[2231] | 1040 |
|
---|
[2112] | 1041 | return 0;
|
---|
| 1042 | }
|
---|
[2130] | 1043 |
|
---|
| 1044 | //
|
---|
| 1045 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1046 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
---|
| 1047 |
|
---|
| 1048 | unsigned char XOR = 0;
|
---|
| 1049 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
| 1050 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
| 1051 | }
|
---|
[2181] | 1052 |
|
---|
| 1053 | QString outStr = '$' + nmStr
|
---|
| 1054 | + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
---|
[2130] | 1055 |
|
---|
[2178] | 1056 | if (_nmeaStream) {
|
---|
[2181] | 1057 | *_nmeaStream << outStr;
|
---|
[2178] | 1058 | _nmeaStream->flush();
|
---|
| 1059 | }
|
---|
[2130] | 1060 |
|
---|
[2181] | 1061 | emit newNMEAstr(outStr.toAscii());
|
---|
[2130] | 1062 | }
|
---|
[2283] | 1063 |
|
---|
| 1064 | ////
|
---|
| 1065 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 1066 | void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
|
---|
| 1067 | const DiagonalMatrix& PP,
|
---|
| 1068 | SymmetricMatrix& QQ, ColumnVector& dx) {
|
---|
| 1069 |
|
---|
| 1070 | int nObs = AA.Nrows();
|
---|
| 1071 | int nPar = AA.Ncols();
|
---|
| 1072 |
|
---|
| 1073 | UpperTriangularMatrix SS = Cholesky(QQ).t();
|
---|
| 1074 |
|
---|
| 1075 | Matrix SA = SS*AA.t();
|
---|
| 1076 | Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
|
---|
| 1077 | for (int ii = 1; ii <= nObs; ++ii) {
|
---|
| 1078 | SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
|
---|
| 1079 | }
|
---|
| 1080 |
|
---|
| 1081 | SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
|
---|
| 1082 | SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
|
---|
| 1083 |
|
---|
| 1084 | UpperTriangularMatrix UU;
|
---|
| 1085 | QRZ(SRF, UU);
|
---|
| 1086 |
|
---|
| 1087 | SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
|
---|
| 1088 | UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
|
---|
| 1089 | Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
|
---|
| 1090 |
|
---|
| 1091 | UpperTriangularMatrix SHi = SH_rt.i();
|
---|
| 1092 |
|
---|
| 1093 | Matrix KT = SHi * YY;
|
---|
| 1094 | SymmetricMatrix Hi; Hi << SHi * SHi.t();
|
---|
| 1095 |
|
---|
| 1096 | dx = KT.t() * ll;
|
---|
| 1097 | QQ << (SS.t() * SS);
|
---|
| 1098 | }
|
---|
[2582] | 1099 |
|
---|
| 1100 | // Phase Wind-Up Correction
|
---|
| 1101 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1102 | double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
|
---|
| 1103 | const ColumnVector& rRec) {
|
---|
| 1104 |
|
---|
| 1105 | double Mjd = _time.mjd() + _time.daysec() / 86400.0;
|
---|
| 1106 |
|
---|
| 1107 | // First time - initialize to zero
|
---|
| 1108 | // -------------------------------
|
---|
| 1109 | if (!_windUpTime.contains(prn)) {
|
---|
| 1110 | _windUpTime[prn] = Mjd;
|
---|
| 1111 | _windUpSum[prn] = 0.0;
|
---|
| 1112 | }
|
---|
| 1113 |
|
---|
| 1114 | // Compute the correction for new time
|
---|
| 1115 | // -----------------------------------
|
---|
| 1116 | else if (_windUpTime[prn] != Mjd) {
|
---|
| 1117 | _windUpTime[prn] = Mjd;
|
---|
| 1118 |
|
---|
| 1119 | // Unit Vector GPS Satellite --> Receiver
|
---|
| 1120 | // --------------------------------------
|
---|
| 1121 | ColumnVector rho = rRec - rSat;
|
---|
| 1122 | rho /= rho.norm_Frobenius();
|
---|
| 1123 |
|
---|
| 1124 | // GPS Satellite unit Vectors sz, sy, sx
|
---|
| 1125 | // -------------------------------------
|
---|
| 1126 | ColumnVector sz = -rSat / rSat.norm_Frobenius();
|
---|
| 1127 |
|
---|
| 1128 | ColumnVector xSun = Sun(Mjd);
|
---|
| 1129 | xSun /= xSun.norm_Frobenius();
|
---|
| 1130 |
|
---|
| 1131 | ColumnVector sy = crossproduct(sz, xSun);
|
---|
| 1132 | ColumnVector sx = crossproduct(sy, sz);
|
---|
| 1133 |
|
---|
| 1134 | // Effective Dipole of the GPS Satellite Antenna
|
---|
| 1135 | // ---------------------------------------------
|
---|
| 1136 | ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
|
---|
| 1137 | - crossproduct(rho, sy);
|
---|
| 1138 |
|
---|
| 1139 | // Receiver unit Vectors rx, ry
|
---|
| 1140 | // ----------------------------
|
---|
| 1141 | ColumnVector rx(3);
|
---|
| 1142 | ColumnVector ry(3);
|
---|
| 1143 |
|
---|
| 1144 | double recEll[3]; xyz2ell(rRec.data(), recEll) ;
|
---|
| 1145 | double neu[3];
|
---|
| 1146 |
|
---|
| 1147 | neu[0] = 1.0;
|
---|
| 1148 | neu[1] = 0.0;
|
---|
| 1149 | neu[2] = 0.0;
|
---|
| 1150 | neu2xyz(recEll, neu, rx.data());
|
---|
| 1151 |
|
---|
| 1152 | neu[0] = 0.0;
|
---|
| 1153 | neu[1] = -1.0;
|
---|
| 1154 | neu[2] = 0.0;
|
---|
| 1155 | neu2xyz(recEll, neu, ry.data());
|
---|
| 1156 |
|
---|
| 1157 | // Effective Dipole of the Receiver Antenna
|
---|
| 1158 | // ----------------------------------------
|
---|
| 1159 | ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
|
---|
| 1160 | + crossproduct(rho, ry);
|
---|
| 1161 |
|
---|
| 1162 | // Resulting Effect
|
---|
| 1163 | // ----------------
|
---|
| 1164 | double alpha = DotProduct(dipSat,dipRec) /
|
---|
| 1165 | (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
|
---|
| 1166 |
|
---|
| 1167 | if (alpha > 1.0) alpha = 1.0;
|
---|
| 1168 | if (alpha < -1.0) alpha = -1.0;
|
---|
| 1169 |
|
---|
| 1170 | double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
|
---|
| 1171 |
|
---|
| 1172 | if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
|
---|
| 1173 | dphi = -dphi;
|
---|
| 1174 | }
|
---|
| 1175 |
|
---|
| 1176 | _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
|
---|
| 1177 | }
|
---|
| 1178 |
|
---|
| 1179 | return _windUpSum[prn];
|
---|
| 1180 | }
|
---|