[6054] | 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 "bncpppclient.h"
|
---|
| 48 | #include "bnccore.h"
|
---|
| 49 | #include "bncpppclient.h"
|
---|
| 50 | #include "bancroft.h"
|
---|
| 51 | #include "bncutils.h"
|
---|
| 52 | #include "bncantex.h"
|
---|
[6059] | 53 | #include "pppOptions.h"
|
---|
[6054] | 54 |
|
---|
[6055] | 55 | using namespace BNC_PPP;
|
---|
[6054] | 56 | using namespace std;
|
---|
| 57 |
|
---|
| 58 | const unsigned MINOBS = 5;
|
---|
| 59 | const double MINELE = 10.0 * M_PI / 180.0;
|
---|
| 60 | const double MAXRES_CODE = 15.0;
|
---|
| 61 | const double MAXRES_PHASE_GPS = 0.04;
|
---|
| 62 | const double MAXRES_PHASE_GLONASS = 0.08;
|
---|
| 63 | const double GLONASS_WEIGHT_FACTOR = 5.0;
|
---|
| 64 |
|
---|
| 65 | // Constructor
|
---|
| 66 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 67 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
| 68 | const QString& prnIn) {
|
---|
| 69 | type = typeIn;
|
---|
| 70 | index = indexIn;
|
---|
| 71 | prn = prnIn;
|
---|
| 72 | index_old = 0;
|
---|
| 73 | xx = 0.0;
|
---|
| 74 | numEpo = 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | // Destructor
|
---|
| 78 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 79 | bncParam::~bncParam() {
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | // Partial
|
---|
| 83 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 84 | double bncParam::partial(t_satData* satData, bool phase) {
|
---|
| 85 |
|
---|
| 86 | Tracer tracer("bncParam::partial");
|
---|
| 87 |
|
---|
| 88 | // Coordinates
|
---|
| 89 | // -----------
|
---|
| 90 | if (type == CRD_X) {
|
---|
| 91 | return (xx - satData->xx(1)) / satData->rho;
|
---|
| 92 | }
|
---|
| 93 | else if (type == CRD_Y) {
|
---|
| 94 | return (xx - satData->xx(2)) / satData->rho;
|
---|
| 95 | }
|
---|
| 96 | else if (type == CRD_Z) {
|
---|
| 97 | return (xx - satData->xx(3)) / satData->rho;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | // Receiver Clocks
|
---|
| 101 | // ---------------
|
---|
| 102 | else if (type == RECCLK) {
|
---|
| 103 | return 1.0;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | // Troposphere
|
---|
| 107 | // -----------
|
---|
| 108 | else if (type == TROPO) {
|
---|
| 109 | return 1.0 / sin(satData->eleSat);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | // Glonass Offset
|
---|
| 113 | // --------------
|
---|
| 114 | else if (type == GLONASS_OFFSET) {
|
---|
| 115 | if (satData->prn[0] == 'R') {
|
---|
| 116 | return 1.0;
|
---|
| 117 | }
|
---|
| 118 | else {
|
---|
| 119 | return 0.0;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | // Galileo Offset
|
---|
| 124 | // --------------
|
---|
| 125 | else if (type == GALILEO_OFFSET) {
|
---|
| 126 | if (satData->prn[0] == 'E') {
|
---|
| 127 | return 1.0;
|
---|
| 128 | }
|
---|
| 129 | else {
|
---|
| 130 | return 0.0;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | // Ambiguities
|
---|
| 135 | // -----------
|
---|
| 136 | else if (type == AMB_L3) {
|
---|
| 137 | if (phase && satData->prn == prn) {
|
---|
| 138 | return 1.0;
|
---|
| 139 | }
|
---|
| 140 | else {
|
---|
| 141 | return 0.0;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | // Default return
|
---|
| 146 | // --------------
|
---|
| 147 | return 0.0;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | // Constructor
|
---|
| 151 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 152 | bncModel::bncModel(bncPPPclient* pppClient) {
|
---|
| 153 |
|
---|
| 154 | _pppClient = pppClient;
|
---|
| 155 | _staID = pppClient->staID();
|
---|
| 156 | _opt = pppClient->opt();
|
---|
| 157 |
|
---|
| 158 | // Antenna Name, ANTEX File
|
---|
| 159 | // ------------------------
|
---|
| 160 | _antex = 0;
|
---|
| 161 | if (!_opt->antexFile.isEmpty()) {
|
---|
| 162 | _antex = new bncAntex();
|
---|
| 163 | if (_antex->readFile(_opt->antexFile) != success) {
|
---|
| 164 | _pppClient->emitNewMessage("wrong ANTEX file", true);
|
---|
| 165 | delete _antex;
|
---|
| 166 | _antex = 0;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | // Bancroft Coordinates
|
---|
| 171 | // --------------------
|
---|
| 172 | _xcBanc.ReSize(4); _xcBanc = 0.0;
|
---|
| 173 | _ellBanc.ReSize(3); _ellBanc = 0.0;
|
---|
| 174 |
|
---|
| 175 | // Save copy of data (used in outlier detection)
|
---|
| 176 | // ---------------------------------------------
|
---|
| 177 | _epoData_sav = new t_epoData();
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | // Destructor
|
---|
| 181 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 182 | bncModel::~bncModel() {
|
---|
| 183 | for (int ii = 0; ii < _posAverage.size(); ++ii) {
|
---|
| 184 | delete _posAverage[ii];
|
---|
| 185 | }
|
---|
| 186 | delete _antex;
|
---|
| 187 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 188 | delete _params[iPar-1];
|
---|
| 189 | }
|
---|
| 190 | for (int iPar = 1; iPar <= _params_sav.size(); iPar++) {
|
---|
| 191 | delete _params_sav[iPar-1];
|
---|
| 192 | }
|
---|
| 193 | delete _epoData_sav;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | // Reset Parameters and Variance-Covariance Matrix
|
---|
| 197 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 198 | void bncModel::reset() {
|
---|
| 199 |
|
---|
| 200 | Tracer tracer("bncModel::reset");
|
---|
| 201 |
|
---|
| 202 | double lastTrp = 0.0;
|
---|
| 203 | for (int ii = 0; ii < _params.size(); ii++) {
|
---|
| 204 | bncParam* pp = _params[ii];
|
---|
| 205 | if (pp->type == bncParam::TROPO) {
|
---|
| 206 | lastTrp = pp->xx;
|
---|
| 207 | }
|
---|
| 208 | delete pp;
|
---|
| 209 | }
|
---|
| 210 | _params.clear();
|
---|
| 211 |
|
---|
| 212 | int nextPar = 0;
|
---|
| 213 | _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
|
---|
| 214 | _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
|
---|
| 215 | _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
|
---|
| 216 | _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
|
---|
| 217 | if (_opt->estTropo) {
|
---|
| 218 | _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
|
---|
| 219 | }
|
---|
| 220 | if (_opt->useGlonass) {
|
---|
| 221 | _params.push_back(new bncParam(bncParam::GLONASS_OFFSET, ++nextPar, ""));
|
---|
| 222 | }
|
---|
| 223 | if (_opt->useGalileo) {
|
---|
| 224 | _params.push_back(new bncParam(bncParam::GALILEO_OFFSET, ++nextPar, ""));
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | _QQ.ReSize(_params.size());
|
---|
| 228 | _QQ = 0.0;
|
---|
| 229 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 230 | bncParam* pp = _params[iPar-1];
|
---|
| 231 | pp->xx = 0.0;
|
---|
| 232 | if (pp->isCrd()) {
|
---|
| 233 | _QQ(iPar,iPar) = _opt->sigCrd0 * _opt->sigCrd0;
|
---|
| 234 | }
|
---|
| 235 | else if (pp->type == bncParam::RECCLK) {
|
---|
| 236 | _QQ(iPar,iPar) = _opt->sigClk0 * _opt->sigClk0;
|
---|
| 237 | }
|
---|
| 238 | else if (pp->type == bncParam::TROPO) {
|
---|
| 239 | _QQ(iPar,iPar) = _opt->sigTrp0 * _opt->sigTrp0;
|
---|
| 240 | pp->xx = lastTrp;
|
---|
| 241 | }
|
---|
| 242 | else if (pp->type == bncParam::GLONASS_OFFSET) {
|
---|
| 243 | _QQ(iPar,iPar) = _opt->sigGlonassOffset0 * _opt->sigGlonassOffset0;
|
---|
| 244 | }
|
---|
| 245 | else if (pp->type == bncParam::GALILEO_OFFSET) {
|
---|
| 246 | _QQ(iPar,iPar) = _opt->sigGalileoOffset0 * _opt->sigGalileoOffset0;
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | // Bancroft Solution
|
---|
| 252 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 253 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
---|
| 254 |
|
---|
| 255 | Tracer tracer("bncModel::cmpBancroft");
|
---|
| 256 |
|
---|
| 257 | if (epoData->sizeSys('G') < MINOBS) {
|
---|
| 258 | _log += "bncModel::cmpBancroft: not enough data\n";
|
---|
| 259 | return failure;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | Matrix BB(epoData->sizeSys('G'), 4);
|
---|
| 263 |
|
---|
| 264 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 265 | int iObsBanc = 0;
|
---|
| 266 | while (it.hasNext()) {
|
---|
| 267 | it.next();
|
---|
| 268 | t_satData* satData = it.value();
|
---|
| 269 | if (satData->system() == 'G') {
|
---|
| 270 | ++iObsBanc;
|
---|
| 271 | QString prn = it.key();
|
---|
| 272 | BB(iObsBanc, 1) = satData->xx(1);
|
---|
| 273 | BB(iObsBanc, 2) = satData->xx(2);
|
---|
| 274 | BB(iObsBanc, 3) = satData->xx(3);
|
---|
| 275 | BB(iObsBanc, 4) = satData->P3 + satData->clk;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | bancroft(BB, _xcBanc);
|
---|
| 280 |
|
---|
| 281 | // Ellipsoidal Coordinates
|
---|
| 282 | // ------------------------
|
---|
| 283 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
---|
| 284 |
|
---|
| 285 | // Compute Satellite Elevations
|
---|
| 286 | // ----------------------------
|
---|
| 287 | QMutableMapIterator<QString, t_satData*> im(epoData->satData);
|
---|
| 288 | while (im.hasNext()) {
|
---|
| 289 | im.next();
|
---|
| 290 | t_satData* satData = im.value();
|
---|
| 291 | cmpEle(satData);
|
---|
| 292 | if (satData->eleSat < MINELE) {
|
---|
| 293 | delete satData;
|
---|
| 294 | im.remove();
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | return success;
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | // Computed Value
|
---|
| 302 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 303 | double bncModel::cmpValue(t_satData* satData, bool phase) {
|
---|
| 304 |
|
---|
| 305 | Tracer tracer("bncModel::cmpValue");
|
---|
| 306 |
|
---|
| 307 | ColumnVector xRec(3);
|
---|
| 308 | xRec(1) = x();
|
---|
| 309 | xRec(2) = y();
|
---|
| 310 | xRec(3) = z();
|
---|
| 311 |
|
---|
| 312 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
---|
| 313 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
---|
| 314 |
|
---|
| 315 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
---|
| 316 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
---|
| 317 | xRec(3) = z();
|
---|
| 318 |
|
---|
| 319 | tides(_time, xRec);
|
---|
| 320 |
|
---|
| 321 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
---|
| 322 |
|
---|
| 323 | double tropDelay = delay_saast(satData->eleSat) +
|
---|
| 324 | trp() / sin(satData->eleSat);
|
---|
| 325 |
|
---|
| 326 | double wind = 0.0;
|
---|
| 327 | if (phase) {
|
---|
| 328 | wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | double offset = 0.0;
|
---|
| 332 | if (satData->prn[0] == 'R') {
|
---|
| 333 | offset = Glonass_offset();
|
---|
| 334 | }
|
---|
| 335 | else if (satData->prn[0] == 'E') {
|
---|
| 336 | offset = Galileo_offset();
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | double phaseCenter = 0.0;
|
---|
| 340 | if (_antex) {
|
---|
| 341 | bool found;
|
---|
| 342 | phaseCenter = _antex->pco(_opt->antennaName, satData->eleSat, found);
|
---|
| 343 | if (!found) {
|
---|
| 344 | _pppClient->emitNewMessage("ANTEX: antenna >"
|
---|
| 345 | + _opt->antennaName.toAscii() + "< not found", true);
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | double antennaOffset = 0.0;
|
---|
| 350 | if (_opt->antEccSet()) {
|
---|
| 351 | double cosa = cos(satData->azSat);
|
---|
| 352 | double sina = sin(satData->azSat);
|
---|
| 353 | double cose = cos(satData->eleSat);
|
---|
| 354 | double sine = sin(satData->eleSat);
|
---|
| 355 | antennaOffset = -_opt->antEccNEU[0] * cosa*cose
|
---|
| 356 | -_opt->antEccNEU[1] * sina*cose
|
---|
| 357 | -_opt->antEccNEU[2] * sine;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | return satData->rho + phaseCenter + antennaOffset + clk()
|
---|
| 361 | + offset - satData->clk + tropDelay + wind;
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | // Tropospheric Model (Saastamoinen)
|
---|
| 365 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 366 | double bncModel::delay_saast(double Ele) {
|
---|
| 367 |
|
---|
| 368 | Tracer tracer("bncModel::delay_saast");
|
---|
| 369 |
|
---|
| 370 | double xyz[3];
|
---|
| 371 | xyz[0] = x();
|
---|
| 372 | xyz[1] = y();
|
---|
| 373 | xyz[2] = z();
|
---|
| 374 | double ell[3];
|
---|
| 375 | xyz2ell(xyz, ell);
|
---|
| 376 | double height = ell[2];
|
---|
| 377 |
|
---|
| 378 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
---|
| 379 | double TT = 18.0 - height * 0.0065 + 273.15;
|
---|
| 380 | double hh = 50.0 * exp(-6.396e-4 * height);
|
---|
| 381 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
---|
| 382 |
|
---|
| 383 | double h_km = height / 1000.0;
|
---|
| 384 |
|
---|
| 385 | if (h_km < 0.0) h_km = 0.0;
|
---|
| 386 | if (h_km > 5.0) h_km = 5.0;
|
---|
| 387 | int ii = int(h_km + 1);
|
---|
| 388 | double href = ii - 1;
|
---|
| 389 |
|
---|
| 390 | double bCor[6];
|
---|
| 391 | bCor[0] = 1.156;
|
---|
| 392 | bCor[1] = 1.006;
|
---|
| 393 | bCor[2] = 0.874;
|
---|
| 394 | bCor[3] = 0.757;
|
---|
| 395 | bCor[4] = 0.654;
|
---|
| 396 | bCor[5] = 0.563;
|
---|
| 397 |
|
---|
| 398 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
---|
| 399 |
|
---|
| 400 | double zen = M_PI/2.0 - Ele;
|
---|
| 401 |
|
---|
| 402 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | // Prediction Step of the Filter
|
---|
| 406 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 407 | void bncModel::predict(int iPhase, t_epoData* epoData) {
|
---|
| 408 |
|
---|
| 409 | Tracer tracer("bncModel::predict");
|
---|
| 410 |
|
---|
| 411 | if (iPhase == 0) {
|
---|
| 412 |
|
---|
| 413 | bool firstCrd = false;
|
---|
| 414 | if (!_lastTimeOK.valid() || (_opt->maxSolGap > 0 && _time - _lastTimeOK > _opt->maxSolGap)) {
|
---|
| 415 | firstCrd = true;
|
---|
| 416 | _startTime = epoData->tt;
|
---|
| 417 | reset();
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | // Use different white noise for Quick-Start mode
|
---|
| 421 | // ----------------------------------------------
|
---|
| 422 | double sigCrdP_used = _opt->sigCrdP;
|
---|
| 423 | if ( _opt->quickStart > 0.0 && _opt->quickStart > (epoData->tt - _startTime) ) {
|
---|
| 424 | sigCrdP_used = 0.0;
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | // Predict Parameter values, add white noise
|
---|
| 428 | // -----------------------------------------
|
---|
| 429 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 430 | bncParam* pp = _params[iPar-1];
|
---|
| 431 |
|
---|
| 432 | // Coordinates
|
---|
| 433 | // -----------
|
---|
| 434 | if (pp->type == bncParam::CRD_X) {
|
---|
| 435 | if (firstCrd) {
|
---|
| 436 | if (_opt->refCrdSet()) {
|
---|
| 437 | pp->xx = _opt->refCrd[0];
|
---|
| 438 | }
|
---|
| 439 | else {
|
---|
| 440 | pp->xx = _xcBanc(1);
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 | _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
|
---|
| 444 | }
|
---|
| 445 | else if (pp->type == bncParam::CRD_Y) {
|
---|
| 446 | if (firstCrd) {
|
---|
| 447 | if (_opt->refCrdSet()) {
|
---|
| 448 | pp->xx = _opt->refCrd[1];
|
---|
| 449 | }
|
---|
| 450 | else {
|
---|
| 451 | pp->xx = _xcBanc(2);
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 | _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
|
---|
| 455 | }
|
---|
| 456 | else if (pp->type == bncParam::CRD_Z) {
|
---|
| 457 | if (firstCrd) {
|
---|
| 458 | if (_opt->refCrdSet()) {
|
---|
| 459 | pp->xx = _opt->refCrd[2];
|
---|
| 460 | }
|
---|
| 461 | else {
|
---|
| 462 | pp->xx = _xcBanc(3);
|
---|
| 463 | }
|
---|
| 464 | }
|
---|
| 465 | _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | // Receiver Clocks
|
---|
| 469 | // ---------------
|
---|
| 470 | else if (pp->type == bncParam::RECCLK) {
|
---|
| 471 | pp->xx = _xcBanc(4);
|
---|
| 472 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 473 | _QQ(iPar, jj) = 0.0;
|
---|
| 474 | }
|
---|
| 475 | _QQ(iPar,iPar) = _opt->sigClk0 * _opt->sigClk0;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | // Tropospheric Delay
|
---|
| 479 | // ------------------
|
---|
| 480 | else if (pp->type == bncParam::TROPO) {
|
---|
| 481 | _QQ(iPar,iPar) += _opt->sigTrpP * _opt->sigTrpP;
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | // Glonass Offset
|
---|
| 485 | // --------------
|
---|
| 486 | else if (pp->type == bncParam::GLONASS_OFFSET) {
|
---|
| 487 | bool epoSpec = true;
|
---|
| 488 | if (epoSpec) {
|
---|
| 489 | pp->xx = 0.0;
|
---|
| 490 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 491 | _QQ(iPar, jj) = 0.0;
|
---|
| 492 | }
|
---|
| 493 | _QQ(iPar,iPar) = _opt->sigGlonassOffset0 * _opt->sigGlonassOffset0;
|
---|
| 494 | }
|
---|
| 495 | else {
|
---|
| 496 | _QQ(iPar,iPar) += _opt->sigGlonassOffsetP * _opt->sigGlonassOffsetP;
|
---|
| 497 | }
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | // Galileo Offset
|
---|
| 501 | // --------------
|
---|
| 502 | else if (pp->type == bncParam::GALILEO_OFFSET) {
|
---|
| 503 | _QQ(iPar,iPar) += _opt->sigGalileoOffsetP * _opt->sigGalileoOffsetP;
|
---|
| 504 | }
|
---|
| 505 | }
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | // Add New Ambiguities if necessary
|
---|
| 509 | // --------------------------------
|
---|
| 510 | if (_opt->usePhase) {
|
---|
| 511 |
|
---|
| 512 | // Make a copy of QQ and xx, set parameter indices
|
---|
| 513 | // -----------------------------------------------
|
---|
| 514 | SymmetricMatrix QQ_old = _QQ;
|
---|
| 515 |
|
---|
| 516 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 517 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
---|
| 518 | _params[iPar-1]->index = 0;
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | // Remove Ambiguity Parameters without observations
|
---|
| 522 | // ------------------------------------------------
|
---|
| 523 | int iPar = 0;
|
---|
| 524 | QMutableVectorIterator<bncParam*> im(_params);
|
---|
| 525 | while (im.hasNext()) {
|
---|
| 526 | bncParam* par = im.next();
|
---|
| 527 | bool removed = false;
|
---|
| 528 | if (par->type == bncParam::AMB_L3) {
|
---|
| 529 | if (epoData->satData.find(par->prn) == epoData->satData.end()) {
|
---|
| 530 | removed = true;
|
---|
| 531 | delete par;
|
---|
| 532 | im.remove();
|
---|
| 533 | }
|
---|
| 534 | }
|
---|
| 535 | if (! removed) {
|
---|
| 536 | ++iPar;
|
---|
| 537 | par->index = iPar;
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | // Add new ambiguity parameters
|
---|
| 542 | // ----------------------------
|
---|
| 543 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 544 | while (it.hasNext()) {
|
---|
| 545 | it.next();
|
---|
| 546 | t_satData* satData = it.value();
|
---|
| 547 | addAmb(satData);
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | int nPar = _params.size();
|
---|
| 551 | _QQ.ReSize(nPar); _QQ = 0.0;
|
---|
| 552 | for (int i1 = 1; i1 <= nPar; i1++) {
|
---|
| 553 | bncParam* p1 = _params[i1-1];
|
---|
| 554 | if (p1->index_old != 0) {
|
---|
| 555 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
---|
| 556 | for (int i2 = 1; i2 <= nPar; i2++) {
|
---|
| 557 | bncParam* p2 = _params[i2-1];
|
---|
| 558 | if (p2->index_old != 0) {
|
---|
| 559 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 | }
|
---|
| 564 |
|
---|
| 565 | for (int ii = 1; ii <= nPar; ii++) {
|
---|
| 566 | bncParam* par = _params[ii-1];
|
---|
| 567 | if (par->index_old == 0) {
|
---|
| 568 | _QQ(par->index, par->index) = _opt->sigAmb0 * _opt->sigAmb0;
|
---|
| 569 | }
|
---|
| 570 | par->index_old = par->index;
|
---|
| 571 | }
|
---|
| 572 | }
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | // Update Step of the Filter (currently just a single-epoch solution)
|
---|
| 576 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 577 | t_irc bncModel::update(t_epoData* epoData) {
|
---|
| 578 |
|
---|
| 579 | Tracer tracer("bncModel::update");
|
---|
| 580 |
|
---|
| 581 | _log.clear();
|
---|
| 582 |
|
---|
| 583 | _time = epoData->tt; // current epoch time
|
---|
| 584 |
|
---|
| 585 | if (_opt->pppMode) {
|
---|
| 586 | _log += "Precise Point Positioning of Epoch "
|
---|
| 587 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
| 588 | "\n---------------------------------------------------------------\n";
|
---|
| 589 | }
|
---|
| 590 | else {
|
---|
| 591 | _log += "Single Point Positioning of Epoch "
|
---|
| 592 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
| 593 | "\n--------------------------------------------------------------\n";
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | // Outlier Detection Loop
|
---|
| 597 | // ----------------------
|
---|
| 598 | if (update_p(epoData) != success) {
|
---|
| 599 | _pppClient->emitNewMessage(_log, false);
|
---|
| 600 | return failure;
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 | // Remember the Epoch-specific Results for the computation of means
|
---|
| 604 | // ----------------------------------------------------------------
|
---|
| 605 | pppPos* newPos = new pppPos;
|
---|
| 606 | newPos->time = epoData->tt;
|
---|
| 607 |
|
---|
| 608 | // Set Solution Vector
|
---|
| 609 | // -------------------
|
---|
| 610 | ostringstream strB;
|
---|
| 611 | strB.setf(ios::fixed);
|
---|
| 612 | QVectorIterator<bncParam*> itPar(_params);
|
---|
| 613 | while (itPar.hasNext()) {
|
---|
| 614 | bncParam* par = itPar.next();
|
---|
| 615 |
|
---|
| 616 | if (par->type == bncParam::RECCLK) {
|
---|
| 617 | strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
|
---|
| 618 | << " +- " << setw(6) << setprecision(3)
|
---|
| 619 | << sqrt(_QQ(par->index,par->index));
|
---|
| 620 | }
|
---|
| 621 | else if (par->type == bncParam::AMB_L3) {
|
---|
| 622 | ++par->numEpo;
|
---|
| 623 | strB << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
| 624 | << setw(10) << setprecision(3) << par->xx
|
---|
| 625 | << " +- " << setw(6) << setprecision(3)
|
---|
| 626 | << sqrt(_QQ(par->index,par->index))
|
---|
| 627 | << " nEpo = " << par->numEpo;
|
---|
| 628 | }
|
---|
| 629 | else if (par->type == bncParam::TROPO) {
|
---|
| 630 | double aprTrp = delay_saast(M_PI/2.0);
|
---|
| 631 | strB << "\n trp = " << par->prn.toAscii().data()
|
---|
| 632 | << setw(7) << setprecision(3) << aprTrp << " "
|
---|
| 633 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
---|
| 634 | << " +- " << setw(6) << setprecision(3)
|
---|
| 635 | << sqrt(_QQ(par->index,par->index));
|
---|
| 636 | newPos->xnt[6] = aprTrp + par->xx;
|
---|
| 637 | }
|
---|
| 638 | else if (par->type == bncParam::GLONASS_OFFSET) {
|
---|
| 639 | strB << "\n offGlo = " << setw(10) << setprecision(3) << par->xx
|
---|
| 640 | << " +- " << setw(6) << setprecision(3)
|
---|
| 641 | << sqrt(_QQ(par->index,par->index));
|
---|
| 642 | }
|
---|
| 643 | else if (par->type == bncParam::GALILEO_OFFSET) {
|
---|
| 644 | strB << "\n offGal = " << setw(10) << setprecision(3) << par->xx
|
---|
| 645 | << " +- " << setw(6) << setprecision(3)
|
---|
| 646 | << sqrt(_QQ(par->index,par->index));
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 | strB << '\n';
|
---|
| 650 | _log += strB.str().c_str();
|
---|
| 651 | _pppClient->emitNewMessage(_log, false);
|
---|
| 652 |
|
---|
| 653 | // Final Message (both log file and screen)
|
---|
| 654 | // ----------------------------------------
|
---|
| 655 | ostringstream strC;
|
---|
| 656 | strC.setf(ios::fixed);
|
---|
| 657 | strC << _staID.data() << " PPP "
|
---|
| 658 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
| 659 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
| 660 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
| 661 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
| 662 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
| 663 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
| 664 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
| 665 |
|
---|
| 666 | // NEU Output
|
---|
| 667 | // ----------
|
---|
| 668 | if (_opt->refCrdSet()) {
|
---|
| 669 | newPos->xnt[0] = x() - _opt->refCrd[0];
|
---|
| 670 | newPos->xnt[1] = y() - _opt->refCrd[1];
|
---|
| 671 | newPos->xnt[2] = z() - _opt->refCrd[2];
|
---|
| 672 |
|
---|
| 673 | double ellRef[3];
|
---|
| 674 | xyz2ell(_opt->refCrd, ellRef);
|
---|
| 675 | xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
|
---|
| 676 |
|
---|
| 677 | strC << " NEU "
|
---|
| 678 | << setw(8) << setprecision(3) << newPos->xnt[3] << " "
|
---|
| 679 | << setw(8) << setprecision(3) << newPos->xnt[4] << " "
|
---|
| 680 | << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
|
---|
| 681 |
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | _pppClient->emitNewMessage(QByteArray(strC.str().c_str()), true);
|
---|
| 685 |
|
---|
| 686 | if (_opt->pppAverage == 0.0) {
|
---|
| 687 | delete newPos;
|
---|
| 688 | }
|
---|
| 689 | else {
|
---|
| 690 |
|
---|
| 691 | _posAverage.push_back(newPos);
|
---|
| 692 |
|
---|
| 693 | // Compute the Mean
|
---|
| 694 | // ----------------
|
---|
| 695 | ColumnVector mean(7); mean = 0.0;
|
---|
| 696 |
|
---|
| 697 | QMutableVectorIterator<pppPos*> it(_posAverage);
|
---|
| 698 | while (it.hasNext()) {
|
---|
| 699 | pppPos* pp = it.next();
|
---|
| 700 | if ( (epoData->tt - pp->time) >= _opt->pppAverage ) {
|
---|
| 701 | delete pp;
|
---|
| 702 | it.remove();
|
---|
| 703 | }
|
---|
| 704 | else {
|
---|
| 705 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 706 | mean[ii] += pp->xnt[ii];
|
---|
| 707 | }
|
---|
| 708 | }
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 | int nn = _posAverage.size();
|
---|
| 712 |
|
---|
| 713 | if (nn > 0) {
|
---|
| 714 |
|
---|
| 715 | mean /= nn;
|
---|
| 716 |
|
---|
| 717 | // Compute the Deviation
|
---|
| 718 | // ---------------------
|
---|
| 719 | ColumnVector std(7); std = 0.0;
|
---|
| 720 | QVectorIterator<pppPos*> it2(_posAverage);
|
---|
| 721 | while (it2.hasNext()) {
|
---|
| 722 | pppPos* pp = it2.next();
|
---|
| 723 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 724 | std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
|
---|
| 725 | }
|
---|
| 726 | }
|
---|
| 727 | for (int ii = 0; ii < 7; ++ii) {
|
---|
| 728 | std[ii] = sqrt(std[ii] / nn);
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | if (_opt->refCrdSet()) {
|
---|
| 732 | ostringstream strD; strD.setf(ios::fixed);
|
---|
| 733 | strD << _staID.data() << " AVE-XYZ "
|
---|
| 734 | << epoData->tt.timestr(1) << " "
|
---|
| 735 | << setw(13) << setprecision(3) << mean[0] + _opt->refCrd[0] << " +- "
|
---|
| 736 | << setw(6) << setprecision(3) << std[0] << " "
|
---|
| 737 | << setw(14) << setprecision(3) << mean[1] + _opt->refCrd[1] << " +- "
|
---|
| 738 | << setw(6) << setprecision(3) << std[1] << " "
|
---|
| 739 | << setw(14) << setprecision(3) << mean[2] + _opt->refCrd[2] << " +- "
|
---|
| 740 | << setw(6) << setprecision(3) << std[2];
|
---|
| 741 | _pppClient->emitNewMessage(QByteArray(strD.str().c_str()), true);
|
---|
| 742 |
|
---|
| 743 | ostringstream strE; strE.setf(ios::fixed);
|
---|
| 744 | strE << _staID.data() << " AVE-NEU "
|
---|
| 745 | << epoData->tt.timestr(1) << " "
|
---|
| 746 | << setw(13) << setprecision(3) << mean[3] << " +- "
|
---|
| 747 | << setw(6) << setprecision(3) << std[3] << " "
|
---|
| 748 | << setw(14) << setprecision(3) << mean[4] << " +- "
|
---|
| 749 | << setw(6) << setprecision(3) << std[4] << " "
|
---|
| 750 | << setw(14) << setprecision(3) << mean[5] << " +- "
|
---|
| 751 | << setw(6) << setprecision(3) << std[5];
|
---|
| 752 | _pppClient->emitNewMessage(QByteArray(strE.str().c_str()), true);
|
---|
| 753 |
|
---|
| 754 | if (_opt->estTropo) {
|
---|
| 755 | ostringstream strF; strF.setf(ios::fixed);
|
---|
| 756 | strF << _staID.data() << " AVE-TRP "
|
---|
| 757 | << epoData->tt.timestr(1) << " "
|
---|
| 758 | << setw(13) << setprecision(3) << mean[6] << " +- "
|
---|
| 759 | << setw(6) << setprecision(3) << std[6] << endl;
|
---|
| 760 | _pppClient->emitNewMessage(QByteArray(strF.str().c_str()), true);
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 | }
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 | _lastTimeOK = _time; // remember time of last successful update
|
---|
| 767 | return success;
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | // Outlier Detection
|
---|
| 771 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 772 | QString bncModel::outlierDetection(int iPhase, const ColumnVector& vv,
|
---|
| 773 | QMap<QString, t_satData*>& satData) {
|
---|
| 774 |
|
---|
| 775 | Tracer tracer("bncModel::outlierDetection");
|
---|
| 776 |
|
---|
| 777 | QString prnGPS;
|
---|
| 778 | QString prnGlo;
|
---|
| 779 | double maxResGPS = 0.0;
|
---|
| 780 | double maxResGlo = 0.0;
|
---|
| 781 | findMaxRes(vv, satData, prnGPS, prnGlo, maxResGPS, maxResGlo);
|
---|
| 782 |
|
---|
| 783 | if (iPhase == 1) {
|
---|
| 784 | if (maxResGlo > MAXRES_PHASE_GLONASS) {
|
---|
| 785 | _log += "Outlier Phase " + prnGlo + " "
|
---|
| 786 | + QByteArray::number(maxResGlo, 'f', 3) + "\n";
|
---|
| 787 | return prnGlo;
|
---|
| 788 | }
|
---|
| 789 | else if (maxResGPS > MAXRES_PHASE_GPS) {
|
---|
| 790 | _log += "Outlier Phase " + prnGPS + " "
|
---|
| 791 | + QByteArray::number(maxResGPS, 'f', 3) + "\n";
|
---|
| 792 | return prnGPS;
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 | else if (iPhase == 0 && maxResGPS > MAXRES_CODE) {
|
---|
| 796 | _log += "Outlier Code " + prnGPS + " "
|
---|
| 797 | + QByteArray::number(maxResGPS, 'f', 3) + "\n";
|
---|
| 798 | return prnGPS;
|
---|
| 799 | }
|
---|
| 800 |
|
---|
| 801 | return QString();
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 | //
|
---|
| 805 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 806 | void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
|
---|
| 807 | const DiagonalMatrix& PP,
|
---|
| 808 | SymmetricMatrix& QQ, ColumnVector& dx) {
|
---|
| 809 |
|
---|
| 810 | Tracer tracer("bncModel::kalman");
|
---|
| 811 |
|
---|
| 812 | int nPar = AA.Ncols();
|
---|
| 813 | int nObs = AA.Nrows();
|
---|
| 814 | UpperTriangularMatrix SS = Cholesky(QQ).t();
|
---|
| 815 |
|
---|
| 816 | Matrix SA = SS*AA.t();
|
---|
| 817 | Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
|
---|
| 818 | for (int ii = 1; ii <= nObs; ++ii) {
|
---|
| 819 | SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
|
---|
| 820 | }
|
---|
| 821 |
|
---|
| 822 | SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
|
---|
| 823 | SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
|
---|
| 824 |
|
---|
| 825 | UpperTriangularMatrix UU;
|
---|
| 826 | QRZ(SRF, UU);
|
---|
| 827 |
|
---|
| 828 | SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
|
---|
| 829 | UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
|
---|
| 830 | Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
|
---|
| 831 |
|
---|
| 832 | UpperTriangularMatrix SHi = SH_rt.i();
|
---|
| 833 |
|
---|
| 834 | Matrix KT = SHi * YY;
|
---|
| 835 | SymmetricMatrix Hi; Hi << SHi * SHi.t();
|
---|
| 836 |
|
---|
| 837 | dx = KT.t() * ll;
|
---|
| 838 | QQ << (SS.t() * SS);
|
---|
| 839 | }
|
---|
| 840 |
|
---|
| 841 | // Phase Wind-Up Correction
|
---|
| 842 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 843 | double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
|
---|
| 844 | const ColumnVector& rRec) {
|
---|
| 845 |
|
---|
| 846 | Tracer tracer("bncModel::windUp");
|
---|
| 847 |
|
---|
| 848 | double Mjd = _time.mjd() + _time.daysec() / 86400.0;
|
---|
| 849 |
|
---|
| 850 | // First time - initialize to zero
|
---|
| 851 | // -------------------------------
|
---|
| 852 | if (!_windUpTime.contains(prn)) {
|
---|
| 853 | _windUpSum[prn] = 0.0;
|
---|
| 854 | }
|
---|
| 855 |
|
---|
| 856 | // Compute the correction for new time
|
---|
| 857 | // -----------------------------------
|
---|
| 858 | if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
|
---|
| 859 | _windUpTime[prn] = Mjd;
|
---|
| 860 |
|
---|
| 861 | // Unit Vector GPS Satellite --> Receiver
|
---|
| 862 | // --------------------------------------
|
---|
| 863 | ColumnVector rho = rRec - rSat;
|
---|
| 864 | rho /= rho.norm_Frobenius();
|
---|
| 865 |
|
---|
| 866 | // GPS Satellite unit Vectors sz, sy, sx
|
---|
| 867 | // -------------------------------------
|
---|
| 868 | ColumnVector sz = -rSat / rSat.norm_Frobenius();
|
---|
| 869 |
|
---|
| 870 | ColumnVector xSun = Sun(Mjd);
|
---|
| 871 | xSun /= xSun.norm_Frobenius();
|
---|
| 872 |
|
---|
| 873 | ColumnVector sy = crossproduct(sz, xSun);
|
---|
| 874 | ColumnVector sx = crossproduct(sy, sz);
|
---|
| 875 |
|
---|
| 876 | // Effective Dipole of the GPS Satellite Antenna
|
---|
| 877 | // ---------------------------------------------
|
---|
| 878 | ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
|
---|
| 879 | - crossproduct(rho, sy);
|
---|
| 880 |
|
---|
| 881 | // Receiver unit Vectors rx, ry
|
---|
| 882 | // ----------------------------
|
---|
| 883 | ColumnVector rx(3);
|
---|
| 884 | ColumnVector ry(3);
|
---|
| 885 |
|
---|
| 886 | double recEll[3]; xyz2ell(rRec.data(), recEll) ;
|
---|
| 887 | double neu[3];
|
---|
| 888 |
|
---|
| 889 | neu[0] = 1.0;
|
---|
| 890 | neu[1] = 0.0;
|
---|
| 891 | neu[2] = 0.0;
|
---|
| 892 | neu2xyz(recEll, neu, rx.data());
|
---|
| 893 |
|
---|
| 894 | neu[0] = 0.0;
|
---|
| 895 | neu[1] = -1.0;
|
---|
| 896 | neu[2] = 0.0;
|
---|
| 897 | neu2xyz(recEll, neu, ry.data());
|
---|
| 898 |
|
---|
| 899 | // Effective Dipole of the Receiver Antenna
|
---|
| 900 | // ----------------------------------------
|
---|
| 901 | ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
|
---|
| 902 | + crossproduct(rho, ry);
|
---|
| 903 |
|
---|
| 904 | // Resulting Effect
|
---|
| 905 | // ----------------
|
---|
| 906 | double alpha = DotProduct(dipSat,dipRec) /
|
---|
| 907 | (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
|
---|
| 908 |
|
---|
| 909 | if (alpha > 1.0) alpha = 1.0;
|
---|
| 910 | if (alpha < -1.0) alpha = -1.0;
|
---|
| 911 |
|
---|
| 912 | double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
|
---|
| 913 |
|
---|
| 914 | if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
|
---|
| 915 | dphi = -dphi;
|
---|
| 916 | }
|
---|
| 917 |
|
---|
| 918 | _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
|
---|
| 919 | }
|
---|
| 920 |
|
---|
| 921 | return _windUpSum[prn];
|
---|
| 922 | }
|
---|
| 923 |
|
---|
| 924 | //
|
---|
| 925 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 926 | void bncModel::cmpEle(t_satData* satData) {
|
---|
| 927 | Tracer tracer("bncModel::cmpEle");
|
---|
| 928 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
| 929 | double rho = rr.norm_Frobenius();
|
---|
| 930 |
|
---|
| 931 | double neu[3];
|
---|
| 932 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
| 933 |
|
---|
| 934 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
| 935 | if (neu[2] < 0) {
|
---|
| 936 | satData->eleSat *= -1.0;
|
---|
| 937 | }
|
---|
| 938 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
| 939 | }
|
---|
| 940 |
|
---|
| 941 | //
|
---|
| 942 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 943 | void bncModel::addAmb(t_satData* satData) {
|
---|
| 944 | Tracer tracer("bncModel::addAmb");
|
---|
| 945 | bool found = false;
|
---|
| 946 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 947 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 948 | _params[iPar-1]->prn == satData->prn) {
|
---|
| 949 | found = true;
|
---|
| 950 | break;
|
---|
| 951 | }
|
---|
| 952 | }
|
---|
| 953 | if (!found) {
|
---|
| 954 | bncParam* par = new bncParam(bncParam::AMB_L3,
|
---|
| 955 | _params.size()+1, satData->prn);
|
---|
| 956 | _params.push_back(par);
|
---|
| 957 | par->xx = satData->L3 - cmpValue(satData, true);
|
---|
| 958 | }
|
---|
| 959 | }
|
---|
| 960 |
|
---|
| 961 | //
|
---|
| 962 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 963 | void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
|
---|
| 964 | Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
|
---|
| 965 |
|
---|
| 966 | Tracer tracer("bncModel::addObs");
|
---|
| 967 |
|
---|
| 968 | const double ELEWGHT = 20.0;
|
---|
| 969 | double ellWgtCoef = 1.0;
|
---|
| 970 | double eleD = satData->eleSat * 180.0 / M_PI;
|
---|
| 971 | if (eleD < ELEWGHT) {
|
---|
| 972 | ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
|
---|
| 973 | }
|
---|
| 974 |
|
---|
| 975 | // Remember Observation Index
|
---|
| 976 | // --------------------------
|
---|
| 977 | ++iObs;
|
---|
| 978 | satData->obsIndex = iObs;
|
---|
| 979 |
|
---|
| 980 | // Phase Observations
|
---|
| 981 | // ------------------
|
---|
| 982 | if (iPhase == 1) {
|
---|
| 983 | ll(iObs) = satData->L3 - cmpValue(satData, true);
|
---|
| 984 | double sigL3 = _opt->sigL3;
|
---|
| 985 | if (satData->system() == 'R') {
|
---|
| 986 | sigL3 *= GLONASS_WEIGHT_FACTOR;
|
---|
| 987 | }
|
---|
| 988 | PP(iObs,iObs) = 1.0 / (sigL3 * sigL3) / (ellWgtCoef * ellWgtCoef);
|
---|
| 989 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 990 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
| 991 | _params[iPar-1]->prn == satData->prn) {
|
---|
| 992 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
| 993 | }
|
---|
| 994 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
| 995 | }
|
---|
| 996 | }
|
---|
| 997 |
|
---|
| 998 | // Code Observations
|
---|
| 999 | // -----------------
|
---|
| 1000 | else {
|
---|
| 1001 | ll(iObs) = satData->P3 - cmpValue(satData, false);
|
---|
| 1002 | PP(iObs,iObs) = 1.0 / (_opt->sigP3 * _opt->sigP3) / (ellWgtCoef * ellWgtCoef);
|
---|
| 1003 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 1004 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
|
---|
| 1005 | }
|
---|
| 1006 | }
|
---|
| 1007 | }
|
---|
| 1008 |
|
---|
| 1009 | //
|
---|
| 1010 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1011 | QByteArray bncModel::printRes(int iPhase, const ColumnVector& vv,
|
---|
| 1012 | const QMap<QString, t_satData*>& satDataMap) {
|
---|
| 1013 |
|
---|
| 1014 | Tracer tracer("bncModel::printRes");
|
---|
| 1015 |
|
---|
| 1016 | ostringstream str;
|
---|
| 1017 | str.setf(ios::fixed);
|
---|
| 1018 |
|
---|
| 1019 | QMapIterator<QString, t_satData*> it(satDataMap);
|
---|
| 1020 | while (it.hasNext()) {
|
---|
| 1021 | it.next();
|
---|
| 1022 | t_satData* satData = it.value();
|
---|
| 1023 | if (satData->obsIndex != 0) {
|
---|
| 1024 | str << _time.timestr(1)
|
---|
| 1025 | << " RES " << satData->prn.toAscii().data()
|
---|
| 1026 | << (iPhase ? " L3 " : " P3 ")
|
---|
| 1027 | << setw(9) << setprecision(4) << vv(satData->obsIndex) << endl;
|
---|
| 1028 | }
|
---|
| 1029 | }
|
---|
| 1030 |
|
---|
| 1031 | return QByteArray(str.str().c_str());
|
---|
| 1032 | }
|
---|
| 1033 |
|
---|
| 1034 | //
|
---|
| 1035 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1036 | void bncModel::findMaxRes(const ColumnVector& vv,
|
---|
| 1037 | const QMap<QString, t_satData*>& satData,
|
---|
| 1038 | QString& prnGPS, QString& prnGlo,
|
---|
| 1039 | double& maxResGPS, double& maxResGlo) {
|
---|
| 1040 |
|
---|
| 1041 | Tracer tracer("bncModel::findMaxRes");
|
---|
| 1042 |
|
---|
| 1043 | maxResGPS = 0.0;
|
---|
| 1044 | maxResGlo = 0.0;
|
---|
| 1045 |
|
---|
| 1046 | QMapIterator<QString, t_satData*> it(satData);
|
---|
| 1047 | while (it.hasNext()) {
|
---|
| 1048 | it.next();
|
---|
| 1049 | t_satData* satData = it.value();
|
---|
| 1050 | if (satData->obsIndex != 0) {
|
---|
| 1051 | QString prn = satData->prn;
|
---|
| 1052 | if (prn[0] == 'R') {
|
---|
| 1053 | if (fabs(vv(satData->obsIndex)) > maxResGlo) {
|
---|
| 1054 | maxResGlo = fabs(vv(satData->obsIndex));
|
---|
| 1055 | prnGlo = prn;
|
---|
| 1056 | }
|
---|
| 1057 | }
|
---|
| 1058 | else {
|
---|
| 1059 | if (fabs(vv(satData->obsIndex)) > maxResGPS) {
|
---|
| 1060 | maxResGPS = fabs(vv(satData->obsIndex));
|
---|
| 1061 | prnGPS = prn;
|
---|
| 1062 | }
|
---|
| 1063 | }
|
---|
| 1064 | }
|
---|
| 1065 | }
|
---|
| 1066 | }
|
---|
| 1067 |
|
---|
| 1068 | // Update Step (private - loop over outliers)
|
---|
| 1069 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1070 | t_irc bncModel::update_p(t_epoData* epoData) {
|
---|
| 1071 |
|
---|
| 1072 | Tracer tracer("bncModel::update_p");
|
---|
| 1073 |
|
---|
| 1074 | // Save Variance-Covariance Matrix, and Status Vector
|
---|
| 1075 | // --------------------------------------------------
|
---|
| 1076 | rememberState(epoData);
|
---|
| 1077 |
|
---|
| 1078 | QString lastOutlierPrn;
|
---|
| 1079 |
|
---|
| 1080 | // Try with all satellites, then with all minus one, etc.
|
---|
| 1081 | // ------------------------------------------------------
|
---|
| 1082 | while (selectSatellites(lastOutlierPrn, epoData->satData) == success) {
|
---|
| 1083 |
|
---|
| 1084 | QByteArray strResCode;
|
---|
| 1085 | QByteArray strResPhase;
|
---|
| 1086 |
|
---|
| 1087 | // Bancroft Solution
|
---|
| 1088 | // -----------------
|
---|
| 1089 | if (cmpBancroft(epoData) != success) {
|
---|
| 1090 | break;
|
---|
| 1091 | }
|
---|
| 1092 |
|
---|
| 1093 | // First update using code observations, then phase observations
|
---|
| 1094 | // -------------------------------------------------------------
|
---|
| 1095 | for (int iPhase = 0; iPhase <= (_opt->usePhase ? 1 : 0); iPhase++) {
|
---|
| 1096 |
|
---|
| 1097 | // Status Prediction
|
---|
| 1098 | // -----------------
|
---|
| 1099 | predict(iPhase, epoData);
|
---|
| 1100 |
|
---|
| 1101 | // Create First-Design Matrix
|
---|
| 1102 | // --------------------------
|
---|
| 1103 | unsigned nPar = _params.size();
|
---|
| 1104 | unsigned nObs = 0;
|
---|
| 1105 | if (iPhase == 0) {
|
---|
| 1106 | nObs = epoData->sizeAll() - epoData->sizeSys('R'); // Glonass code not used
|
---|
| 1107 | }
|
---|
| 1108 | else {
|
---|
| 1109 | nObs = epoData->sizeAll();
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
| 1112 | // Prepare first-design Matrix, vector observed-computed
|
---|
| 1113 | // -----------------------------------------------------
|
---|
| 1114 | Matrix AA(nObs, nPar); // first design matrix
|
---|
| 1115 | ColumnVector ll(nObs); // tems observed-computed
|
---|
| 1116 | DiagonalMatrix PP(nObs); PP = 0.0;
|
---|
| 1117 |
|
---|
| 1118 | unsigned iObs = 0;
|
---|
| 1119 | QMapIterator<QString, t_satData*> it(epoData->satData);
|
---|
| 1120 | while (it.hasNext()) {
|
---|
| 1121 | it.next();
|
---|
| 1122 | t_satData* satData = it.value();
|
---|
| 1123 | if (iPhase == 1 || satData->system() != 'R') {
|
---|
| 1124 | QString prn = satData->prn;
|
---|
| 1125 | addObs(iPhase, iObs, satData, AA, ll, PP);
|
---|
| 1126 | }
|
---|
| 1127 | }
|
---|
| 1128 |
|
---|
| 1129 | // Compute Filter Update
|
---|
| 1130 | // ---------------------
|
---|
| 1131 | ColumnVector dx;
|
---|
| 1132 | kalman(AA, ll, PP, _QQ, dx);
|
---|
| 1133 | ColumnVector vv = ll - AA * dx;
|
---|
| 1134 |
|
---|
| 1135 | // Print Residuals
|
---|
| 1136 | // ---------------
|
---|
| 1137 | if (iPhase == 0) {
|
---|
| 1138 | strResCode = printRes(iPhase, vv, epoData->satData);
|
---|
| 1139 | }
|
---|
| 1140 | else {
|
---|
| 1141 | strResPhase = printRes(iPhase, vv, epoData->satData);
|
---|
| 1142 | }
|
---|
| 1143 |
|
---|
| 1144 | // Check the residuals
|
---|
| 1145 | // -------------------
|
---|
| 1146 | lastOutlierPrn = outlierDetection(iPhase, vv, epoData->satData);
|
---|
| 1147 |
|
---|
| 1148 | // No Outlier Detected
|
---|
| 1149 | // -------------------
|
---|
| 1150 | if (lastOutlierPrn.isEmpty()) {
|
---|
| 1151 |
|
---|
| 1152 | QVectorIterator<bncParam*> itPar(_params);
|
---|
| 1153 | while (itPar.hasNext()) {
|
---|
| 1154 | bncParam* par = itPar.next();
|
---|
| 1155 | par->xx += dx(par->index);
|
---|
| 1156 | }
|
---|
| 1157 |
|
---|
| 1158 | if (!_opt->usePhase || iPhase == 1) {
|
---|
| 1159 | if (_outlierGPS.size() > 0 || _outlierGlo.size() > 0) {
|
---|
| 1160 | _log += "Neglected PRNs: ";
|
---|
| 1161 | if (!_outlierGPS.isEmpty()) {
|
---|
| 1162 | _log += _outlierGPS.last() + ' ';
|
---|
| 1163 | }
|
---|
| 1164 | QStringListIterator itGlo(_outlierGlo);
|
---|
| 1165 | while (itGlo.hasNext()) {
|
---|
| 1166 | QString prn = itGlo.next();
|
---|
| 1167 | _log += prn + ' ';
|
---|
| 1168 | }
|
---|
| 1169 | }
|
---|
| 1170 | _log += '\n';
|
---|
| 1171 |
|
---|
| 1172 | _log += strResCode + strResPhase;
|
---|
| 1173 |
|
---|
| 1174 | return success;
|
---|
| 1175 | }
|
---|
| 1176 | }
|
---|
| 1177 |
|
---|
| 1178 | // Outlier Found
|
---|
| 1179 | // -------------
|
---|
| 1180 | else {
|
---|
| 1181 | restoreState(epoData);
|
---|
| 1182 | break;
|
---|
| 1183 | }
|
---|
| 1184 |
|
---|
| 1185 | } // for iPhase
|
---|
| 1186 |
|
---|
| 1187 | } // while selectSatellites
|
---|
| 1188 |
|
---|
| 1189 | restoreState(epoData);
|
---|
| 1190 | return failure;
|
---|
| 1191 | }
|
---|
| 1192 |
|
---|
| 1193 | // Remeber Original State Vector and Variance-Covariance Matrix
|
---|
| 1194 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1195 | void bncModel::rememberState(t_epoData* epoData) {
|
---|
| 1196 |
|
---|
| 1197 | _QQ_sav = _QQ;
|
---|
| 1198 |
|
---|
| 1199 | QVectorIterator<bncParam*> itSav(_params_sav);
|
---|
| 1200 | while (itSav.hasNext()) {
|
---|
| 1201 | bncParam* par = itSav.next();
|
---|
| 1202 | delete par;
|
---|
| 1203 | }
|
---|
| 1204 | _params_sav.clear();
|
---|
| 1205 |
|
---|
| 1206 | QVectorIterator<bncParam*> it(_params);
|
---|
| 1207 | while (it.hasNext()) {
|
---|
| 1208 | bncParam* par = it.next();
|
---|
| 1209 | _params_sav.push_back(new bncParam(*par));
|
---|
| 1210 | }
|
---|
| 1211 |
|
---|
| 1212 | _epoData_sav->deepCopy(epoData);
|
---|
| 1213 | }
|
---|
| 1214 |
|
---|
| 1215 | // Restore Original State Vector and Variance-Covariance Matrix
|
---|
| 1216 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1217 | void bncModel::restoreState(t_epoData* epoData) {
|
---|
| 1218 |
|
---|
| 1219 | _QQ = _QQ_sav;
|
---|
| 1220 |
|
---|
| 1221 | QVectorIterator<bncParam*> it(_params);
|
---|
| 1222 | while (it.hasNext()) {
|
---|
| 1223 | bncParam* par = it.next();
|
---|
| 1224 | delete par;
|
---|
| 1225 | }
|
---|
| 1226 | _params.clear();
|
---|
| 1227 |
|
---|
| 1228 | QVectorIterator<bncParam*> itSav(_params_sav);
|
---|
| 1229 | while (itSav.hasNext()) {
|
---|
| 1230 | bncParam* par = itSav.next();
|
---|
| 1231 | _params.push_back(new bncParam(*par));
|
---|
| 1232 | }
|
---|
| 1233 |
|
---|
| 1234 | epoData->deepCopy(_epoData_sav);
|
---|
| 1235 | }
|
---|
| 1236 |
|
---|
| 1237 | //
|
---|
| 1238 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1239 | t_irc bncModel::selectSatellites(const QString& lastOutlierPrn,
|
---|
| 1240 | QMap<QString, t_satData*>& satData) {
|
---|
| 1241 |
|
---|
| 1242 | // First Call
|
---|
| 1243 | // ----------
|
---|
| 1244 | if (lastOutlierPrn.isEmpty()) {
|
---|
| 1245 | _outlierGPS.clear();
|
---|
| 1246 | _outlierGlo.clear();
|
---|
| 1247 | return success;
|
---|
| 1248 | }
|
---|
| 1249 |
|
---|
| 1250 | // Second and next trials
|
---|
| 1251 | // ----------------------
|
---|
| 1252 | else {
|
---|
| 1253 |
|
---|
| 1254 | if (lastOutlierPrn[0] == 'R') {
|
---|
| 1255 | _outlierGlo << lastOutlierPrn;
|
---|
| 1256 | }
|
---|
| 1257 |
|
---|
| 1258 | // Remove all Glonass Outliers
|
---|
| 1259 | // ---------------------------
|
---|
| 1260 | QStringListIterator it(_outlierGlo);
|
---|
| 1261 | while (it.hasNext()) {
|
---|
| 1262 | QString prn = it.next();
|
---|
| 1263 | if (satData.contains(prn)) {
|
---|
| 1264 | delete satData.take(prn);
|
---|
| 1265 | }
|
---|
| 1266 | }
|
---|
| 1267 |
|
---|
| 1268 | if (lastOutlierPrn[0] == 'R') {
|
---|
| 1269 | _outlierGPS.clear();
|
---|
| 1270 | return success;
|
---|
| 1271 | }
|
---|
| 1272 |
|
---|
| 1273 | // GPS Outlier appeared for the first time - try to delete it
|
---|
| 1274 | // ----------------------------------------------------------
|
---|
| 1275 | if (_outlierGPS.indexOf(lastOutlierPrn) == -1) {
|
---|
| 1276 | _outlierGPS << lastOutlierPrn;
|
---|
| 1277 | if (satData.contains(lastOutlierPrn)) {
|
---|
| 1278 | delete satData.take(lastOutlierPrn);
|
---|
| 1279 | }
|
---|
| 1280 | return success;
|
---|
| 1281 | }
|
---|
| 1282 |
|
---|
| 1283 | }
|
---|
| 1284 |
|
---|
| 1285 | return failure;
|
---|
| 1286 | }
|
---|