[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"
|
---|
[2057] | 52 |
|
---|
| 53 | using namespace std;
|
---|
| 54 |
|
---|
[2243] | 55 | const unsigned MINOBS = 4;
|
---|
[2287] | 56 | const double MINELE_GPS = 10.0 * M_PI / 180.0;
|
---|
| 57 | const double MINELE_GLO = 10.0 * M_PI / 180.0;
|
---|
[2243] | 58 | const double MAXRES_CODE_GPS = 10.0;
|
---|
| 59 | const double MAXRES_PHASE_GPS = 0.10;
|
---|
[2267] | 60 | const double MAXRES_PHASE_GLO = 0.10;
|
---|
[2243] | 61 | const double sig_crd_0 = 100.0;
|
---|
| 62 | const double sig_crd_p = 100.0;
|
---|
[2283] | 63 | const double sig_clk_0 = 1000.0;
|
---|
[2287] | 64 | const double sig_trp_0 = 0.01;
|
---|
[2286] | 65 | const double sig_trp_p = 1e-7;
|
---|
[2265] | 66 | const double sig_amb_0_GPS = 100.0;
|
---|
| 67 | const double sig_amb_0_GLO = 1000.0;
|
---|
[2477] | 68 | ////const double sig_P3 = 20.0;
|
---|
[2286] | 69 | const double sig_L3_GPS = 0.02;
|
---|
| 70 | const double sig_L3_GLO = 0.02;
|
---|
[2070] | 71 |
|
---|
[2057] | 72 | // Constructor
|
---|
| 73 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 74 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
| 75 | const QString& prnIn) {
|
---|
| 76 | type = typeIn;
|
---|
| 77 | index = indexIn;
|
---|
| 78 | prn = prnIn;
|
---|
| 79 | index_old = 0;
|
---|
| 80 | xx = 0.0;
|
---|
[2473] | 81 |
|
---|
[2057] | 82 | }
|
---|
| 83 |
|
---|
| 84 | // Destructor
|
---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 86 | bncParam::~bncParam() {
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[2060] | 89 | // Partial
|
---|
| 90 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2239] | 91 | double bncParam::partial(t_satData* satData, bool phase) {
|
---|
| 92 |
|
---|
| 93 | // Coordinates
|
---|
| 94 | // -----------
|
---|
[2060] | 95 | if (type == CRD_X) {
|
---|
[2109] | 96 | return (xx - satData->xx(1)) / satData->rho;
|
---|
[2060] | 97 | }
|
---|
| 98 | else if (type == CRD_Y) {
|
---|
[2109] | 99 | return (xx - satData->xx(2)) / satData->rho;
|
---|
[2060] | 100 | }
|
---|
| 101 | else if (type == CRD_Z) {
|
---|
[2109] | 102 | return (xx - satData->xx(3)) / satData->rho;
|
---|
[2060] | 103 | }
|
---|
[2239] | 104 |
|
---|
| 105 | // Receiver Clocks
|
---|
| 106 | // ---------------
|
---|
[2265] | 107 | else if (type == RECCLK) {
|
---|
| 108 | return 1.0;
|
---|
[2060] | 109 | }
|
---|
[2239] | 110 |
|
---|
| 111 | // Troposphere
|
---|
| 112 | // -----------
|
---|
[2084] | 113 | else if (type == TROPO) {
|
---|
| 114 | return 1.0 / sin(satData->eleSat);
|
---|
| 115 | }
|
---|
[2239] | 116 |
|
---|
| 117 | // Ambiguities
|
---|
| 118 | // -----------
|
---|
[2080] | 119 | else if (type == AMB_L3) {
|
---|
[2239] | 120 | if (phase && satData->prn == prn) {
|
---|
[2080] | 121 | return 1.0;
|
---|
| 122 | }
|
---|
| 123 | else {
|
---|
| 124 | return 0.0;
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
[2239] | 127 |
|
---|
| 128 | // Default return
|
---|
| 129 | // --------------
|
---|
[2060] | 130 | return 0.0;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[2058] | 133 | // Constructor
|
---|
| 134 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2113] | 135 | bncModel::bncModel(QByteArray staID) {
|
---|
[2084] | 136 |
|
---|
[2113] | 137 | _staID = staID;
|
---|
| 138 |
|
---|
| 139 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 140 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 141 |
|
---|
[2084] | 142 | bncSettings settings;
|
---|
| 143 |
|
---|
| 144 | _static = false;
|
---|
| 145 | if ( Qt::CheckState(settings.value("pppStatic").toInt()) == Qt::Checked) {
|
---|
| 146 | _static = true;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | _usePhase = false;
|
---|
| 150 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
|
---|
| 151 | _usePhase = true;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | _estTropo = false;
|
---|
| 155 | if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
|
---|
| 156 | _estTropo = true;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | _xcBanc.ReSize(4); _xcBanc = 0.0;
|
---|
| 160 | _ellBanc.ReSize(3); _ellBanc = 0.0;
|
---|
| 161 |
|
---|
[2265] | 162 | if (_usePhase &&
|
---|
| 163 | Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
|
---|
[2239] | 164 | _useGlonass = true;
|
---|
| 165 | }
|
---|
| 166 | else {
|
---|
| 167 | _useGlonass = false;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | int nextPar = 0;
|
---|
[2265] | 171 | _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
|
---|
| 172 | _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
|
---|
| 173 | _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
|
---|
| 174 | _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
|
---|
[2084] | 175 | if (_estTropo) {
|
---|
[2239] | 176 | _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
|
---|
[2084] | 177 | }
|
---|
[2073] | 178 |
|
---|
| 179 | unsigned nPar = _params.size();
|
---|
[2084] | 180 |
|
---|
[2073] | 181 | _QQ.ReSize(nPar);
|
---|
[2239] | 182 |
|
---|
[2073] | 183 | _QQ = 0.0;
|
---|
| 184 |
|
---|
[2239] | 185 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 186 | bncParam* pp = _params[iPar-1];
|
---|
| 187 | if (pp->isCrd()) {
|
---|
| 188 | _QQ(iPar,iPar) = sig_crd_0 * sig_crd_0;
|
---|
| 189 | }
|
---|
[2265] | 190 | else if (pp->type == bncParam::RECCLK) {
|
---|
[2239] | 191 | _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
|
---|
| 192 | }
|
---|
| 193 | else if (pp->type == bncParam::TROPO) {
|
---|
| 194 | _QQ(iPar,iPar) = sig_trp_0 * sig_trp_0;
|
---|
| 195 | }
|
---|
[2077] | 196 | }
|
---|
[2125] | 197 |
|
---|
| 198 | // NMEA Output
|
---|
| 199 | // -----------
|
---|
| 200 | QString nmeaFileName = settings.value("nmeaFile").toString();
|
---|
| 201 | if (nmeaFileName.isEmpty()) {
|
---|
| 202 | _nmeaFile = 0;
|
---|
| 203 | _nmeaStream = 0;
|
---|
| 204 | }
|
---|
| 205 | else {
|
---|
| 206 | expandEnvVar(nmeaFileName);
|
---|
| 207 | _nmeaFile = new QFile(nmeaFileName);
|
---|
| 208 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 209 | _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 210 | }
|
---|
| 211 | else {
|
---|
| 212 | _nmeaFile->open(QIODevice::WriteOnly);
|
---|
| 213 | }
|
---|
| 214 | _nmeaStream = new QTextStream();
|
---|
| 215 | _nmeaStream->setDevice(_nmeaFile);
|
---|
[2130] | 216 | QDateTime dateTime = QDateTime::currentDateTime().toUTC();
|
---|
| 217 | QString nmStr = "GPRMC," + dateTime.time().toString("hhmmss")
|
---|
[2171] | 218 | + ",A,,,,,,,"
|
---|
[2130] | 219 | + dateTime.date().toString("ddMMyy")
|
---|
[2171] | 220 | + ",,";
|
---|
[2130] | 221 |
|
---|
| 222 | writeNMEAstr(nmStr);
|
---|
[2125] | 223 | }
|
---|
[2058] | 224 | }
|
---|
| 225 |
|
---|
| 226 | // Destructor
|
---|
| 227 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 228 | bncModel::~bncModel() {
|
---|
[2126] | 229 | delete _nmeaStream;
|
---|
| 230 | delete _nmeaFile;
|
---|
[2058] | 231 | }
|
---|
| 232 |
|
---|
| 233 | // Bancroft Solution
|
---|
| 234 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 235 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
---|
| 236 |
|
---|
[2231] | 237 | if (epoData->sizeGPS() < MINOBS) {
|
---|
[2124] | 238 | _log += "\nNot enough data";
|
---|
[2058] | 239 | return failure;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[2231] | 242 | Matrix BB(epoData->sizeGPS(), 4);
|
---|
[2058] | 243 |
|
---|
[2231] | 244 | QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
|
---|
[2058] | 245 | int iObs = 0;
|
---|
| 246 | while (it.hasNext()) {
|
---|
[2060] | 247 | ++iObs;
|
---|
[2058] | 248 | it.next();
|
---|
| 249 | QString prn = it.key();
|
---|
| 250 | t_satData* satData = it.value();
|
---|
| 251 | BB(iObs, 1) = satData->xx(1);
|
---|
| 252 | BB(iObs, 2) = satData->xx(2);
|
---|
| 253 | BB(iObs, 3) = satData->xx(3);
|
---|
| 254 | BB(iObs, 4) = satData->P3 + satData->clk;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | bancroft(BB, _xcBanc);
|
---|
| 258 |
|
---|
[2064] | 259 | // Ellipsoidal Coordinates
|
---|
| 260 | // ------------------------
|
---|
| 261 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
---|
[2063] | 262 |
|
---|
[2064] | 263 | // Compute Satellite Elevations
|
---|
| 264 | // ----------------------------
|
---|
[2231] | 265 | QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
---|
| 266 | while (iGPS.hasNext()) {
|
---|
| 267 | iGPS.next();
|
---|
| 268 | QString prn = iGPS.key();
|
---|
| 269 | t_satData* satData = iGPS.value();
|
---|
[2063] | 270 |
|
---|
[2109] | 271 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 272 | double rho = rr.norm_Frobenius();
|
---|
[2064] | 273 |
|
---|
| 274 | double neu[3];
|
---|
[2109] | 275 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
[2064] | 276 |
|
---|
| 277 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 278 | if (neu[2] < 0) {
|
---|
| 279 | satData->eleSat *= -1.0;
|
---|
| 280 | }
|
---|
| 281 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
[2070] | 282 |
|
---|
[2287] | 283 | if (satData->eleSat < MINELE_GPS) {
|
---|
[2070] | 284 | delete satData;
|
---|
[2231] | 285 | iGPS.remove();
|
---|
[2070] | 286 | }
|
---|
[2064] | 287 | }
|
---|
| 288 |
|
---|
[2231] | 289 | QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
---|
| 290 | while (iGlo.hasNext()) {
|
---|
| 291 | iGlo.next();
|
---|
| 292 | QString prn = iGlo.key();
|
---|
| 293 | t_satData* satData = iGlo.value();
|
---|
| 294 |
|
---|
| 295 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 296 | double rho = rr.norm_Frobenius();
|
---|
| 297 |
|
---|
| 298 | double neu[3];
|
---|
| 299 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
| 300 |
|
---|
| 301 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 302 | if (neu[2] < 0) {
|
---|
| 303 | satData->eleSat *= -1.0;
|
---|
| 304 | }
|
---|
| 305 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
| 306 |
|
---|
[2287] | 307 | if (satData->eleSat < MINELE_GLO) {
|
---|
[2231] | 308 | delete satData;
|
---|
| 309 | iGlo.remove();
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[2058] | 313 | return success;
|
---|
| 314 | }
|
---|
[2060] | 315 |
|
---|
| 316 | // Computed Value
|
---|
| 317 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 318 | double bncModel::cmpValue(t_satData* satData) {
|
---|
[2060] | 319 |
|
---|
[2073] | 320 | ColumnVector xRec(3);
|
---|
| 321 | xRec(1) = x();
|
---|
| 322 | xRec(2) = y();
|
---|
| 323 | xRec(3) = z();
|
---|
[2060] | 324 |
|
---|
[2073] | 325 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
---|
[2060] | 326 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
---|
| 327 |
|
---|
[2073] | 328 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
---|
| 329 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
---|
| 330 | xRec(3) = z();
|
---|
| 331 |
|
---|
[2060] | 332 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
---|
| 333 |
|
---|
[2084] | 334 | double tropDelay = delay_saast(satData->eleSat) +
|
---|
| 335 | trp() / sin(satData->eleSat);
|
---|
[2060] | 336 |
|
---|
[2265] | 337 | return satData->rho + clk() - satData->clk + tropDelay;
|
---|
[2060] | 338 | }
|
---|
| 339 |
|
---|
[2063] | 340 | // Tropospheric Model (Saastamoinen)
|
---|
| 341 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2065] | 342 | double bncModel::delay_saast(double Ele) {
|
---|
[2063] | 343 |
|
---|
[2064] | 344 | double height = _ellBanc(3);
|
---|
[2063] | 345 |
|
---|
[2064] | 346 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
---|
| 347 | double TT = 18.0 - height * 0.0065 + 273.15;
|
---|
| 348 | double hh = 50.0 * exp(-6.396e-4 * height);
|
---|
[2063] | 349 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
---|
| 350 |
|
---|
[2064] | 351 | double h_km = height / 1000.0;
|
---|
[2063] | 352 |
|
---|
| 353 | if (h_km < 0.0) h_km = 0.0;
|
---|
| 354 | if (h_km > 5.0) h_km = 5.0;
|
---|
| 355 | int ii = int(h_km + 1);
|
---|
| 356 | double href = ii - 1;
|
---|
| 357 |
|
---|
| 358 | double bCor[6];
|
---|
| 359 | bCor[0] = 1.156;
|
---|
| 360 | bCor[1] = 1.006;
|
---|
| 361 | bCor[2] = 0.874;
|
---|
| 362 | bCor[3] = 0.757;
|
---|
| 363 | bCor[4] = 0.654;
|
---|
| 364 | bCor[5] = 0.563;
|
---|
| 365 |
|
---|
| 366 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
---|
| 367 |
|
---|
| 368 | double zen = M_PI/2.0 - Ele;
|
---|
| 369 |
|
---|
| 370 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
---|
| 371 | }
|
---|
| 372 |
|
---|
[2073] | 373 | // Prediction Step of the Filter
|
---|
| 374 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 375 | void bncModel::predict(t_epoData* epoData) {
|
---|
[2073] | 376 |
|
---|
[2244] | 377 | bool firstCrd = x() == 0.0 && y() == 0.0 && z() == 0.0;
|
---|
| 378 |
|
---|
| 379 | // Predict Parameter values, add white noise
|
---|
| 380 | // -----------------------------------------
|
---|
| 381 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 382 | bncParam* pp = _params[iPar-1];
|
---|
| 383 |
|
---|
| 384 | // Coordinates
|
---|
| 385 | // -----------
|
---|
| 386 | if (pp->type == bncParam::CRD_X) {
|
---|
| 387 | if (firstCrd || !_static) {
|
---|
| 388 | pp->xx = _xcBanc(1);
|
---|
| 389 | }
|
---|
| 390 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
| 391 | }
|
---|
| 392 | else if (pp->type == bncParam::CRD_Y) {
|
---|
| 393 | if (firstCrd || !_static) {
|
---|
| 394 | pp->xx = _xcBanc(2);
|
---|
| 395 | }
|
---|
| 396 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
| 397 | }
|
---|
| 398 | else if (pp->type == bncParam::CRD_Z) {
|
---|
| 399 | if (firstCrd || !_static) {
|
---|
| 400 | pp->xx = _xcBanc(3);
|
---|
| 401 | }
|
---|
| 402 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | // Receiver Clocks
|
---|
| 406 | // ---------------
|
---|
[2265] | 407 | else if (pp->type == bncParam::RECCLK) {
|
---|
[2244] | 408 | pp->xx = _xcBanc(4);
|
---|
| 409 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 410 | _QQ(iPar, jj) = 0.0;
|
---|
| 411 | }
|
---|
| 412 | _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | // Tropospheric Delay
|
---|
| 416 | // ------------------
|
---|
| 417 | else if (pp->type == bncParam::TROPO) {
|
---|
| 418 | _QQ(iPar,iPar) += sig_trp_p * sig_trp_p;
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | // Add New Ambiguities if necessary
|
---|
| 423 | // --------------------------------
|
---|
[2083] | 424 | if (_usePhase) {
|
---|
[2080] | 425 |
|
---|
[2083] | 426 | // Make a copy of QQ and xx, set parameter indices
|
---|
| 427 | // -----------------------------------------------
|
---|
| 428 | SymmetricMatrix QQ_old = _QQ;
|
---|
| 429 |
|
---|
| 430 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 431 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
---|
| 432 | _params[iPar-1]->index = 0;
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | // Remove Ambiguity Parameters without observations
|
---|
| 436 | // ------------------------------------------------
|
---|
| 437 | int iPar = 0;
|
---|
| 438 | QMutableVectorIterator<bncParam*> it(_params);
|
---|
| 439 | while (it.hasNext()) {
|
---|
| 440 | bncParam* par = it.next();
|
---|
| 441 | bool removed = false;
|
---|
| 442 | if (par->type == bncParam::AMB_L3) {
|
---|
[2231] | 443 | if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
|
---|
| 444 | epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() ) {
|
---|
[2083] | 445 | removed = true;
|
---|
| 446 | delete par;
|
---|
| 447 | it.remove();
|
---|
| 448 | }
|
---|
[2080] | 449 | }
|
---|
[2083] | 450 | if (! removed) {
|
---|
| 451 | ++iPar;
|
---|
| 452 | par->index = iPar;
|
---|
| 453 | }
|
---|
[2080] | 454 | }
|
---|
[2083] | 455 |
|
---|
| 456 | // Add new ambiguity parameters
|
---|
| 457 | // ----------------------------
|
---|
[2231] | 458 | QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
---|
| 459 | while (iGPS.hasNext()) {
|
---|
| 460 | iGPS.next();
|
---|
[2233] | 461 | QString prn = iGPS.key();
|
---|
[2244] | 462 | t_satData* satData = iGPS.value();
|
---|
[2231] | 463 | bool found = false;
|
---|
[2083] | 464 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 465 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 466 | _params[iPar-1]->prn == prn) {
|
---|
| 467 | found = true;
|
---|
| 468 | break;
|
---|
| 469 | }
|
---|
[2080] | 470 | }
|
---|
[2083] | 471 | if (!found) {
|
---|
| 472 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
| 473 | _params.push_back(par);
|
---|
[2244] | 474 | par->xx = satData->L3 - cmpValue(satData);
|
---|
[2083] | 475 | }
|
---|
[2080] | 476 | }
|
---|
[2231] | 477 |
|
---|
| 478 | QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
---|
| 479 | while (iGlo.hasNext()) {
|
---|
| 480 | iGlo.next();
|
---|
[2233] | 481 | QString prn = iGlo.key();
|
---|
| 482 | t_satData* satData = iGlo.value();
|
---|
[2231] | 483 | bool found = false;
|
---|
| 484 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 485 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 486 | _params[iPar-1]->prn == prn) {
|
---|
| 487 | found = true;
|
---|
| 488 | break;
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 | if (!found) {
|
---|
| 492 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
| 493 | _params.push_back(par);
|
---|
[2244] | 494 | par->xx = satData->L3 - cmpValue(satData);
|
---|
[2231] | 495 | }
|
---|
| 496 | }
|
---|
[2083] | 497 |
|
---|
| 498 | int nPar = _params.size();
|
---|
| 499 | _QQ.ReSize(nPar); _QQ = 0.0;
|
---|
| 500 | for (int i1 = 1; i1 <= nPar; i1++) {
|
---|
| 501 | bncParam* p1 = _params[i1-1];
|
---|
| 502 | if (p1->index_old != 0) {
|
---|
| 503 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
---|
| 504 | for (int i2 = 1; i2 <= nPar; i2++) {
|
---|
| 505 | bncParam* p2 = _params[i2-1];
|
---|
| 506 | if (p2->index_old != 0) {
|
---|
| 507 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
---|
| 508 | }
|
---|
[2080] | 509 | }
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
[2083] | 512 |
|
---|
| 513 | for (int ii = 1; ii <= nPar; ii++) {
|
---|
| 514 | bncParam* par = _params[ii-1];
|
---|
| 515 | if (par->index_old == 0) {
|
---|
[2265] | 516 | if (par->prn[0] == 'R') {
|
---|
| 517 | _QQ(par->index, par->index) = sig_amb_0_GLO * sig_amb_0_GLO;
|
---|
| 518 | }
|
---|
| 519 | else {
|
---|
| 520 | _QQ(par->index, par->index) = sig_amb_0_GPS * sig_amb_0_GPS;
|
---|
| 521 | }
|
---|
[2083] | 522 | }
|
---|
| 523 | par->index_old = par->index;
|
---|
[2080] | 524 | }
|
---|
| 525 | }
|
---|
| 526 |
|
---|
[2073] | 527 | }
|
---|
| 528 |
|
---|
[2060] | 529 | // Update Step of the Filter (currently just a single-epoch solution)
|
---|
| 530 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 531 | t_irc bncModel::update(t_epoData* epoData) {
|
---|
| 532 |
|
---|
[2473] | 533 | bncSettings settings;
|
---|
| 534 | double sig_P3;
|
---|
| 535 | sig_P3 = 5.0;
|
---|
| 536 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked ) {
|
---|
| 537 | sig_P3 = settings.value("pppSigC").toDouble();
|
---|
| 538 | if (sig_P3 < 0.3 || sig_P3 > 50.0) {
|
---|
| 539 | sig_P3 = 5.0;
|
---|
| 540 | }
|
---|
| 541 | }
|
---|
| 542 |
|
---|
[2248] | 543 | _log.clear();
|
---|
[2124] | 544 |
|
---|
[2143] | 545 | _time = epoData->tt;
|
---|
| 546 |
|
---|
[2112] | 547 | SymmetricMatrix QQsav;
|
---|
[2109] | 548 | ColumnVector dx;
|
---|
[2112] | 549 | ColumnVector vv;
|
---|
[2073] | 550 |
|
---|
[2113] | 551 | // Loop over all outliers
|
---|
| 552 | // ----------------------
|
---|
[2108] | 553 | do {
|
---|
| 554 |
|
---|
| 555 | // Bancroft Solution
|
---|
| 556 | // -----------------
|
---|
| 557 | if (cmpBancroft(epoData) != success) {
|
---|
[2124] | 558 | _log += "\nBancroft failed";
|
---|
| 559 | emit newMessage(_log, false);
|
---|
[2108] | 560 | return failure;
|
---|
| 561 | }
|
---|
[2080] | 562 |
|
---|
[2231] | 563 | if (epoData->sizeGPS() < MINOBS) {
|
---|
[2124] | 564 | _log += "\nNot enough data";
|
---|
| 565 | emit newMessage(_log, false);
|
---|
[2116] | 566 | return failure;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
[2108] | 569 | // Status Prediction
|
---|
| 570 | // -----------------
|
---|
| 571 | predict(epoData);
|
---|
| 572 |
|
---|
[2109] | 573 | // Create First-Design Matrix
|
---|
| 574 | // --------------------------
|
---|
[2108] | 575 | unsigned nPar = _params.size();
|
---|
[2231] | 576 | unsigned nObs = 0;
|
---|
| 577 | if (_usePhase) {
|
---|
[2238] | 578 | nObs = 2 * epoData->sizeGPS() + epoData->sizeGlo();
|
---|
[2231] | 579 | }
|
---|
| 580 | else {
|
---|
| 581 | nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
|
---|
| 582 | }
|
---|
[2108] | 583 |
|
---|
| 584 | Matrix AA(nObs, nPar); // first design matrix
|
---|
| 585 | ColumnVector ll(nObs); // tems observed-computed
|
---|
[2283] | 586 | DiagonalMatrix PP(nObs); PP = 0.0;
|
---|
[2108] | 587 |
|
---|
| 588 | unsigned iObs = 0;
|
---|
[2231] | 589 |
|
---|
| 590 | // GPS code and (optionally) phase observations
|
---|
| 591 | // --------------------------------------------
|
---|
| 592 | QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
|
---|
| 593 | while (itGPS.hasNext()) {
|
---|
[2083] | 594 | ++iObs;
|
---|
[2231] | 595 | itGPS.next();
|
---|
| 596 | QString prn = itGPS.key();
|
---|
| 597 | t_satData* satData = itGPS.value();
|
---|
[2108] | 598 |
|
---|
| 599 | double rhoCmp = cmpValue(satData);
|
---|
| 600 |
|
---|
| 601 | ll(iObs) = satData->P3 - rhoCmp;
|
---|
[2244] | 602 | PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3);
|
---|
[2083] | 603 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
[2239] | 604 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
|
---|
[2083] | 605 | }
|
---|
[2108] | 606 |
|
---|
| 607 | if (_usePhase) {
|
---|
| 608 | ++iObs;
|
---|
| 609 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
[2244] | 610 | PP(iObs,iObs) = 1.0 / (sig_L3_GPS * sig_L3_GPS);
|
---|
[2108] | 611 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 612 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 613 | _params[iPar-1]->prn == prn) {
|
---|
[2109] | 614 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
[2108] | 615 | }
|
---|
[2239] | 616 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
[2108] | 617 | }
|
---|
| 618 | }
|
---|
[2080] | 619 | }
|
---|
[2231] | 620 |
|
---|
| 621 | // Glonass phase observations
|
---|
| 622 | // --------------------------
|
---|
| 623 | if (_usePhase) {
|
---|
| 624 | QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
|
---|
| 625 | while (itGlo.hasNext()) {
|
---|
[2238] | 626 | ++iObs;
|
---|
[2231] | 627 | itGlo.next();
|
---|
| 628 | QString prn = itGlo.key();
|
---|
| 629 | t_satData* satData = itGlo.value();
|
---|
[2238] | 630 |
|
---|
| 631 | double rhoCmp = cmpValue(satData);
|
---|
| 632 |
|
---|
| 633 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
[2242] | 634 |
|
---|
[2244] | 635 | PP(iObs,iObs) = 1.0 / (sig_L3_GLO * sig_L3_GLO);
|
---|
[2238] | 636 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 637 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 638 | _params[iPar-1]->prn == prn) {
|
---|
| 639 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
| 640 | }
|
---|
[2239] | 641 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
[2238] | 642 | }
|
---|
[2231] | 643 | }
|
---|
| 644 | }
|
---|
| 645 |
|
---|
[2112] | 646 | // Compute Filter Update
|
---|
[2108] | 647 | // ---------------------
|
---|
[2112] | 648 | QQsav = _QQ;
|
---|
| 649 |
|
---|
[2283] | 650 | // Matrix ATP = AA.t() * PP;
|
---|
| 651 | // SymmetricMatrix NN = _QQ.i();
|
---|
| 652 | // NN << NN + ATP * AA;
|
---|
| 653 | // _QQ = NN.i();
|
---|
| 654 | // dx = _QQ * ATP * ll;
|
---|
[2060] | 655 |
|
---|
[2283] | 656 | kalman(AA, ll, PP, _QQ, dx);
|
---|
| 657 |
|
---|
| 658 | vv = ll - AA * dx;
|
---|
| 659 |
|
---|
[2265] | 660 | ostringstream str;
|
---|
| 661 | str.setf(ios::fixed);
|
---|
| 662 | ColumnVector vv_code(epoData->sizeGPS());
|
---|
| 663 | ColumnVector vv_phase(epoData->sizeGPS());
|
---|
| 664 | ColumnVector vv_glo(epoData->sizeGlo());
|
---|
[2245] | 665 |
|
---|
[2265] | 666 | for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
|
---|
| 667 | if (_usePhase) {
|
---|
[2246] | 668 | vv_code(iobs) = vv(2*iobs-1);
|
---|
| 669 | vv_phase(iobs) = vv(2*iobs);
|
---|
| 670 | }
|
---|
[2265] | 671 | else {
|
---|
| 672 | vv_code(iobs) = vv(iobs);
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
| 675 | if (_useGlonass) {
|
---|
[2246] | 676 | for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
|
---|
| 677 | vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
|
---|
| 678 | }
|
---|
[2265] | 679 | }
|
---|
[2246] | 680 |
|
---|
[2265] | 681 | str << "\nresiduals code " << setprecision(3) << vv_code.t();
|
---|
| 682 | if (_usePhase) {
|
---|
[2248] | 683 | str << "residuals phase " << setprecision(3) << vv_phase.t();
|
---|
[2265] | 684 | }
|
---|
| 685 | if (_useGlonass) {
|
---|
[2248] | 686 | str << "residuals glo " << setprecision(3) << vv_glo.t();
|
---|
[2246] | 687 | }
|
---|
[2265] | 688 | _log += str.str().c_str();
|
---|
[2246] | 689 |
|
---|
[2231] | 690 | } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
|
---|
[2233] | 691 | epoData->satDataGlo) != 0);
|
---|
[2111] | 692 |
|
---|
[2109] | 693 | // Set Solution Vector
|
---|
| 694 | // -------------------
|
---|
[2265] | 695 | ostringstream strB;
|
---|
| 696 | strB.setf(ios::fixed);
|
---|
[2073] | 697 | QVectorIterator<bncParam*> itPar(_params);
|
---|
[2060] | 698 | while (itPar.hasNext()) {
|
---|
| 699 | bncParam* par = itPar.next();
|
---|
[2109] | 700 | par->xx += dx(par->index);
|
---|
[2265] | 701 |
|
---|
| 702 | if (par->type == bncParam::RECCLK) {
|
---|
| 703 | strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
|
---|
[2124] | 704 | << " +- " << setw(6) << setprecision(3)
|
---|
| 705 | << sqrt(_QQ(par->index,par->index));
|
---|
| 706 | }
|
---|
| 707 | else if (par->type == bncParam::AMB_L3) {
|
---|
[2265] | 708 | strB << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
[2124] | 709 | << setw(6) << setprecision(3) << par->xx
|
---|
| 710 | << " +- " << setw(6) << setprecision(3)
|
---|
| 711 | << sqrt(_QQ(par->index,par->index));
|
---|
| 712 | }
|
---|
[2212] | 713 | else if (par->type == bncParam::TROPO) {
|
---|
[2265] | 714 | strB << "\n trp = " << par->prn.toAscii().data()
|
---|
[2212] | 715 | << setw(7) << setprecision(3) << delay_saast(M_PI/2.0) << " "
|
---|
[2213] | 716 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
---|
[2212] | 717 | << " +- " << setw(6) << setprecision(3)
|
---|
| 718 | << sqrt(_QQ(par->index,par->index));
|
---|
| 719 | }
|
---|
[2060] | 720 | }
|
---|
[2265] | 721 | strB << '\n';
|
---|
[2060] | 722 |
|
---|
[2113] | 723 | // Message (both log file and screen)
|
---|
| 724 | // ----------------------------------
|
---|
[2265] | 725 | ostringstream strA;
|
---|
| 726 | strA.setf(ios::fixed);
|
---|
| 727 | strA << _staID.data() << ": PPP "
|
---|
[2231] | 728 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
| 729 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
| 730 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
| 731 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
| 732 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
| 733 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
[2124] | 734 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
[2113] | 735 |
|
---|
[2265] | 736 | emit newMessage(QByteArray(strA.str().c_str()), true);
|
---|
| 737 |
|
---|
| 738 | _log += strB.str().c_str();
|
---|
[2124] | 739 | emit newMessage(_log, false);
|
---|
[2113] | 740 |
|
---|
[2370] | 741 | // NEU Output
|
---|
| 742 | // ----------
|
---|
[2372] | 743 | if (settings.value("pppOrigin").toString() == "X Y Z") {
|
---|
[2370] | 744 | double xyzRef[3];
|
---|
| 745 | double ellRef[3];
|
---|
| 746 | double _xyz[3];
|
---|
| 747 | double _neu[3];
|
---|
| 748 | xyzRef[0] = settings.value("pppRefCrdX").toDouble();
|
---|
| 749 | xyzRef[1] = settings.value("pppRefCrdY").toDouble();
|
---|
| 750 | xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
|
---|
| 751 | _xyz[0] = x() - xyzRef[0];
|
---|
| 752 | _xyz[1] = y() - xyzRef[1];
|
---|
| 753 | _xyz[2] = z() - xyzRef[2];
|
---|
| 754 | xyz2ell(xyzRef, ellRef);
|
---|
| 755 | xyz2neu(ellRef, _xyz, _neu);
|
---|
| 756 | ostringstream strC;
|
---|
| 757 | strC.setf(ios::fixed);
|
---|
| 758 | strC << _staID.data() << ": NEU "
|
---|
| 759 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
| 760 | << setw(8) << setprecision(3) << _neu[0] << " "
|
---|
| 761 | << setw(8) << setprecision(3) << _neu[1] << " "
|
---|
| 762 | << setw(8) << setprecision(3) << _neu[2];
|
---|
| 763 | emit newMessage(QByteArray(strC.str().c_str()), true);
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[2131] | 766 | // NMEA Output
|
---|
| 767 | // -----------
|
---|
[2181] | 768 | double xyz[3];
|
---|
| 769 | xyz[0] = x();
|
---|
| 770 | xyz[1] = y();
|
---|
| 771 | xyz[2] = z();
|
---|
| 772 | double ell[3];
|
---|
| 773 | xyz2ell(xyz, ell);
|
---|
| 774 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
| 775 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
[2132] | 776 |
|
---|
[2181] | 777 | char phiCh = 'N';
|
---|
| 778 | if (phiDeg < 0) {
|
---|
| 779 | phiDeg = -phiDeg;
|
---|
| 780 | phiCh = 'S';
|
---|
| 781 | }
|
---|
| 782 | char lamCh = 'E';
|
---|
| 783 | if (lamDeg < 0) {
|
---|
[2406] | 784 | // lamDeg = -lamDeg; // GW, reason: RTKPlot cant handle 'W'
|
---|
| 785 | // lamCh = 'W'; // GW, reason: RTKPlot cant handle 'W'
|
---|
| 786 | lamDeg = 360. +lamDeg; // GW, reason: RTKPlot cant handle 'W'
|
---|
[2181] | 787 | }
|
---|
[2132] | 788 |
|
---|
[2181] | 789 | double dop = 2.0; // TODO
|
---|
[2133] | 790 |
|
---|
[2181] | 791 | ostringstream str3;
|
---|
| 792 | str3.setf(ios::fixed);
|
---|
| 793 | str3 << "GPGGA,"
|
---|
| 794 | << epoData->tt.timestr(0,0) << ','
|
---|
| 795 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
| 796 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 797 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
| 798 | << setw(2) << setfill('0') << int(lamDeg)
|
---|
| 799 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 800 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
[2231] | 801 | << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
|
---|
[2181] | 802 | << setw(3) << setprecision(1) << dop << ','
|
---|
| 803 | << setprecision(3) << ell[2] << ",M,0.0,M,,,";
|
---|
| 804 |
|
---|
| 805 | writeNMEAstr(QString(str3.str().c_str()));
|
---|
[2131] | 806 |
|
---|
[2060] | 807 | return success;
|
---|
| 808 | }
|
---|
[2112] | 809 |
|
---|
| 810 | // Outlier Detection
|
---|
| 811 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 812 | int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
|
---|
| 813 | const ColumnVector& vv,
|
---|
[2231] | 814 | QMap<QString, t_satData*>& satDataGPS,
|
---|
| 815 | QMap<QString, t_satData*>& satDataGlo) {
|
---|
[2112] | 816 |
|
---|
[2231] | 817 | double vvMaxCodeGPS = 0.0;
|
---|
| 818 | double vvMaxPhaseGPS = 0.0;
|
---|
| 819 | double vvMaxPhaseGlo = 0.0;
|
---|
| 820 | QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
|
---|
| 821 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
|
---|
| 822 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
|
---|
[2112] | 823 |
|
---|
| 824 | int ii = 0;
|
---|
[2231] | 825 |
|
---|
| 826 | // GPS code and (optionally) phase residuals
|
---|
| 827 | // -----------------------------------------
|
---|
| 828 | QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
|
---|
| 829 | while (itGPS.hasNext()) {
|
---|
| 830 | itGPS.next();
|
---|
[2112] | 831 | ++ii;
|
---|
| 832 |
|
---|
[2231] | 833 | if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
|
---|
| 834 | vvMaxCodeGPS = fabs(vv(ii));
|
---|
| 835 | itMaxCodeGPS = itGPS;
|
---|
[2112] | 836 | }
|
---|
| 837 |
|
---|
| 838 | if (_usePhase) {
|
---|
| 839 | ++ii;
|
---|
[2231] | 840 | if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
|
---|
| 841 | vvMaxPhaseGPS = fabs(vv(ii));
|
---|
| 842 | itMaxPhaseGPS = itGPS;
|
---|
[2112] | 843 | }
|
---|
| 844 | }
|
---|
| 845 | }
|
---|
[2231] | 846 |
|
---|
[2238] | 847 | // Glonass phase residuals
|
---|
| 848 | // -----------------------
|
---|
| 849 | if (_usePhase) {
|
---|
| 850 | QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
|
---|
| 851 | while (itGlo.hasNext()) {
|
---|
| 852 | itGlo.next();
|
---|
| 853 | ++ii;
|
---|
| 854 | if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
|
---|
| 855 | vvMaxPhaseGlo = fabs(vv(ii));
|
---|
| 856 | itMaxPhaseGlo = itGlo;
|
---|
| 857 | }
|
---|
| 858 | }
|
---|
| 859 | }
|
---|
[2112] | 860 |
|
---|
[2248] | 861 | if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
|
---|
| 862 | QString prn = itMaxPhaseGlo.key();
|
---|
| 863 | t_satData* satData = itMaxPhaseGlo.value();
|
---|
| 864 | delete satData;
|
---|
| 865 | itMaxPhaseGlo.remove();
|
---|
| 866 | _QQ = QQsav;
|
---|
| 867 |
|
---|
| 868 | _log += "\nOutlier Phase " + prn.toAscii() + " "
|
---|
| 869 | + QByteArray::number(vvMaxPhaseGlo, 'f', 3);
|
---|
| 870 |
|
---|
| 871 | return 1;
|
---|
| 872 | }
|
---|
| 873 |
|
---|
| 874 | else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
|
---|
[2231] | 875 | QString prn = itMaxCodeGPS.key();
|
---|
| 876 | t_satData* satData = itMaxCodeGPS.value();
|
---|
[2112] | 877 | delete satData;
|
---|
[2231] | 878 | itMaxCodeGPS.remove();
|
---|
[2112] | 879 | _QQ = QQsav;
|
---|
[2114] | 880 |
|
---|
[2124] | 881 | _log += "\nOutlier Code " + prn.toAscii() + " "
|
---|
[2231] | 882 | + QByteArray::number(vvMaxCodeGPS, 'f', 3);
|
---|
[2114] | 883 |
|
---|
[2112] | 884 | return 1;
|
---|
| 885 | }
|
---|
[2243] | 886 | else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
|
---|
[2231] | 887 | QString prn = itMaxPhaseGPS.key();
|
---|
| 888 | t_satData* satData = itMaxPhaseGPS.value();
|
---|
[2112] | 889 | delete satData;
|
---|
[2231] | 890 | itMaxPhaseGPS.remove();
|
---|
[2112] | 891 | _QQ = QQsav;
|
---|
[2114] | 892 |
|
---|
[2124] | 893 | _log += "\nOutlier Phase " + prn.toAscii() + " "
|
---|
[2231] | 894 | + QByteArray::number(vvMaxPhaseGPS, 'f', 3);
|
---|
[2114] | 895 |
|
---|
[2112] | 896 | return 1;
|
---|
| 897 | }
|
---|
[2231] | 898 |
|
---|
[2112] | 899 | return 0;
|
---|
| 900 | }
|
---|
[2130] | 901 |
|
---|
| 902 | //
|
---|
| 903 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 904 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
---|
| 905 |
|
---|
| 906 | unsigned char XOR = 0;
|
---|
| 907 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
| 908 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
| 909 | }
|
---|
[2181] | 910 |
|
---|
| 911 | QString outStr = '$' + nmStr
|
---|
| 912 | + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
---|
[2130] | 913 |
|
---|
[2178] | 914 | if (_nmeaStream) {
|
---|
[2181] | 915 | *_nmeaStream << outStr;
|
---|
[2178] | 916 | _nmeaStream->flush();
|
---|
| 917 | }
|
---|
[2130] | 918 |
|
---|
[2181] | 919 | emit newNMEAstr(outStr.toAscii());
|
---|
[2130] | 920 | }
|
---|
[2283] | 921 |
|
---|
| 922 |
|
---|
| 923 | ////
|
---|
| 924 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 925 | void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
|
---|
| 926 | const DiagonalMatrix& PP,
|
---|
| 927 | SymmetricMatrix& QQ, ColumnVector& dx) {
|
---|
| 928 |
|
---|
| 929 | int nObs = AA.Nrows();
|
---|
| 930 | int nPar = AA.Ncols();
|
---|
| 931 |
|
---|
| 932 | UpperTriangularMatrix SS = Cholesky(QQ).t();
|
---|
| 933 |
|
---|
| 934 | Matrix SA = SS*AA.t();
|
---|
| 935 | Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
|
---|
| 936 | for (int ii = 1; ii <= nObs; ++ii) {
|
---|
| 937 | SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
|
---|
| 941 | SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
|
---|
| 942 |
|
---|
| 943 | UpperTriangularMatrix UU;
|
---|
| 944 | QRZ(SRF, UU);
|
---|
| 945 |
|
---|
| 946 | SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
|
---|
| 947 | UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
|
---|
| 948 | Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
|
---|
| 949 |
|
---|
| 950 | UpperTriangularMatrix SHi = SH_rt.i();
|
---|
| 951 |
|
---|
| 952 | Matrix KT = SHi * YY;
|
---|
| 953 | SymmetricMatrix Hi; Hi << SHi * SHi.t();
|
---|
| 954 |
|
---|
| 955 | dx = KT.t() * ll;
|
---|
| 956 | QQ << (SS.t() * SS);
|
---|
| 957 | }
|
---|