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

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

* empty log message *

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