source: ntrip/trunk/BNC/bncmodel.cpp@ 2571

Last change on this file since 2571 was 2569, checked in by mervart, 15 years ago
File size: 26.9 KB
RevLine 
[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
53using namespace std;
54
[2243]55const unsigned MINOBS = 4;
[2287]56const double MINELE_GPS = 10.0 * M_PI / 180.0;
57const double MINELE_GLO = 10.0 * M_PI / 180.0;
[2243]58const double MAXRES_CODE_GPS = 10.0;
59const double MAXRES_PHASE_GPS = 0.10;
[2539]60const double MAXRES_PHASE_GLO = 0.05;
[2243]61const double sig_crd_0 = 100.0;
62const double sig_crd_p = 100.0;
[2283]63const double sig_clk_0 = 1000.0;
[2489]64const double sig_trp_0 = 0.10;
65const double sig_trp_p = 1e-8;
[2540]66const double sig_amb_0_GPS = 1000.0;
[2265]67const double sig_amb_0_GLO = 1000.0;
[2286]68const double sig_L3_GPS = 0.02;
[2538]69const double sig_L3_GLO = 0.05;
[2070]70
[2057]71// Constructor
72////////////////////////////////////////////////////////////////////////////
[2080]73bncParam::bncParam(bncParam::parType typeIn, int indexIn,
74 const QString& prnIn) {
75 type = typeIn;
76 index = indexIn;
77 prn = prnIn;
78 index_old = 0;
79 xx = 0.0;
[2473]80
[2057]81}
82
83// Destructor
84////////////////////////////////////////////////////////////////////////////
85bncParam::~bncParam() {
86}
87
[2060]88// Partial
89////////////////////////////////////////////////////////////////////////////
[2239]90double bncParam::partial(t_satData* satData, bool phase) {
91
92 // Coordinates
93 // -----------
[2060]94 if (type == CRD_X) {
[2109]95 return (xx - satData->xx(1)) / satData->rho;
[2060]96 }
97 else if (type == CRD_Y) {
[2109]98 return (xx - satData->xx(2)) / satData->rho;
[2060]99 }
100 else if (type == CRD_Z) {
[2109]101 return (xx - satData->xx(3)) / satData->rho;
[2060]102 }
[2239]103
104 // Receiver Clocks
105 // ---------------
[2265]106 else if (type == RECCLK) {
107 return 1.0;
[2060]108 }
[2239]109
110 // Troposphere
111 // -----------
[2084]112 else if (type == TROPO) {
113 return 1.0 / sin(satData->eleSat);
114 }
[2239]115
116 // Ambiguities
117 // -----------
[2080]118 else if (type == AMB_L3) {
[2239]119 if (phase && satData->prn == prn) {
[2080]120 return 1.0;
121 }
122 else {
123 return 0.0;
124 }
125 }
[2239]126
127 // Default return
128 // --------------
[2060]129 return 0.0;
130}
131
[2058]132// Constructor
133////////////////////////////////////////////////////////////////////////////
[2113]134bncModel::bncModel(QByteArray staID) {
[2084]135
[2113]136 _staID = staID;
137
138 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[2548]139 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
[2113]140
[2084]141 bncSettings settings;
142
143 _static = false;
144 if ( Qt::CheckState(settings.value("pppStatic").toInt()) == Qt::Checked) {
145 _static = true;
146 }
147
148 _usePhase = false;
149 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
150 _usePhase = true;
151 }
152
153 _estTropo = false;
154 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
155 _estTropo = true;
156 }
157
158 _xcBanc.ReSize(4); _xcBanc = 0.0;
159 _ellBanc.ReSize(3); _ellBanc = 0.0;
160
[2265]161 if (_usePhase &&
162 Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
[2239]163 _useGlonass = true;
164 }
165 else {
166 _useGlonass = false;
167 }
168
169 int nextPar = 0;
[2265]170 _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
171 _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
172 _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
173 _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
[2084]174 if (_estTropo) {
[2239]175 _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
[2084]176 }
[2073]177
178 unsigned nPar = _params.size();
[2084]179
[2073]180 _QQ.ReSize(nPar);
[2239]181
[2073]182 _QQ = 0.0;
183
[2239]184 for (int iPar = 1; iPar <= _params.size(); iPar++) {
185 bncParam* pp = _params[iPar-1];
186 if (pp->isCrd()) {
187 _QQ(iPar,iPar) = sig_crd_0 * sig_crd_0;
188 }
[2265]189 else if (pp->type == bncParam::RECCLK) {
[2239]190 _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
191 }
192 else if (pp->type == bncParam::TROPO) {
193 _QQ(iPar,iPar) = sig_trp_0 * sig_trp_0;
194 }
[2077]195 }
[2125]196
197 // NMEA Output
198 // -----------
199 QString nmeaFileName = settings.value("nmeaFile").toString();
200 if (nmeaFileName.isEmpty()) {
201 _nmeaFile = 0;
202 _nmeaStream = 0;
203 }
204 else {
205 expandEnvVar(nmeaFileName);
206 _nmeaFile = new QFile(nmeaFileName);
207 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
208 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
209 }
210 else {
211 _nmeaFile->open(QIODevice::WriteOnly);
212 }
213 _nmeaStream = new QTextStream();
214 _nmeaStream->setDevice(_nmeaFile);
215 }
[2058]216}
217
218// Destructor
219////////////////////////////////////////////////////////////////////////////
220bncModel::~bncModel() {
[2126]221 delete _nmeaStream;
222 delete _nmeaFile;
[2058]223}
224
225// Bancroft Solution
226////////////////////////////////////////////////////////////////////////////
227t_irc bncModel::cmpBancroft(t_epoData* epoData) {
228
[2231]229 if (epoData->sizeGPS() < MINOBS) {
[2547]230 _log += "bncModel::cmpBancroft: not enough data\n";
[2058]231 return failure;
232 }
233
[2231]234 Matrix BB(epoData->sizeGPS(), 4);
[2058]235
[2231]236 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
[2058]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 // ----------------------------
[2231]257 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
258 while (iGPS.hasNext()) {
259 iGPS.next();
260 QString prn = iGPS.key();
261 t_satData* satData = iGPS.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
[2287]275 if (satData->eleSat < MINELE_GPS) {
[2070]276 delete satData;
[2231]277 iGPS.remove();
[2070]278 }
[2064]279 }
280
[2231]281 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
282 while (iGlo.hasNext()) {
283 iGlo.next();
284 QString prn = iGlo.key();
285 t_satData* satData = iGlo.value();
286
287 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
288 double rho = rr.norm_Frobenius();
289
290 double neu[3];
291 xyz2neu(_ellBanc.data(), rr.data(), neu);
292
293 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
294 if (neu[2] < 0) {
295 satData->eleSat *= -1.0;
296 }
297 satData->azSat = atan2(neu[1], neu[0]);
298
[2287]299 if (satData->eleSat < MINELE_GLO) {
[2231]300 delete satData;
301 iGlo.remove();
302 }
303 }
304
[2058]305 return success;
306}
[2060]307
308// Computed Value
309////////////////////////////////////////////////////////////////////////////
[2080]310double bncModel::cmpValue(t_satData* satData) {
[2060]311
[2073]312 ColumnVector xRec(3);
313 xRec(1) = x();
314 xRec(2) = y();
315 xRec(3) = z();
[2060]316
[2073]317 double rho0 = (satData->xx - xRec).norm_Frobenius();
[2060]318 double dPhi = t_CST::omega * rho0 / t_CST::c;
319
[2073]320 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
321 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
322 xRec(3) = z();
323
[2060]324 satData->rho = (satData->xx - xRec).norm_Frobenius();
325
[2084]326 double tropDelay = delay_saast(satData->eleSat) +
327 trp() / sin(satData->eleSat);
[2060]328
[2265]329 return satData->rho + clk() - satData->clk + tropDelay;
[2060]330}
331
[2063]332// Tropospheric Model (Saastamoinen)
333////////////////////////////////////////////////////////////////////////////
[2065]334double bncModel::delay_saast(double Ele) {
[2063]335
[2064]336 double height = _ellBanc(3);
[2063]337
[2064]338 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
339 double TT = 18.0 - height * 0.0065 + 273.15;
340 double hh = 50.0 * exp(-6.396e-4 * height);
[2063]341 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
342
[2064]343 double h_km = height / 1000.0;
[2063]344
345 if (h_km < 0.0) h_km = 0.0;
346 if (h_km > 5.0) h_km = 5.0;
347 int ii = int(h_km + 1);
348 double href = ii - 1;
349
350 double bCor[6];
351 bCor[0] = 1.156;
352 bCor[1] = 1.006;
353 bCor[2] = 0.874;
354 bCor[3] = 0.757;
355 bCor[4] = 0.654;
356 bCor[5] = 0.563;
357
358 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
359
360 double zen = M_PI/2.0 - Ele;
361
362 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
363}
364
[2073]365// Prediction Step of the Filter
366////////////////////////////////////////////////////////////////////////////
[2080]367void bncModel::predict(t_epoData* epoData) {
[2073]368
[2244]369 bool firstCrd = x() == 0.0 && y() == 0.0 && z() == 0.0;
370
371 // Predict Parameter values, add white noise
372 // -----------------------------------------
373 for (int iPar = 1; iPar <= _params.size(); iPar++) {
374 bncParam* pp = _params[iPar-1];
375
376 // Coordinates
377 // -----------
378 if (pp->type == bncParam::CRD_X) {
379 if (firstCrd || !_static) {
380 pp->xx = _xcBanc(1);
381 }
382 _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
383 }
384 else if (pp->type == bncParam::CRD_Y) {
385 if (firstCrd || !_static) {
386 pp->xx = _xcBanc(2);
387 }
388 _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
389 }
390 else if (pp->type == bncParam::CRD_Z) {
391 if (firstCrd || !_static) {
392 pp->xx = _xcBanc(3);
393 }
394 _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
395 }
396
397 // Receiver Clocks
398 // ---------------
[2265]399 else if (pp->type == bncParam::RECCLK) {
[2244]400 pp->xx = _xcBanc(4);
401 for (int jj = 1; jj <= _params.size(); jj++) {
402 _QQ(iPar, jj) = 0.0;
403 }
404 _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
405 }
406
407 // Tropospheric Delay
408 // ------------------
409 else if (pp->type == bncParam::TROPO) {
410 _QQ(iPar,iPar) += sig_trp_p * sig_trp_p;
411 }
412 }
413
414 // Add New Ambiguities if necessary
415 // --------------------------------
[2083]416 if (_usePhase) {
[2080]417
[2083]418 // Make a copy of QQ and xx, set parameter indices
419 // -----------------------------------------------
420 SymmetricMatrix QQ_old = _QQ;
421
422 for (int iPar = 1; iPar <= _params.size(); iPar++) {
423 _params[iPar-1]->index_old = _params[iPar-1]->index;
424 _params[iPar-1]->index = 0;
425 }
426
427 // Remove Ambiguity Parameters without observations
428 // ------------------------------------------------
429 int iPar = 0;
430 QMutableVectorIterator<bncParam*> it(_params);
431 while (it.hasNext()) {
432 bncParam* par = it.next();
433 bool removed = false;
434 if (par->type == bncParam::AMB_L3) {
[2231]435 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
436 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() ) {
[2083]437 removed = true;
438 delete par;
439 it.remove();
440 }
[2080]441 }
[2083]442 if (! removed) {
443 ++iPar;
444 par->index = iPar;
445 }
[2080]446 }
[2083]447
448 // Add new ambiguity parameters
449 // ----------------------------
[2231]450 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
451 while (iGPS.hasNext()) {
452 iGPS.next();
[2233]453 QString prn = iGPS.key();
[2244]454 t_satData* satData = iGPS.value();
[2231]455 bool found = false;
[2083]456 for (int iPar = 1; iPar <= _params.size(); iPar++) {
457 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
458 _params[iPar-1]->prn == prn) {
459 found = true;
460 break;
461 }
[2080]462 }
[2083]463 if (!found) {
464 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
465 _params.push_back(par);
[2244]466 par->xx = satData->L3 - cmpValue(satData);
[2083]467 }
[2080]468 }
[2231]469
470 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
471 while (iGlo.hasNext()) {
472 iGlo.next();
[2233]473 QString prn = iGlo.key();
474 t_satData* satData = iGlo.value();
[2231]475 bool found = false;
476 for (int iPar = 1; iPar <= _params.size(); iPar++) {
477 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
478 _params[iPar-1]->prn == prn) {
479 found = true;
480 break;
481 }
482 }
483 if (!found) {
484 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
485 _params.push_back(par);
[2244]486 par->xx = satData->L3 - cmpValue(satData);
[2231]487 }
488 }
[2083]489
490 int nPar = _params.size();
491 _QQ.ReSize(nPar); _QQ = 0.0;
492 for (int i1 = 1; i1 <= nPar; i1++) {
493 bncParam* p1 = _params[i1-1];
494 if (p1->index_old != 0) {
495 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
496 for (int i2 = 1; i2 <= nPar; i2++) {
497 bncParam* p2 = _params[i2-1];
498 if (p2->index_old != 0) {
499 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
500 }
[2080]501 }
502 }
503 }
[2083]504
505 for (int ii = 1; ii <= nPar; ii++) {
506 bncParam* par = _params[ii-1];
507 if (par->index_old == 0) {
[2265]508 if (par->prn[0] == 'R') {
509 _QQ(par->index, par->index) = sig_amb_0_GLO * sig_amb_0_GLO;
510 }
511 else {
512 _QQ(par->index, par->index) = sig_amb_0_GPS * sig_amb_0_GPS;
513 }
[2083]514 }
515 par->index_old = par->index;
[2080]516 }
517 }
518
[2073]519}
520
[2060]521// Update Step of the Filter (currently just a single-epoch solution)
522////////////////////////////////////////////////////////////////////////////
523t_irc bncModel::update(t_epoData* epoData) {
524
[2473]525 bncSettings settings;
526 double sig_P3;
527 sig_P3 = 5.0;
528 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked ) {
[2482]529 sig_P3 = settings.value("pppSigmaCode").toDouble();
[2473]530 if (sig_P3 < 0.3 || sig_P3 > 50.0) {
531 sig_P3 = 5.0;
532 }
533 }
534
[2248]535 _log.clear();
[2124]536
[2143]537 _time = epoData->tt;
538
[2547]539 _log += "Single Point Positioning of Epoch "
540 + QByteArray(_time.timestr(1).c_str()) +
541 "\n--------------------------------------------------------------\n";
542
[2112]543 SymmetricMatrix QQsav;
[2109]544 ColumnVector dx;
[2112]545 ColumnVector vv;
[2073]546
[2113]547 // Loop over all outliers
548 // ----------------------
[2108]549 do {
550
551 // Bancroft Solution
552 // -----------------
553 if (cmpBancroft(epoData) != success) {
[2124]554 emit newMessage(_log, false);
[2108]555 return failure;
556 }
[2080]557
[2108]558 // Status Prediction
559 // -----------------
560 predict(epoData);
561
[2109]562 // Create First-Design Matrix
563 // --------------------------
[2108]564 unsigned nPar = _params.size();
[2231]565 unsigned nObs = 0;
566 if (_usePhase) {
[2238]567 nObs = 2 * epoData->sizeGPS() + epoData->sizeGlo();
[2231]568 }
569 else {
570 nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
571 }
[2108]572
[2540]573 if (nObs < nPar) {
[2547]574 _log += "bncModel::update: nObs < nPar\n";
[2540]575 emit newMessage(_log, false);
576 return failure;
577 }
578
[2108]579 Matrix AA(nObs, nPar); // first design matrix
580 ColumnVector ll(nObs); // tems observed-computed
[2283]581 DiagonalMatrix PP(nObs); PP = 0.0;
[2108]582
583 unsigned iObs = 0;
[2231]584
585 // GPS code and (optionally) phase observations
586 // --------------------------------------------
587 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
588 while (itGPS.hasNext()) {
[2083]589 ++iObs;
[2231]590 itGPS.next();
591 QString prn = itGPS.key();
592 t_satData* satData = itGPS.value();
[2108]593
594 double rhoCmp = cmpValue(satData);
595
596 ll(iObs) = satData->P3 - rhoCmp;
[2244]597 PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3);
[2083]598 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[2239]599 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
[2083]600 }
[2108]601
602 if (_usePhase) {
603 ++iObs;
604 ll(iObs) = satData->L3 - rhoCmp;
[2244]605 PP(iObs,iObs) = 1.0 / (sig_L3_GPS * sig_L3_GPS);
[2108]606 for (int iPar = 1; iPar <= _params.size(); iPar++) {
607 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
608 _params[iPar-1]->prn == prn) {
[2109]609 ll(iObs) -= _params[iPar-1]->xx;
[2108]610 }
[2239]611 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
[2108]612 }
613 }
[2080]614 }
[2231]615
616 // Glonass phase observations
617 // --------------------------
618 if (_usePhase) {
619 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
620 while (itGlo.hasNext()) {
[2238]621 ++iObs;
[2231]622 itGlo.next();
623 QString prn = itGlo.key();
624 t_satData* satData = itGlo.value();
[2238]625
626 double rhoCmp = cmpValue(satData);
627
628 ll(iObs) = satData->L3 - rhoCmp;
[2242]629
[2244]630 PP(iObs,iObs) = 1.0 / (sig_L3_GLO * sig_L3_GLO);
[2238]631 for (int iPar = 1; iPar <= _params.size(); iPar++) {
632 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
633 _params[iPar-1]->prn == prn) {
634 ll(iObs) -= _params[iPar-1]->xx;
635 }
[2239]636 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
[2238]637 }
[2231]638 }
639 }
640
[2112]641 // Compute Filter Update
[2108]642 // ---------------------
[2112]643 QQsav = _QQ;
644
[2283]645 kalman(AA, ll, PP, _QQ, dx);
646
647 vv = ll - AA * dx;
648
[2547]649 ostringstream strA;
650 strA.setf(ios::fixed);
[2265]651 ColumnVector vv_code(epoData->sizeGPS());
652 ColumnVector vv_phase(epoData->sizeGPS());
653 ColumnVector vv_glo(epoData->sizeGlo());
[2245]654
[2265]655 for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
656 if (_usePhase) {
[2246]657 vv_code(iobs) = vv(2*iobs-1);
658 vv_phase(iobs) = vv(2*iobs);
659 }
[2265]660 else {
661 vv_code(iobs) = vv(iobs);
662 }
663 }
664 if (_useGlonass) {
[2246]665 for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
666 vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
667 }
[2265]668 }
[2246]669
[2547]670 strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
[2265]671 if (_usePhase) {
[2547]672 strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
[2265]673 }
674 if (_useGlonass) {
[2547]675 strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
[2246]676 }
[2547]677 _log += strA.str().c_str();
[2246]678
[2231]679 } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
[2233]680 epoData->satDataGlo) != 0);
[2111]681
[2109]682 // Set Solution Vector
683 // -------------------
[2265]684 ostringstream strB;
685 strB.setf(ios::fixed);
[2073]686 QVectorIterator<bncParam*> itPar(_params);
[2060]687 while (itPar.hasNext()) {
688 bncParam* par = itPar.next();
[2109]689 par->xx += dx(par->index);
[2265]690
691 if (par->type == bncParam::RECCLK) {
[2547]692 strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
[2124]693 << " +- " << setw(6) << setprecision(3)
694 << sqrt(_QQ(par->index,par->index));
695 }
696 else if (par->type == bncParam::AMB_L3) {
[2265]697 strB << "\n amb " << par->prn.toAscii().data() << " = "
[2124]698 << setw(6) << setprecision(3) << par->xx
699 << " +- " << setw(6) << setprecision(3)
700 << sqrt(_QQ(par->index,par->index));
701 }
[2212]702 else if (par->type == bncParam::TROPO) {
[2547]703 strB << "\n trp = " << par->prn.toAscii().data()
[2212]704 << setw(7) << setprecision(3) << delay_saast(M_PI/2.0) << " "
[2213]705 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
[2212]706 << " +- " << setw(6) << setprecision(3)
707 << sqrt(_QQ(par->index,par->index));
708 }
[2060]709 }
[2265]710 strB << '\n';
[2547]711 _log += strB.str().c_str();
712 emit newMessage(_log, false);
[2060]713
[2547]714 // Final Message (both log file and screen)
715 // ----------------------------------------
716 ostringstream strC;
717 strC.setf(ios::fixed);
718 strC << _staID.data() << " PPP "
[2231]719 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
720 << setw(14) << setprecision(3) << x() << " +- "
721 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
722 << setw(14) << setprecision(3) << y() << " +- "
723 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
724 << setw(14) << setprecision(3) << z() << " +- "
[2124]725 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
[2113]726
[2370]727 // NEU Output
728 // ----------
[2372]729 if (settings.value("pppOrigin").toString() == "X Y Z") {
[2370]730 double xyzRef[3];
731 double ellRef[3];
732 double _xyz[3];
733 double _neu[3];
734 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
735 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
736 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
737 _xyz[0] = x() - xyzRef[0];
738 _xyz[1] = y() - xyzRef[1];
739 _xyz[2] = z() - xyzRef[2];
740 xyz2ell(xyzRef, ellRef);
741 xyz2neu(ellRef, _xyz, _neu);
[2547]742 strC << " NEU "
743 << setw(8) << setprecision(3) << _neu[0] << " "
744 << setw(8) << setprecision(3) << _neu[1] << " "
745 << setw(8) << setprecision(3) << _neu[2];
[2370]746 }
747
[2547]748 strC << endl;
749
750 emit newMessage(QByteArray(strC.str().c_str()), true);
751
[2131]752 // NMEA Output
753 // -----------
[2181]754 double xyz[3];
755 xyz[0] = x();
756 xyz[1] = y();
757 xyz[2] = z();
758 double ell[3];
759 xyz2ell(xyz, ell);
760 double phiDeg = ell[0] * 180 / M_PI;
761 double lamDeg = ell[1] * 180 / M_PI;
[2132]762
[2181]763 char phiCh = 'N';
764 if (phiDeg < 0) {
765 phiDeg = -phiDeg;
766 phiCh = 'S';
767 }
768 char lamCh = 'E';
769 if (lamDeg < 0) {
[2563]770 lamDeg = -lamDeg;
771 lamCh = 'W';
[2181]772 }
[2132]773
[2566]774 string datestr = epoData->tt.datestr(0); // yyyymmdd
775 ostringstream strRMC;
776 strRMC.setf(ios::fixed);
777 strRMC << "GPRMC,"
778 << epoData->tt.timestr(0,0) << ",A,"
779 << setw(2) << setfill('0') << int(phiDeg)
780 << setw(6) << setprecision(3) << setfill('0')
781 << fmod(60*phiDeg,60) << ',' << phiCh << ','
782 << setw(3) << setfill('0') << int(lamDeg)
783 << setw(6) << setprecision(3) << setfill('0')
784 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
[2569]785 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
786 << datestr[2] << datestr[3] << ",,";
[2566]787
788 writeNMEAstr(QString(strRMC.str().c_str()));
789
[2181]790 double dop = 2.0; // TODO
[2133]791
[2566]792 ostringstream strGGA;
793 strGGA.setf(ios::fixed);
794 strGGA << "GPGGA,"
795 << epoData->tt.timestr(0,0) << ','
796 << setw(2) << setfill('0') << int(phiDeg)
797 << setw(10) << setprecision(7) << setfill('0')
798 << fmod(60*phiDeg,60) << ',' << phiCh << ','
799 << setw(3) << setfill('0') << int(lamDeg)
800 << setw(10) << setprecision(7) << setfill('0')
801 << fmod(60*lamDeg,60) << ',' << lamCh
802 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
803 << setw(3) << setprecision(1) << dop << ','
[2569]804 << setprecision(3) << ell[2] << ",M,0.0,M,,";
[2181]805
[2566]806 writeNMEAstr(QString(strGGA.str().c_str()));
[2131]807
[2060]808 return success;
809}
[2112]810
811// Outlier Detection
812////////////////////////////////////////////////////////////////////////////
813int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
814 const ColumnVector& vv,
[2231]815 QMap<QString, t_satData*>& satDataGPS,
816 QMap<QString, t_satData*>& satDataGlo) {
[2112]817
[2231]818 double vvMaxCodeGPS = 0.0;
819 double vvMaxPhaseGPS = 0.0;
820 double vvMaxPhaseGlo = 0.0;
821 QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
822 QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
823 QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
[2112]824
825 int ii = 0;
[2231]826
827 // GPS code and (optionally) phase residuals
828 // -----------------------------------------
829 QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
830 while (itGPS.hasNext()) {
831 itGPS.next();
[2112]832 ++ii;
833
[2231]834 if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
835 vvMaxCodeGPS = fabs(vv(ii));
836 itMaxCodeGPS = itGPS;
[2112]837 }
838
839 if (_usePhase) {
840 ++ii;
[2231]841 if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
842 vvMaxPhaseGPS = fabs(vv(ii));
843 itMaxPhaseGPS = itGPS;
[2112]844 }
845 }
846 }
[2231]847
[2238]848 // Glonass phase residuals
849 // -----------------------
850 if (_usePhase) {
851 QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
852 while (itGlo.hasNext()) {
853 itGlo.next();
854 ++ii;
855 if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
856 vvMaxPhaseGlo = fabs(vv(ii));
857 itMaxPhaseGlo = itGlo;
858 }
859 }
860 }
[2112]861
[2248]862 if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
863 QString prn = itMaxPhaseGlo.key();
864 t_satData* satData = itMaxPhaseGlo.value();
865 delete satData;
866 itMaxPhaseGlo.remove();
867 _QQ = QQsav;
868
[2547]869 _log += "Outlier Phase " + prn.toAscii() + " "
870 + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
[2248]871
872 return 1;
873 }
874
875 else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
[2231]876 QString prn = itMaxCodeGPS.key();
877 t_satData* satData = itMaxCodeGPS.value();
[2112]878 delete satData;
[2231]879 itMaxCodeGPS.remove();
[2112]880 _QQ = QQsav;
[2114]881
[2547]882 _log += "Outlier Code " + prn.toAscii() + " "
883 + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
[2114]884
[2112]885 return 1;
886 }
[2243]887 else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
[2231]888 QString prn = itMaxPhaseGPS.key();
889 t_satData* satData = itMaxPhaseGPS.value();
[2112]890 delete satData;
[2231]891 itMaxPhaseGPS.remove();
[2112]892 _QQ = QQsav;
[2114]893
[2547]894 _log += "Outlier Phase " + prn.toAscii() + " "
895 + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
[2114]896
[2112]897 return 1;
898 }
[2231]899
[2112]900 return 0;
901}
[2130]902
903//
904////////////////////////////////////////////////////////////////////////////
905void bncModel::writeNMEAstr(const QString& nmStr) {
906
907 unsigned char XOR = 0;
908 for (int ii = 0; ii < nmStr.length(); ii++) {
909 XOR ^= (unsigned char) nmStr[ii].toAscii();
910 }
[2181]911
912 QString outStr = '$' + nmStr
913 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
[2130]914
[2178]915 if (_nmeaStream) {
[2181]916 *_nmeaStream << outStr;
[2178]917 _nmeaStream->flush();
918 }
[2130]919
[2181]920 emit newNMEAstr(outStr.toAscii());
[2130]921}
[2283]922
923
924////
925//////////////////////////////////////////////////////////////////////////////
926void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
927 const DiagonalMatrix& PP,
928 SymmetricMatrix& QQ, ColumnVector& dx) {
929
930 int nObs = AA.Nrows();
931 int nPar = AA.Ncols();
932
933 UpperTriangularMatrix SS = Cholesky(QQ).t();
934
935 Matrix SA = SS*AA.t();
936 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
937 for (int ii = 1; ii <= nObs; ++ii) {
938 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
939 }
940
941 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
942 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
943
944 UpperTriangularMatrix UU;
945 QRZ(SRF, UU);
946
947 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
948 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
949 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
950
951 UpperTriangularMatrix SHi = SH_rt.i();
952
953 Matrix KT = SHi * YY;
954 SymmetricMatrix Hi; Hi << SHi * SHi.t();
955
956 dx = KT.t() * ll;
957 QQ << (SS.t() * SS);
958}
Note: See TracBrowser for help on using the repository browser.