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

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