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

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

* empty log message *

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