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

Last change on this file since 2285 was 2285, checked in by mervart, 17 years ago

* empty log message *

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