| 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>
|
|---|
| 42 | #include <cmath>
|
|---|
| 43 | #include <newmatio.h>
|
|---|
| 44 | #include <sstream>
|
|---|
| 45 |
|
|---|
| 46 | #include "bncmodel.h"
|
|---|
| 47 | #include "bncapp.h"
|
|---|
| 48 | #include "bncpppclient.h"
|
|---|
| 49 | #include "bancroft.h"
|
|---|
| 50 | #include "bncutils.h"
|
|---|
| 51 | #include "bncsettings.h"
|
|---|
| 52 |
|
|---|
| 53 | using namespace std;
|
|---|
| 54 |
|
|---|
| 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;
|
|---|
| 67 |
|
|---|
| 68 | // Constructor
|
|---|
| 69 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 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;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | // Destructor
|
|---|
| 80 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 81 | bncParam::~bncParam() {
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | // Partial
|
|---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 86 | double bncParam::partial(t_satData* satData, const QString& prnIn) {
|
|---|
| 87 | if (type == CRD_X) {
|
|---|
| 88 | return (xx - satData->xx(1)) / satData->rho;
|
|---|
| 89 | }
|
|---|
| 90 | else if (type == CRD_Y) {
|
|---|
| 91 | return (xx - satData->xx(2)) / satData->rho;
|
|---|
| 92 | }
|
|---|
| 93 | else if (type == CRD_Z) {
|
|---|
| 94 | return (xx - satData->xx(3)) / satData->rho;
|
|---|
| 95 | }
|
|---|
| 96 | else if (type == RECCLK) {
|
|---|
| 97 | return 1.0;
|
|---|
| 98 | }
|
|---|
| 99 | else if (type == TROPO) {
|
|---|
| 100 | return 1.0 / sin(satData->eleSat);
|
|---|
| 101 | }
|
|---|
| 102 | else if (type == AMB_L3) {
|
|---|
| 103 | if (prnIn == prn) {
|
|---|
| 104 | return 1.0;
|
|---|
| 105 | }
|
|---|
| 106 | else {
|
|---|
| 107 | return 0.0;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | return 0.0;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | // Constructor
|
|---|
| 114 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 115 | bncModel::bncModel(QByteArray staID) {
|
|---|
| 116 |
|
|---|
| 117 | _staID = staID;
|
|---|
| 118 |
|
|---|
| 119 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 120 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
|---|
| 121 |
|
|---|
| 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 |
|
|---|
| 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, ""));
|
|---|
| 146 | if (_estTropo) {
|
|---|
| 147 | _params.push_back(new bncParam(bncParam::TROPO, 5, ""));
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | unsigned nPar = _params.size();
|
|---|
| 151 |
|
|---|
| 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;
|
|---|
| 159 | if (_estTropo) {
|
|---|
| 160 | _QQ(5,5) = sig_trp_0 * sig_trp_0;
|
|---|
| 161 | }
|
|---|
| 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);
|
|---|
| 181 | QDateTime dateTime = QDateTime::currentDateTime().toUTC();
|
|---|
| 182 | QString nmStr = "GPRMC," + dateTime.time().toString("hhmmss")
|
|---|
| 183 | + ",A,,,,,,,"
|
|---|
| 184 | + dateTime.date().toString("ddMMyy")
|
|---|
| 185 | + ",,";
|
|---|
| 186 |
|
|---|
| 187 | writeNMEAstr(nmStr);
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | // Destructor
|
|---|
| 192 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 193 | bncModel::~bncModel() {
|
|---|
| 194 | delete _nmeaStream;
|
|---|
| 195 | delete _nmeaFile;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | // Bancroft Solution
|
|---|
| 199 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 200 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
|---|
| 201 |
|
|---|
| 202 | if (epoData->sizeGPS() < MINOBS) {
|
|---|
| 203 | _log += "\nNot enough data";
|
|---|
| 204 | return failure;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | Matrix BB(epoData->sizeGPS(), 4);
|
|---|
| 208 |
|
|---|
| 209 | QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
|
|---|
| 210 | int iObs = 0;
|
|---|
| 211 | while (it.hasNext()) {
|
|---|
| 212 | ++iObs;
|
|---|
| 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 |
|
|---|
| 224 | // Ellipsoidal Coordinates
|
|---|
| 225 | // ------------------------
|
|---|
| 226 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
|---|
| 227 |
|
|---|
| 228 | // Compute Satellite Elevations
|
|---|
| 229 | // ----------------------------
|
|---|
| 230 | QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
|---|
| 231 | while (iGPS.hasNext()) {
|
|---|
| 232 | iGPS.next();
|
|---|
| 233 | QString prn = iGPS.key();
|
|---|
| 234 | t_satData* satData = iGPS.value();
|
|---|
| 235 |
|
|---|
| 236 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
|---|
| 237 | double rho = rr.norm_Frobenius();
|
|---|
| 238 |
|
|---|
| 239 | double neu[3];
|
|---|
| 240 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
|---|
| 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]);
|
|---|
| 247 |
|
|---|
| 248 | if (satData->eleSat < MINELE) {
|
|---|
| 249 | delete satData;
|
|---|
| 250 | iGPS.remove();
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
|---|
| 255 | while (iGlo.hasNext()) {
|
|---|
| 256 | iGlo.next();
|
|---|
| 257 | QString prn = iGlo.key();
|
|---|
| 258 | t_satData* satData = iGlo.value();
|
|---|
| 259 |
|
|---|
| 260 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
|---|
| 261 | double rho = rr.norm_Frobenius();
|
|---|
| 262 |
|
|---|
| 263 | double neu[3];
|
|---|
| 264 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
|---|
| 265 |
|
|---|
| 266 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
|---|
| 267 | if (neu[2] < 0) {
|
|---|
| 268 | satData->eleSat *= -1.0;
|
|---|
| 269 | }
|
|---|
| 270 | satData->azSat = atan2(neu[1], neu[0]);
|
|---|
| 271 |
|
|---|
| 272 | if (satData->eleSat < MINELE) {
|
|---|
| 273 | delete satData;
|
|---|
| 274 | iGlo.remove();
|
|---|
| 275 | }
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | return success;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | // Computed Value
|
|---|
| 282 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 283 | double bncModel::cmpValue(t_satData* satData) {
|
|---|
| 284 |
|
|---|
| 285 | ColumnVector xRec(3);
|
|---|
| 286 | xRec(1) = x();
|
|---|
| 287 | xRec(2) = y();
|
|---|
| 288 | xRec(3) = z();
|
|---|
| 289 |
|
|---|
| 290 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
|---|
| 291 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
|---|
| 292 |
|
|---|
| 293 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
|---|
| 294 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
|---|
| 295 | xRec(3) = z();
|
|---|
| 296 |
|
|---|
| 297 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
|---|
| 298 |
|
|---|
| 299 | double tropDelay = delay_saast(satData->eleSat) +
|
|---|
| 300 | trp() / sin(satData->eleSat);
|
|---|
| 301 |
|
|---|
| 302 | return satData->rho + clk() - satData->clk + tropDelay;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | // Tropospheric Model (Saastamoinen)
|
|---|
| 306 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 307 | double bncModel::delay_saast(double Ele) {
|
|---|
| 308 |
|
|---|
| 309 | double height = _ellBanc(3);
|
|---|
| 310 |
|
|---|
| 311 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
|---|
| 312 | double TT = 18.0 - height * 0.0065 + 273.15;
|
|---|
| 313 | double hh = 50.0 * exp(-6.396e-4 * height);
|
|---|
| 314 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
|---|
| 315 |
|
|---|
| 316 | double h_km = height / 1000.0;
|
|---|
| 317 |
|
|---|
| 318 | if (h_km < 0.0) h_km = 0.0;
|
|---|
| 319 | if (h_km > 5.0) h_km = 5.0;
|
|---|
| 320 | int ii = int(h_km + 1);
|
|---|
| 321 | double href = ii - 1;
|
|---|
| 322 |
|
|---|
| 323 | double bCor[6];
|
|---|
| 324 | bCor[0] = 1.156;
|
|---|
| 325 | bCor[1] = 1.006;
|
|---|
| 326 | bCor[2] = 0.874;
|
|---|
| 327 | bCor[3] = 0.757;
|
|---|
| 328 | bCor[4] = 0.654;
|
|---|
| 329 | bCor[5] = 0.563;
|
|---|
| 330 |
|
|---|
| 331 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
|---|
| 332 |
|
|---|
| 333 | double zen = M_PI/2.0 - Ele;
|
|---|
| 334 |
|
|---|
| 335 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | // Prediction Step of the Filter
|
|---|
| 339 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 340 | void bncModel::predict(t_epoData* epoData) {
|
|---|
| 341 |
|
|---|
| 342 | if (_usePhase) {
|
|---|
| 343 |
|
|---|
| 344 | // Make a copy of QQ and xx, set parameter indices
|
|---|
| 345 | // -----------------------------------------------
|
|---|
| 346 | SymmetricMatrix QQ_old = _QQ;
|
|---|
| 347 |
|
|---|
| 348 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 349 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
|---|
| 350 | _params[iPar-1]->index = 0;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | // Remove Ambiguity Parameters without observations
|
|---|
| 354 | // ------------------------------------------------
|
|---|
| 355 | int iPar = 0;
|
|---|
| 356 | QMutableVectorIterator<bncParam*> it(_params);
|
|---|
| 357 | while (it.hasNext()) {
|
|---|
| 358 | bncParam* par = it.next();
|
|---|
| 359 | bool removed = false;
|
|---|
| 360 | if (par->type == bncParam::AMB_L3) {
|
|---|
| 361 | if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
|
|---|
| 362 | epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() ) {
|
|---|
| 363 | removed = true;
|
|---|
| 364 | delete par;
|
|---|
| 365 | it.remove();
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 | if (! removed) {
|
|---|
| 369 | ++iPar;
|
|---|
| 370 | par->index = iPar;
|
|---|
| 371 | }
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | // Add new ambiguity parameters
|
|---|
| 375 | // ----------------------------
|
|---|
| 376 | QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
|---|
| 377 | while (iGPS.hasNext()) {
|
|---|
| 378 | iGPS.next();
|
|---|
| 379 | QString prn = iGPS.key();
|
|---|
| 380 | bool found = false;
|
|---|
| 381 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 382 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
|---|
| 383 | _params[iPar-1]->prn == prn) {
|
|---|
| 384 | found = true;
|
|---|
| 385 | break;
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 | if (!found) {
|
|---|
| 389 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
|---|
| 390 | _params.push_back(par);
|
|---|
| 391 | }
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
|---|
| 395 | while (iGlo.hasNext()) {
|
|---|
| 396 | iGlo.next();
|
|---|
| 397 | QString prn = iGlo.key();
|
|---|
| 398 | bool found = false;
|
|---|
| 399 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 400 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
|---|
| 401 | _params[iPar-1]->prn == prn) {
|
|---|
| 402 | found = true;
|
|---|
| 403 | break;
|
|---|
| 404 | }
|
|---|
| 405 | }
|
|---|
| 406 | if (!found) {
|
|---|
| 407 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
|---|
| 408 | _params.push_back(par);
|
|---|
| 409 | }
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | int nPar = _params.size();
|
|---|
| 413 | _QQ.ReSize(nPar); _QQ = 0.0;
|
|---|
| 414 | for (int i1 = 1; i1 <= nPar; i1++) {
|
|---|
| 415 | bncParam* p1 = _params[i1-1];
|
|---|
| 416 | if (p1->index_old != 0) {
|
|---|
| 417 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
|---|
| 418 | for (int i2 = 1; i2 <= nPar; i2++) {
|
|---|
| 419 | bncParam* p2 = _params[i2-1];
|
|---|
| 420 | if (p2->index_old != 0) {
|
|---|
| 421 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
|---|
| 422 | }
|
|---|
| 423 | }
|
|---|
| 424 | }
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | for (int ii = 1; ii <= nPar; ii++) {
|
|---|
| 428 | bncParam* par = _params[ii-1];
|
|---|
| 429 | if (par->index_old == 0) {
|
|---|
| 430 | _QQ(par->index, par->index) = sig_amb_0 * sig_amb_0;
|
|---|
| 431 | }
|
|---|
| 432 | par->index_old = par->index;
|
|---|
| 433 | }
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | // Coordinates
|
|---|
| 437 | // -----------
|
|---|
| 438 | if (_static) {
|
|---|
| 439 | if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
|
|---|
| 440 | _params[0]->xx = _xcBanc(1);
|
|---|
| 441 | _params[1]->xx = _xcBanc(2);
|
|---|
| 442 | _params[2]->xx = _xcBanc(3);
|
|---|
| 443 | }
|
|---|
| 444 | }
|
|---|
| 445 | else {
|
|---|
| 446 | _params[0]->xx = _xcBanc(1);
|
|---|
| 447 | _params[1]->xx = _xcBanc(2);
|
|---|
| 448 | _params[2]->xx = _xcBanc(3);
|
|---|
| 449 |
|
|---|
| 450 | _QQ(1,1) += sig_crd_p * sig_crd_p;
|
|---|
| 451 | _QQ(2,2) += sig_crd_p * sig_crd_p;
|
|---|
| 452 | _QQ(3,3) += sig_crd_p * sig_crd_p;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | // Receiver Clocks
|
|---|
| 456 | // ---------------
|
|---|
| 457 | _params[3]->xx = _xcBanc(4);
|
|---|
| 458 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 459 | _QQ(iPar, 4) = 0.0;
|
|---|
| 460 | }
|
|---|
| 461 | _QQ(4,4) = sig_clk_0 * sig_clk_0;
|
|---|
| 462 |
|
|---|
| 463 | // Tropospheric Delay
|
|---|
| 464 | // ------------------
|
|---|
| 465 | if (_estTropo) {
|
|---|
| 466 | _QQ(5,5) += sig_trp_p * sig_trp_p;
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | // Update Step of the Filter (currently just a single-epoch solution)
|
|---|
| 471 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 472 | t_irc bncModel::update(t_epoData* epoData) {
|
|---|
| 473 |
|
|---|
| 474 | _log = "Precise Point Positioning";
|
|---|
| 475 |
|
|---|
| 476 | _time = epoData->tt;
|
|---|
| 477 |
|
|---|
| 478 | SymmetricMatrix QQsav;
|
|---|
| 479 | ColumnVector dx;
|
|---|
| 480 | ColumnVector vv;
|
|---|
| 481 |
|
|---|
| 482 | // Loop over all outliers
|
|---|
| 483 | // ----------------------
|
|---|
| 484 | do {
|
|---|
| 485 |
|
|---|
| 486 | // Bancroft Solution
|
|---|
| 487 | // -----------------
|
|---|
| 488 | if (cmpBancroft(epoData) != success) {
|
|---|
| 489 | _log += "\nBancroft failed";
|
|---|
| 490 | emit newMessage(_log, false);
|
|---|
| 491 | return failure;
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | if (epoData->sizeGPS() < MINOBS) {
|
|---|
| 495 | _log += "\nNot enough data";
|
|---|
| 496 | emit newMessage(_log, false);
|
|---|
| 497 | return failure;
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 | // Status Prediction
|
|---|
| 501 | // -----------------
|
|---|
| 502 | predict(epoData);
|
|---|
| 503 |
|
|---|
| 504 | // Create First-Design Matrix
|
|---|
| 505 | // --------------------------
|
|---|
| 506 | unsigned nPar = _params.size();
|
|---|
| 507 | unsigned nObs = 0;
|
|---|
| 508 | if (_usePhase) {
|
|---|
| 509 | nObs = 2 * epoData->sizeGPS() + epoData->sizeGlo();
|
|---|
| 510 | }
|
|---|
| 511 | else {
|
|---|
| 512 | nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | Matrix AA(nObs, nPar); // first design matrix
|
|---|
| 516 | ColumnVector ll(nObs); // tems observed-computed
|
|---|
| 517 | SymmetricMatrix PP(nObs); PP = 0.0;
|
|---|
| 518 |
|
|---|
| 519 | unsigned iObs = 0;
|
|---|
| 520 |
|
|---|
| 521 | // GPS code and (optionally) phase observations
|
|---|
| 522 | // --------------------------------------------
|
|---|
| 523 | QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
|
|---|
| 524 | while (itGPS.hasNext()) {
|
|---|
| 525 | ++iObs;
|
|---|
| 526 | itGPS.next();
|
|---|
| 527 | QString prn = itGPS.key();
|
|---|
| 528 | t_satData* satData = itGPS.value();
|
|---|
| 529 |
|
|---|
| 530 | double rhoCmp = cmpValue(satData);
|
|---|
| 531 |
|
|---|
| 532 | double ellWgtCoeff = 1.0;
|
|---|
| 533 | //// double eleD = satData->eleSat * 180.0 / M_PI;
|
|---|
| 534 | //// if (eleD < 25.0) {
|
|---|
| 535 | //// ellWgtCoeff = 2.5 - (eleD - 10.0) * 0.1;
|
|---|
| 536 | //// ellWgtCoeff *= ellWgtCoeff;
|
|---|
| 537 | //// }
|
|---|
| 538 |
|
|---|
| 539 | ll(iObs) = satData->P3 - rhoCmp;
|
|---|
| 540 | PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3) / ellWgtCoeff;
|
|---|
| 541 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 542 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, "");
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | if (_usePhase) {
|
|---|
| 546 | ++iObs;
|
|---|
| 547 | ll(iObs) = satData->L3 - rhoCmp;
|
|---|
| 548 | PP(iObs,iObs) = 1.0 / (sig_L3 * sig_L3) / ellWgtCoeff;
|
|---|
| 549 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 550 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
|---|
| 551 | _params[iPar-1]->prn == prn) {
|
|---|
| 552 | ll(iObs) -= _params[iPar-1]->xx;
|
|---|
| 553 | }
|
|---|
| 554 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, prn);
|
|---|
| 555 | }
|
|---|
| 556 | }
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | // Glonass phase observations
|
|---|
| 560 | // --------------------------
|
|---|
| 561 | if (_usePhase) {
|
|---|
| 562 | QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
|
|---|
| 563 | while (itGlo.hasNext()) {
|
|---|
| 564 | ++iObs;
|
|---|
| 565 | itGlo.next();
|
|---|
| 566 | QString prn = itGlo.key();
|
|---|
| 567 | t_satData* satData = itGlo.value();
|
|---|
| 568 |
|
|---|
| 569 | double rhoCmp = cmpValue(satData);
|
|---|
| 570 |
|
|---|
| 571 | //// beg test
|
|---|
| 572 | cout << prn.toAscii().data() << " " << rhoCmp << " "
|
|---|
| 573 | << satData->P3 << " " << satData->L3 << endl;
|
|---|
| 574 | //// end test
|
|---|
| 575 |
|
|---|
| 576 | double ellWgtCoeff = 1.0;
|
|---|
| 577 | //// double eleD = satData->eleSat * 180.0 / M_PI;
|
|---|
| 578 | //// if (eleD < 25.0) {
|
|---|
| 579 | //// ellWgtCoeff = 2.5 - (eleD - 10.0) * 0.1;
|
|---|
| 580 | //// ellWgtCoeff *= ellWgtCoeff;
|
|---|
| 581 | //// }
|
|---|
| 582 |
|
|---|
| 583 | ll(iObs) = satData->L3 - rhoCmp;
|
|---|
| 584 | PP(iObs,iObs) = 1.0 / (sig_L3 * sig_L3) / ellWgtCoeff;
|
|---|
| 585 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 586 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
|---|
| 587 | _params[iPar-1]->prn == prn) {
|
|---|
| 588 | ll(iObs) -= _params[iPar-1]->xx;
|
|---|
| 589 | }
|
|---|
| 590 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, prn);
|
|---|
| 591 | }
|
|---|
| 592 | }
|
|---|
| 593 | }
|
|---|
| 594 |
|
|---|
| 595 | // Compute Filter Update
|
|---|
| 596 | // ---------------------
|
|---|
| 597 | QQsav = _QQ;
|
|---|
| 598 |
|
|---|
| 599 | Matrix ATP = AA.t() * PP;
|
|---|
| 600 | SymmetricMatrix NN = _QQ.i();
|
|---|
| 601 | NN << NN + ATP * AA;
|
|---|
| 602 | _QQ = NN.i();
|
|---|
| 603 | dx = _QQ * ATP * ll;
|
|---|
| 604 | vv = ll - AA * dx;
|
|---|
| 605 |
|
|---|
| 606 | } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
|
|---|
| 607 | epoData->satDataGlo) != 0);
|
|---|
| 608 |
|
|---|
| 609 | // Set Solution Vector
|
|---|
| 610 | // -------------------
|
|---|
| 611 | ostringstream str1;
|
|---|
| 612 | str1.setf(ios::fixed);
|
|---|
| 613 | QVectorIterator<bncParam*> itPar(_params);
|
|---|
| 614 | while (itPar.hasNext()) {
|
|---|
| 615 | bncParam* par = itPar.next();
|
|---|
| 616 | par->xx += dx(par->index);
|
|---|
| 617 | if (par->type == bncParam::RECCLK) {
|
|---|
| 618 | str1 << "\n clk = " << setw(6) << setprecision(3) << par->xx
|
|---|
| 619 | << " +- " << setw(6) << setprecision(3)
|
|---|
| 620 | << sqrt(_QQ(par->index,par->index));
|
|---|
| 621 | }
|
|---|
| 622 | else if (par->type == bncParam::AMB_L3) {
|
|---|
| 623 | str1 << "\n amb " << par->prn.toAscii().data() << " = "
|
|---|
| 624 | << setw(6) << setprecision(3) << par->xx
|
|---|
| 625 | << " +- " << setw(6) << setprecision(3)
|
|---|
| 626 | << sqrt(_QQ(par->index,par->index));
|
|---|
| 627 | }
|
|---|
| 628 | else if (par->type == bncParam::TROPO) {
|
|---|
| 629 | str1 << "\n trp = " << par->prn.toAscii().data()
|
|---|
| 630 | << setw(7) << setprecision(3) << delay_saast(M_PI/2.0) << " "
|
|---|
| 631 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
|---|
| 632 | << " +- " << setw(6) << setprecision(3)
|
|---|
| 633 | << sqrt(_QQ(par->index,par->index));
|
|---|
| 634 | }
|
|---|
| 635 | }
|
|---|
| 636 | _log += str1.str().c_str();
|
|---|
| 637 |
|
|---|
| 638 | // Message (both log file and screen)
|
|---|
| 639 | // ----------------------------------
|
|---|
| 640 | ostringstream str2;
|
|---|
| 641 | str2.setf(ios::fixed);
|
|---|
| 642 | str2 << _staID.data() << ": PPP "
|
|---|
| 643 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
|---|
| 644 | << setw(14) << setprecision(3) << x() << " +- "
|
|---|
| 645 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
|---|
| 646 | << setw(14) << setprecision(3) << y() << " +- "
|
|---|
| 647 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
|---|
| 648 | << setw(14) << setprecision(3) << z() << " +- "
|
|---|
| 649 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
|---|
| 650 | if (_estTropo) {
|
|---|
| 651 | str2 << " " << setw(6) << setprecision(3) << trp() << " +- "
|
|---|
| 652 | << setw(6) << setprecision(3) << sqrt(_QQ(5,5));
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | emit newMessage(_log, false);
|
|---|
| 656 | emit newMessage(QByteArray(str2.str().c_str()), true);
|
|---|
| 657 |
|
|---|
| 658 | // NMEA Output
|
|---|
| 659 | // -----------
|
|---|
| 660 | double xyz[3];
|
|---|
| 661 | xyz[0] = x();
|
|---|
| 662 | xyz[1] = y();
|
|---|
| 663 | xyz[2] = z();
|
|---|
| 664 | double ell[3];
|
|---|
| 665 | xyz2ell(xyz, ell);
|
|---|
| 666 | double phiDeg = ell[0] * 180 / M_PI;
|
|---|
| 667 | double lamDeg = ell[1] * 180 / M_PI;
|
|---|
| 668 |
|
|---|
| 669 | char phiCh = 'N';
|
|---|
| 670 | if (phiDeg < 0) {
|
|---|
| 671 | phiDeg = -phiDeg;
|
|---|
| 672 | phiCh = 'S';
|
|---|
| 673 | }
|
|---|
| 674 | char lamCh = 'E';
|
|---|
| 675 | if (lamDeg < 0) {
|
|---|
| 676 | lamDeg = -lamDeg;
|
|---|
| 677 | lamCh = 'W';
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | double dop = 2.0; // TODO
|
|---|
| 681 |
|
|---|
| 682 | ostringstream str3;
|
|---|
| 683 | str3.setf(ios::fixed);
|
|---|
| 684 | str3 << "GPGGA,"
|
|---|
| 685 | << epoData->tt.timestr(0,0) << ','
|
|---|
| 686 | << setw(2) << setfill('0') << int(phiDeg)
|
|---|
| 687 | << setw(10) << setprecision(7) << setfill('0')
|
|---|
| 688 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
|---|
| 689 | << setw(2) << setfill('0') << int(lamDeg)
|
|---|
| 690 | << setw(10) << setprecision(7) << setfill('0')
|
|---|
| 691 | << fmod(60*lamDeg,60) << ',' << lamCh
|
|---|
| 692 | << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
|
|---|
| 693 | << setw(3) << setprecision(1) << dop << ','
|
|---|
| 694 | << setprecision(3) << ell[2] << ",M,0.0,M,,,";
|
|---|
| 695 |
|
|---|
| 696 | writeNMEAstr(QString(str3.str().c_str()));
|
|---|
| 697 |
|
|---|
| 698 | return success;
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | // Outlier Detection
|
|---|
| 702 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 703 | int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
|
|---|
| 704 | const ColumnVector& vv,
|
|---|
| 705 | QMap<QString, t_satData*>& satDataGPS,
|
|---|
| 706 | QMap<QString, t_satData*>& satDataGlo) {
|
|---|
| 707 |
|
|---|
| 708 | double vvMaxCodeGPS = 0.0;
|
|---|
| 709 | double vvMaxPhaseGPS = 0.0;
|
|---|
| 710 | double vvMaxPhaseGlo = 0.0;
|
|---|
| 711 | QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
|
|---|
| 712 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
|
|---|
| 713 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
|
|---|
| 714 |
|
|---|
| 715 | int ii = 0;
|
|---|
| 716 |
|
|---|
| 717 | // GPS code and (optionally) phase residuals
|
|---|
| 718 | // -----------------------------------------
|
|---|
| 719 | QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
|
|---|
| 720 | while (itGPS.hasNext()) {
|
|---|
| 721 | itGPS.next();
|
|---|
| 722 | ++ii;
|
|---|
| 723 |
|
|---|
| 724 | if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
|
|---|
| 725 | vvMaxCodeGPS = fabs(vv(ii));
|
|---|
| 726 | itMaxCodeGPS = itGPS;
|
|---|
| 727 | }
|
|---|
| 728 |
|
|---|
| 729 | if (_usePhase) {
|
|---|
| 730 | ++ii;
|
|---|
| 731 | if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
|
|---|
| 732 | vvMaxPhaseGPS = fabs(vv(ii));
|
|---|
| 733 | itMaxPhaseGPS = itGPS;
|
|---|
| 734 | }
|
|---|
| 735 | }
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | // Glonass phase residuals
|
|---|
| 739 | // -----------------------
|
|---|
| 740 | if (_usePhase) {
|
|---|
| 741 | QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
|
|---|
| 742 | while (itGlo.hasNext()) {
|
|---|
| 743 | itGlo.next();
|
|---|
| 744 | ++ii;
|
|---|
| 745 | if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
|
|---|
| 746 | vvMaxPhaseGlo = fabs(vv(ii));
|
|---|
| 747 | itMaxPhaseGlo = itGlo;
|
|---|
| 748 | }
|
|---|
| 749 | }
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | if (vvMaxCodeGPS > MAXRES_CODE) {
|
|---|
| 753 | QString prn = itMaxCodeGPS.key();
|
|---|
| 754 | t_satData* satData = itMaxCodeGPS.value();
|
|---|
| 755 | delete satData;
|
|---|
| 756 | itMaxCodeGPS.remove();
|
|---|
| 757 | _QQ = QQsav;
|
|---|
| 758 |
|
|---|
| 759 | _log += "\nOutlier Code " + prn.toAscii() + " "
|
|---|
| 760 | + QByteArray::number(vvMaxCodeGPS, 'f', 3);
|
|---|
| 761 |
|
|---|
| 762 | return 1;
|
|---|
| 763 | }
|
|---|
| 764 | else if (vvMaxPhaseGPS > MAXRES_PHASE) {
|
|---|
| 765 | QString prn = itMaxPhaseGPS.key();
|
|---|
| 766 | t_satData* satData = itMaxPhaseGPS.value();
|
|---|
| 767 | delete satData;
|
|---|
| 768 | itMaxPhaseGPS.remove();
|
|---|
| 769 | _QQ = QQsav;
|
|---|
| 770 |
|
|---|
| 771 | _log += "\nOutlier Phase " + prn.toAscii() + " "
|
|---|
| 772 | + QByteArray::number(vvMaxPhaseGPS, 'f', 3);
|
|---|
| 773 |
|
|---|
| 774 | return 1;
|
|---|
| 775 | }
|
|---|
| 776 | else if (vvMaxPhaseGlo > MAXRES_PHASE) {
|
|---|
| 777 | QString prn = itMaxPhaseGlo.key();
|
|---|
| 778 | t_satData* satData = itMaxPhaseGlo.value();
|
|---|
| 779 | delete satData;
|
|---|
| 780 | itMaxPhaseGlo.remove();
|
|---|
| 781 | _QQ = QQsav;
|
|---|
| 782 |
|
|---|
| 783 | _log += "\nOutlier Phase " + prn.toAscii() + " "
|
|---|
| 784 | + QByteArray::number(vvMaxPhaseGlo, 'f', 3);
|
|---|
| 785 |
|
|---|
| 786 | return 1;
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| 789 | return 0;
|
|---|
| 790 | }
|
|---|
| 791 |
|
|---|
| 792 | //
|
|---|
| 793 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 794 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
|---|
| 795 |
|
|---|
| 796 | unsigned char XOR = 0;
|
|---|
| 797 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
|---|
| 798 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | QString outStr = '$' + nmStr
|
|---|
| 802 | + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
|---|
| 803 |
|
|---|
| 804 | if (_nmeaStream) {
|
|---|
| 805 | *_nmeaStream << outStr;
|
|---|
| 806 | _nmeaStream->flush();
|
|---|
| 807 | }
|
|---|
| 808 |
|
|---|
| 809 | emit newNMEAstr(outStr.toAscii());
|
|---|
| 810 | }
|
|---|