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

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