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

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