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