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

Last change on this file since 2271 was 2271, checked in by mervart, 14 years ago

* empty log message *

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