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