[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 |
|
---|
[2113] | 55 | const unsigned MINOBS = 4;
|
---|
| 56 | const double MINELE = 10.0 * M_PI / 180.0;
|
---|
| 57 | const double MAXRES_CODE = 10.0;
|
---|
| 58 | const double MAXRES_PHASE = 0.10;
|
---|
| 59 | const double sig_crd_0 = 100.0;
|
---|
| 60 | const double sig_crd_p = 100.0;
|
---|
| 61 | const double sig_clk_0 = 1000.0;
|
---|
| 62 | const double sig_trp_0 = 0.01;
|
---|
| 63 | const double sig_trp_p = 1e-6;
|
---|
| 64 | const double sig_amb_0 = 100.0;
|
---|
| 65 | const double sig_P3 = 1.0;
|
---|
| 66 | const double sig_L3 = 0.01;
|
---|
[2070] | 67 |
|
---|
[2057] | 68 | // Constructor
|
---|
| 69 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 70 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
| 71 | const QString& prnIn) {
|
---|
| 72 | type = typeIn;
|
---|
| 73 | index = indexIn;
|
---|
| 74 | prn = prnIn;
|
---|
| 75 | index_old = 0;
|
---|
| 76 | xx = 0.0;
|
---|
[2057] | 77 | }
|
---|
| 78 |
|
---|
| 79 | // Destructor
|
---|
| 80 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 81 | bncParam::~bncParam() {
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[2060] | 84 | // Partial
|
---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 86 | double bncParam::partial(t_satData* satData, const QString& prnIn) {
|
---|
[2060] | 87 | if (type == CRD_X) {
|
---|
[2109] | 88 | return (xx - satData->xx(1)) / satData->rho;
|
---|
[2060] | 89 | }
|
---|
| 90 | else if (type == CRD_Y) {
|
---|
[2109] | 91 | return (xx - satData->xx(2)) / satData->rho;
|
---|
[2060] | 92 | }
|
---|
| 93 | else if (type == CRD_Z) {
|
---|
[2109] | 94 | return (xx - satData->xx(3)) / satData->rho;
|
---|
[2060] | 95 | }
|
---|
| 96 | else if (type == RECCLK) {
|
---|
| 97 | return 1.0;
|
---|
| 98 | }
|
---|
[2084] | 99 | else if (type == TROPO) {
|
---|
| 100 | return 1.0 / sin(satData->eleSat);
|
---|
| 101 | }
|
---|
[2080] | 102 | else if (type == AMB_L3) {
|
---|
| 103 | if (prnIn == prn) {
|
---|
| 104 | return 1.0;
|
---|
| 105 | }
|
---|
| 106 | else {
|
---|
| 107 | return 0.0;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
[2060] | 110 | return 0.0;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[2058] | 113 | // Constructor
|
---|
| 114 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2113] | 115 | bncModel::bncModel(QByteArray staID) {
|
---|
[2084] | 116 |
|
---|
[2113] | 117 | _staID = staID;
|
---|
| 118 |
|
---|
| 119 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 120 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 121 |
|
---|
[2084] | 122 | bncSettings settings;
|
---|
| 123 |
|
---|
| 124 | _static = false;
|
---|
| 125 | if ( Qt::CheckState(settings.value("pppStatic").toInt()) == Qt::Checked) {
|
---|
| 126 | _static = true;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | _usePhase = false;
|
---|
| 130 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
|
---|
| 131 | _usePhase = true;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | _estTropo = false;
|
---|
| 135 | if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
|
---|
| 136 | _estTropo = true;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | _xcBanc.ReSize(4); _xcBanc = 0.0;
|
---|
| 140 | _ellBanc.ReSize(3); _ellBanc = 0.0;
|
---|
| 141 |
|
---|
[2080] | 142 | _params.push_back(new bncParam(bncParam::CRD_X, 1, ""));
|
---|
| 143 | _params.push_back(new bncParam(bncParam::CRD_Y, 2, ""));
|
---|
| 144 | _params.push_back(new bncParam(bncParam::CRD_Z, 3, ""));
|
---|
| 145 | _params.push_back(new bncParam(bncParam::RECCLK, 4, ""));
|
---|
[2084] | 146 | if (_estTropo) {
|
---|
| 147 | _params.push_back(new bncParam(bncParam::TROPO, 5, ""));
|
---|
| 148 | }
|
---|
[2073] | 149 |
|
---|
| 150 | unsigned nPar = _params.size();
|
---|
[2084] | 151 |
|
---|
[2073] | 152 | _QQ.ReSize(nPar);
|
---|
| 153 | _QQ = 0.0;
|
---|
| 154 |
|
---|
| 155 | _QQ(1,1) = sig_crd_0 * sig_crd_0;
|
---|
| 156 | _QQ(2,2) = sig_crd_0 * sig_crd_0;
|
---|
| 157 | _QQ(3,3) = sig_crd_0 * sig_crd_0;
|
---|
| 158 | _QQ(4,4) = sig_clk_0 * sig_clk_0;
|
---|
[2084] | 159 | if (_estTropo) {
|
---|
| 160 | _QQ(5,5) = sig_trp_0 * sig_trp_0;
|
---|
[2077] | 161 | }
|
---|
[2125] | 162 |
|
---|
| 163 | // NMEA Output
|
---|
| 164 | // -----------
|
---|
| 165 | QString nmeaFileName = settings.value("nmeaFile").toString();
|
---|
| 166 | if (nmeaFileName.isEmpty()) {
|
---|
| 167 | _nmeaFile = 0;
|
---|
| 168 | _nmeaStream = 0;
|
---|
| 169 | }
|
---|
| 170 | else {
|
---|
| 171 | expandEnvVar(nmeaFileName);
|
---|
| 172 | _nmeaFile = new QFile(nmeaFileName);
|
---|
| 173 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 174 | _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 175 | }
|
---|
| 176 | else {
|
---|
| 177 | _nmeaFile->open(QIODevice::WriteOnly);
|
---|
| 178 | }
|
---|
| 179 | _nmeaStream = new QTextStream();
|
---|
| 180 | _nmeaStream->setDevice(_nmeaFile);
|
---|
[2130] | 181 | QDateTime dateTime = QDateTime::currentDateTime().toUTC();
|
---|
| 182 | QString nmStr = "GPRMC," + dateTime.time().toString("hhmmss")
|
---|
[2134] | 183 | + ",A,0000.0000000,N,00000.0000000,E,0.00,0.00,"
|
---|
[2130] | 184 | + dateTime.date().toString("ddMMyy")
|
---|
| 185 | + ",0.0,E";
|
---|
| 186 |
|
---|
| 187 | writeNMEAstr(nmStr);
|
---|
[2125] | 188 | }
|
---|
[2058] | 189 | }
|
---|
| 190 |
|
---|
| 191 | // Destructor
|
---|
| 192 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 193 | bncModel::~bncModel() {
|
---|
[2126] | 194 | delete _nmeaStream;
|
---|
| 195 | delete _nmeaFile;
|
---|
[2058] | 196 | }
|
---|
| 197 |
|
---|
| 198 | // Bancroft Solution
|
---|
| 199 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 200 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
---|
| 201 |
|
---|
| 202 | if (epoData->size() < MINOBS) {
|
---|
[2124] | 203 | _log += "\nNot enough data";
|
---|
[2058] | 204 | return failure;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | Matrix BB(epoData->size(), 4);
|
---|
| 208 |
|
---|
| 209 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 210 | int iObs = 0;
|
---|
| 211 | while (it.hasNext()) {
|
---|
[2060] | 212 | ++iObs;
|
---|
[2058] | 213 | it.next();
|
---|
| 214 | QString prn = it.key();
|
---|
| 215 | t_satData* satData = it.value();
|
---|
| 216 | BB(iObs, 1) = satData->xx(1);
|
---|
| 217 | BB(iObs, 2) = satData->xx(2);
|
---|
| 218 | BB(iObs, 3) = satData->xx(3);
|
---|
| 219 | BB(iObs, 4) = satData->P3 + satData->clk;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | bancroft(BB, _xcBanc);
|
---|
| 223 |
|
---|
[2064] | 224 | // Ellipsoidal Coordinates
|
---|
| 225 | // ------------------------
|
---|
| 226 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
---|
[2063] | 227 |
|
---|
[2064] | 228 | // Compute Satellite Elevations
|
---|
| 229 | // ----------------------------
|
---|
| 230 | QMutableMapIterator<QString, t_satData*> it2(epoData->satData);
|
---|
| 231 | while (it2.hasNext()) {
|
---|
| 232 | it2.next();
|
---|
| 233 | QString prn = it2.key();
|
---|
| 234 | t_satData* satData = it2.value();
|
---|
[2063] | 235 |
|
---|
[2109] | 236 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 237 | double rho = rr.norm_Frobenius();
|
---|
[2064] | 238 |
|
---|
| 239 | double neu[3];
|
---|
[2109] | 240 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
[2064] | 241 |
|
---|
| 242 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 243 | if (neu[2] < 0) {
|
---|
| 244 | satData->eleSat *= -1.0;
|
---|
| 245 | }
|
---|
| 246 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
[2070] | 247 |
|
---|
| 248 | if (satData->eleSat < MINELE) {
|
---|
| 249 | delete satData;
|
---|
| 250 | it2.remove();
|
---|
| 251 | }
|
---|
[2064] | 252 | }
|
---|
| 253 |
|
---|
[2058] | 254 | return success;
|
---|
| 255 | }
|
---|
[2060] | 256 |
|
---|
| 257 | // Computed Value
|
---|
| 258 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 259 | double bncModel::cmpValue(t_satData* satData) {
|
---|
[2060] | 260 |
|
---|
[2073] | 261 | ColumnVector xRec(3);
|
---|
| 262 | xRec(1) = x();
|
---|
| 263 | xRec(2) = y();
|
---|
| 264 | xRec(3) = z();
|
---|
[2060] | 265 |
|
---|
[2073] | 266 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
---|
[2060] | 267 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
---|
| 268 |
|
---|
[2073] | 269 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
---|
| 270 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
---|
| 271 | xRec(3) = z();
|
---|
| 272 |
|
---|
[2060] | 273 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
---|
| 274 |
|
---|
[2084] | 275 | double tropDelay = delay_saast(satData->eleSat) +
|
---|
| 276 | trp() / sin(satData->eleSat);
|
---|
[2060] | 277 |
|
---|
[2073] | 278 | return satData->rho + clk() - satData->clk + tropDelay;
|
---|
[2060] | 279 | }
|
---|
| 280 |
|
---|
[2063] | 281 | // Tropospheric Model (Saastamoinen)
|
---|
| 282 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2065] | 283 | double bncModel::delay_saast(double Ele) {
|
---|
[2063] | 284 |
|
---|
[2064] | 285 | double height = _ellBanc(3);
|
---|
[2063] | 286 |
|
---|
[2064] | 287 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
---|
| 288 | double TT = 18.0 - height * 0.0065 + 273.15;
|
---|
| 289 | double hh = 50.0 * exp(-6.396e-4 * height);
|
---|
[2063] | 290 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
---|
| 291 |
|
---|
[2064] | 292 | double h_km = height / 1000.0;
|
---|
[2063] | 293 |
|
---|
| 294 | if (h_km < 0.0) h_km = 0.0;
|
---|
| 295 | if (h_km > 5.0) h_km = 5.0;
|
---|
| 296 | int ii = int(h_km + 1);
|
---|
| 297 | double href = ii - 1;
|
---|
| 298 |
|
---|
| 299 | double bCor[6];
|
---|
| 300 | bCor[0] = 1.156;
|
---|
| 301 | bCor[1] = 1.006;
|
---|
| 302 | bCor[2] = 0.874;
|
---|
| 303 | bCor[3] = 0.757;
|
---|
| 304 | bCor[4] = 0.654;
|
---|
| 305 | bCor[5] = 0.563;
|
---|
| 306 |
|
---|
| 307 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
---|
| 308 |
|
---|
| 309 | double zen = M_PI/2.0 - Ele;
|
---|
| 310 |
|
---|
| 311 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[2073] | 314 | // Prediction Step of the Filter
|
---|
| 315 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2080] | 316 | void bncModel::predict(t_epoData* epoData) {
|
---|
[2073] | 317 |
|
---|
[2083] | 318 | if (_usePhase) {
|
---|
[2080] | 319 |
|
---|
[2083] | 320 | // Make a copy of QQ and xx, set parameter indices
|
---|
| 321 | // -----------------------------------------------
|
---|
| 322 | SymmetricMatrix QQ_old = _QQ;
|
---|
| 323 |
|
---|
| 324 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 325 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
---|
| 326 | _params[iPar-1]->index = 0;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | // Remove Ambiguity Parameters without observations
|
---|
| 330 | // ------------------------------------------------
|
---|
| 331 | int iPar = 0;
|
---|
| 332 | QMutableVectorIterator<bncParam*> it(_params);
|
---|
| 333 | while (it.hasNext()) {
|
---|
| 334 | bncParam* par = it.next();
|
---|
| 335 | bool removed = false;
|
---|
| 336 | if (par->type == bncParam::AMB_L3) {
|
---|
| 337 | if (epoData->satData.find(par->prn) == epoData->satData.end()) {
|
---|
| 338 | removed = true;
|
---|
| 339 | delete par;
|
---|
| 340 | it.remove();
|
---|
| 341 | }
|
---|
[2080] | 342 | }
|
---|
[2083] | 343 | if (! removed) {
|
---|
| 344 | ++iPar;
|
---|
| 345 | par->index = iPar;
|
---|
| 346 | }
|
---|
[2080] | 347 | }
|
---|
[2083] | 348 |
|
---|
| 349 | // Add new ambiguity parameters
|
---|
| 350 | // ----------------------------
|
---|
| 351 | QMapIterator<QString, t_satData*> itObs(epoData->satData);
|
---|
| 352 | while (itObs.hasNext()) {
|
---|
| 353 | itObs.next();
|
---|
| 354 | QString prn = itObs.key();
|
---|
| 355 | bool found = false;
|
---|
| 356 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 357 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 358 | _params[iPar-1]->prn == prn) {
|
---|
| 359 | found = true;
|
---|
| 360 | break;
|
---|
| 361 | }
|
---|
[2080] | 362 | }
|
---|
[2083] | 363 | if (!found) {
|
---|
| 364 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
| 365 | _params.push_back(par);
|
---|
| 366 | }
|
---|
[2080] | 367 | }
|
---|
[2083] | 368 |
|
---|
| 369 | int nPar = _params.size();
|
---|
| 370 | _QQ.ReSize(nPar); _QQ = 0.0;
|
---|
| 371 | for (int i1 = 1; i1 <= nPar; i1++) {
|
---|
| 372 | bncParam* p1 = _params[i1-1];
|
---|
| 373 | if (p1->index_old != 0) {
|
---|
| 374 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
---|
| 375 | for (int i2 = 1; i2 <= nPar; i2++) {
|
---|
| 376 | bncParam* p2 = _params[i2-1];
|
---|
| 377 | if (p2->index_old != 0) {
|
---|
| 378 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
---|
| 379 | }
|
---|
[2080] | 380 | }
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
[2083] | 383 |
|
---|
| 384 | for (int ii = 1; ii <= nPar; ii++) {
|
---|
| 385 | bncParam* par = _params[ii-1];
|
---|
| 386 | if (par->index_old == 0) {
|
---|
| 387 | _QQ(par->index, par->index) = sig_amb_0 * sig_amb_0;
|
---|
| 388 | }
|
---|
| 389 | par->index_old = par->index;
|
---|
[2080] | 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[2076] | 393 | // Coordinates
|
---|
| 394 | // -----------
|
---|
| 395 | if (_static) {
|
---|
| 396 | if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
|
---|
[2109] | 397 | _params[0]->xx = _xcBanc(1);
|
---|
| 398 | _params[1]->xx = _xcBanc(2);
|
---|
| 399 | _params[2]->xx = _xcBanc(3);
|
---|
[2076] | 400 | }
|
---|
| 401 | }
|
---|
| 402 | else {
|
---|
[2109] | 403 | _params[0]->xx = _xcBanc(1);
|
---|
| 404 | _params[1]->xx = _xcBanc(2);
|
---|
| 405 | _params[2]->xx = _xcBanc(3);
|
---|
[2073] | 406 |
|
---|
[2076] | 407 | _QQ(1,1) += sig_crd_p * sig_crd_p;
|
---|
| 408 | _QQ(2,2) += sig_crd_p * sig_crd_p;
|
---|
| 409 | _QQ(3,3) += sig_crd_p * sig_crd_p;
|
---|
| 410 | }
|
---|
[2073] | 411 |
|
---|
[2076] | 412 | // Receiver Clocks
|
---|
| 413 | // ---------------
|
---|
[2109] | 414 | _params[3]->xx = _xcBanc(4);
|
---|
[2073] | 415 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 416 | _QQ(iPar, 4) = 0.0;
|
---|
| 417 | }
|
---|
| 418 | _QQ(4,4) = sig_clk_0 * sig_clk_0;
|
---|
| 419 |
|
---|
[2084] | 420 | // Tropospheric Delay
|
---|
| 421 | // ------------------
|
---|
| 422 | if (_estTropo) {
|
---|
| 423 | _QQ(5,5) += sig_trp_p * sig_trp_p;
|
---|
| 424 | }
|
---|
[2073] | 425 | }
|
---|
| 426 |
|
---|
[2060] | 427 | // Update Step of the Filter (currently just a single-epoch solution)
|
---|
| 428 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 429 | t_irc bncModel::update(t_epoData* epoData) {
|
---|
| 430 |
|
---|
[2124] | 431 | _log = "Precise Point Positioning";
|
---|
| 432 |
|
---|
[2143] | 433 | _time = epoData->tt;
|
---|
| 434 |
|
---|
[2112] | 435 | SymmetricMatrix QQsav;
|
---|
[2109] | 436 | ColumnVector dx;
|
---|
[2112] | 437 | ColumnVector vv;
|
---|
[2073] | 438 |
|
---|
[2113] | 439 | // Loop over all outliers
|
---|
| 440 | // ----------------------
|
---|
[2108] | 441 | do {
|
---|
| 442 |
|
---|
| 443 | // Bancroft Solution
|
---|
| 444 | // -----------------
|
---|
| 445 | if (cmpBancroft(epoData) != success) {
|
---|
[2124] | 446 | _log += "\nBancroft failed";
|
---|
| 447 | emit newMessage(_log, false);
|
---|
[2108] | 448 | return failure;
|
---|
| 449 | }
|
---|
[2080] | 450 |
|
---|
[2116] | 451 | if (epoData->size() < MINOBS) {
|
---|
[2124] | 452 | _log += "\nNot enough data";
|
---|
| 453 | emit newMessage(_log, false);
|
---|
[2116] | 454 | return failure;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
[2108] | 457 | // Status Prediction
|
---|
| 458 | // -----------------
|
---|
| 459 | predict(epoData);
|
---|
| 460 |
|
---|
[2109] | 461 | // Create First-Design Matrix
|
---|
| 462 | // --------------------------
|
---|
[2108] | 463 | unsigned nPar = _params.size();
|
---|
| 464 | unsigned nObs = _usePhase ? 2 * epoData->size() : epoData->size();
|
---|
| 465 |
|
---|
| 466 | Matrix AA(nObs, nPar); // first design matrix
|
---|
| 467 | ColumnVector ll(nObs); // tems observed-computed
|
---|
| 468 | SymmetricMatrix PP(nObs); PP = 0.0;
|
---|
| 469 |
|
---|
| 470 | unsigned iObs = 0;
|
---|
| 471 | QMapIterator<QString, t_satData*> itObs(epoData->satData);
|
---|
| 472 | while (itObs.hasNext()) {
|
---|
[2083] | 473 | ++iObs;
|
---|
[2108] | 474 | itObs.next();
|
---|
| 475 | QString prn = itObs.key();
|
---|
| 476 | t_satData* satData = itObs.value();
|
---|
| 477 |
|
---|
| 478 | double rhoCmp = cmpValue(satData);
|
---|
| 479 |
|
---|
[2117] | 480 | double ellWgtCoeff = 1.0;
|
---|
[2118] | 481 | //// double eleD = satData->eleSat * 180.0 / M_PI;
|
---|
| 482 | //// if (eleD < 25.0) {
|
---|
| 483 | //// ellWgtCoeff = 2.5 - (eleD - 10.0) * 0.1;
|
---|
| 484 | //// ellWgtCoeff *= ellWgtCoeff;
|
---|
| 485 | //// }
|
---|
[2117] | 486 |
|
---|
[2108] | 487 | ll(iObs) = satData->P3 - rhoCmp;
|
---|
[2117] | 488 | PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3) / ellWgtCoeff;
|
---|
[2083] | 489 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
[2108] | 490 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, "");
|
---|
[2083] | 491 | }
|
---|
[2108] | 492 |
|
---|
| 493 | if (_usePhase) {
|
---|
| 494 | ++iObs;
|
---|
| 495 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
[2117] | 496 | PP(iObs,iObs) = 1.0 / (sig_L3 * sig_L3) / ellWgtCoeff;
|
---|
[2108] | 497 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 498 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 499 | _params[iPar-1]->prn == prn) {
|
---|
[2109] | 500 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
[2108] | 501 | }
|
---|
| 502 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, prn);
|
---|
| 503 | }
|
---|
| 504 | }
|
---|
[2080] | 505 | }
|
---|
[2108] | 506 |
|
---|
[2112] | 507 | // Compute Filter Update
|
---|
[2108] | 508 | // ---------------------
|
---|
[2112] | 509 | QQsav = _QQ;
|
---|
| 510 |
|
---|
| 511 | Matrix ATP = AA.t() * PP;
|
---|
[2109] | 512 | SymmetricMatrix NN = _QQ.i();
|
---|
[2112] | 513 | NN << NN + ATP * AA;
|
---|
| 514 | _QQ = NN.i();
|
---|
| 515 | dx = _QQ * ATP * ll;
|
---|
| 516 | vv = ll - AA * dx;
|
---|
[2060] | 517 |
|
---|
[2112] | 518 | } while (outlierDetection(QQsav, vv, epoData->satData) != 0);
|
---|
[2111] | 519 |
|
---|
[2109] | 520 | // Set Solution Vector
|
---|
| 521 | // -------------------
|
---|
[2124] | 522 | ostringstream str1;
|
---|
| 523 | str1.setf(ios::fixed);
|
---|
[2073] | 524 | QVectorIterator<bncParam*> itPar(_params);
|
---|
[2060] | 525 | while (itPar.hasNext()) {
|
---|
| 526 | bncParam* par = itPar.next();
|
---|
[2109] | 527 | par->xx += dx(par->index);
|
---|
[2124] | 528 | if (par->type == bncParam::RECCLK) {
|
---|
| 529 | str1 << "\n clk = " << setw(6) << setprecision(3) << par->xx
|
---|
| 530 | << " +- " << setw(6) << setprecision(3)
|
---|
| 531 | << sqrt(_QQ(par->index,par->index));
|
---|
| 532 | }
|
---|
| 533 | else if (par->type == bncParam::AMB_L3) {
|
---|
| 534 | str1 << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
| 535 | << setw(6) << setprecision(3) << par->xx
|
---|
| 536 | << " +- " << setw(6) << setprecision(3)
|
---|
| 537 | << sqrt(_QQ(par->index,par->index));
|
---|
| 538 | }
|
---|
[2060] | 539 | }
|
---|
[2124] | 540 | _log += str1.str().c_str();
|
---|
[2060] | 541 |
|
---|
[2113] | 542 | // Message (both log file and screen)
|
---|
| 543 | // ----------------------------------
|
---|
[2124] | 544 | ostringstream str2;
|
---|
| 545 | str2.setf(ios::fixed);
|
---|
[2165] | 546 | str2 << _staID.data() << ": PPP "
|
---|
[2124] | 547 | << epoData->tt.timestr(1) << " " << epoData->size() << " "
|
---|
| 548 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
| 549 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
| 550 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
| 551 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
| 552 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
| 553 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
[2114] | 554 | if (_estTropo) {
|
---|
[2124] | 555 | str2 << " " << setw(6) << setprecision(3) << trp() << " +- "
|
---|
| 556 | << setw(6) << setprecision(3) << sqrt(_QQ(5,5));
|
---|
[2114] | 557 | }
|
---|
[2113] | 558 |
|
---|
[2124] | 559 | emit newMessage(_log, false);
|
---|
| 560 | emit newMessage(QByteArray(str2.str().c_str()), true);
|
---|
[2113] | 561 |
|
---|
[2131] | 562 | // NMEA Output
|
---|
| 563 | // -----------
|
---|
| 564 | if (_nmeaStream) {
|
---|
[2132] | 565 | double xyz[3];
|
---|
| 566 | xyz[0] = x();
|
---|
| 567 | xyz[1] = y();
|
---|
| 568 | xyz[2] = z();
|
---|
| 569 | double ell[3];
|
---|
| 570 | xyz2ell(xyz, ell);
|
---|
| 571 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
| 572 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
| 573 |
|
---|
| 574 | char phiCh = 'N';
|
---|
| 575 | if (phiDeg < 0) {
|
---|
| 576 | phiDeg = -phiDeg;
|
---|
| 577 | phiCh = 'S';
|
---|
| 578 | }
|
---|
| 579 | char lamCh = 'E';
|
---|
| 580 | if (lamDeg < 0) {
|
---|
| 581 | lamDeg = -lamDeg;
|
---|
| 582 | lamCh = 'W';
|
---|
| 583 | }
|
---|
| 584 |
|
---|
[2133] | 585 | double dop = 2.0; // TODO
|
---|
| 586 |
|
---|
[2131] | 587 | ostringstream str3;
|
---|
| 588 | str3.setf(ios::fixed);
|
---|
[2132] | 589 | str3 << "GPGGA,"
|
---|
| 590 | << epoData->tt.timestr(0,0) << ','
|
---|
| 591 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
| 592 | << setw(10) << setprecision(7) << setfill('0')
|
---|
| 593 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
| 594 | << setw(2) << setfill('0') << int(lamDeg)
|
---|
| 595 | << setw(10) << setprecision(7) << setfill('0')
|
---|
[2133] | 596 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
| 597 | << ",1," << setw(2) << setfill('0') << epoData->size() << ','
|
---|
| 598 | << setw(3) << setprecision(1) << dop << ','
|
---|
| 599 | << setprecision(3) << ell[2] << ",M,0.0,M,,,";
|
---|
[2131] | 600 |
|
---|
| 601 | writeNMEAstr(QString(str3.str().c_str()));
|
---|
| 602 | }
|
---|
| 603 |
|
---|
[2060] | 604 | return success;
|
---|
| 605 | }
|
---|
[2112] | 606 |
|
---|
| 607 | // Outlier Detection
|
---|
| 608 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 609 | int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
|
---|
| 610 | const ColumnVector& vv,
|
---|
| 611 | QMap<QString, t_satData*>& satData) {
|
---|
| 612 |
|
---|
| 613 | double vvMaxCode = 0.0;
|
---|
| 614 | double vvMaxPhase = 0.0;
|
---|
| 615 | QMutableMapIterator<QString, t_satData*> itMaxCode(satData);
|
---|
| 616 | QMutableMapIterator<QString, t_satData*> itMaxPhase(satData);
|
---|
| 617 |
|
---|
| 618 | int ii = 0;
|
---|
| 619 | QMutableMapIterator<QString, t_satData*> it(satData);
|
---|
| 620 | while (it.hasNext()) {
|
---|
| 621 | it.next();
|
---|
| 622 | ++ii;
|
---|
| 623 |
|
---|
| 624 | if (vvMaxCode == 0.0 || fabs(vv(ii)) > vvMaxCode) {
|
---|
| 625 | vvMaxCode = fabs(vv(ii));
|
---|
| 626 | itMaxCode = it;
|
---|
| 627 | }
|
---|
| 628 |
|
---|
| 629 | if (_usePhase) {
|
---|
| 630 | ++ii;
|
---|
| 631 | if (vvMaxPhase == 0.0 || fabs(vv(ii)) > vvMaxPhase) {
|
---|
| 632 | vvMaxPhase = fabs(vv(ii));
|
---|
| 633 | itMaxPhase = it;
|
---|
| 634 | }
|
---|
| 635 | }
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | if (vvMaxCode > MAXRES_CODE) {
|
---|
| 639 | QString prn = itMaxCode.key();
|
---|
| 640 | t_satData* satData = itMaxCode.value();
|
---|
| 641 | delete satData;
|
---|
| 642 | itMaxCode.remove();
|
---|
| 643 | _QQ = QQsav;
|
---|
[2114] | 644 |
|
---|
[2124] | 645 | _log += "\nOutlier Code " + prn.toAscii() + " "
|
---|
| 646 | + QByteArray::number(vvMaxCode, 'f', 3);
|
---|
[2114] | 647 |
|
---|
[2112] | 648 | return 1;
|
---|
| 649 | }
|
---|
| 650 | else if (vvMaxPhase > MAXRES_PHASE) {
|
---|
| 651 | QString prn = itMaxPhase.key();
|
---|
| 652 | t_satData* satData = itMaxPhase.value();
|
---|
| 653 | delete satData;
|
---|
| 654 | itMaxPhase.remove();
|
---|
| 655 | _QQ = QQsav;
|
---|
[2114] | 656 |
|
---|
[2124] | 657 | _log += "\nOutlier Phase " + prn.toAscii() + " "
|
---|
| 658 | + QByteArray::number(vvMaxPhase, 'f', 3);
|
---|
[2114] | 659 |
|
---|
[2112] | 660 | return 1;
|
---|
| 661 | }
|
---|
| 662 |
|
---|
| 663 | return 0;
|
---|
| 664 | }
|
---|
[2130] | 665 |
|
---|
| 666 | //
|
---|
| 667 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 668 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
---|
| 669 |
|
---|
| 670 | if (!_nmeaStream) {
|
---|
| 671 | return;
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | unsigned char XOR = 0;
|
---|
| 675 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
| 676 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
| 677 | }
|
---|
| 678 |
|
---|
| 679 | *_nmeaStream << '$' << nmStr << '*' << hex << (int) XOR << endl;
|
---|
| 680 |
|
---|
| 681 | _nmeaStream->flush();
|
---|
| 682 | }
|
---|