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