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

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

* empty log message *

File size: 22.5 KB
RevLine 
[2057]1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncParam, bncModel
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
[2063]42#include <cmath>
[2060]43#include <newmatio.h>
[2113]44#include <sstream>
[2057]45
46#include "bncmodel.h"
[2113]47#include "bncapp.h"
[2058]48#include "bncpppclient.h"
49#include "bancroft.h"
[2063]50#include "bncutils.h"
[2077]51#include "bncsettings.h"
[2057]52
53using namespace std;
54
[2113]55const unsigned MINOBS = 4;
56const double MINELE = 10.0 * M_PI / 180.0;
57const double MAXRES_CODE = 10.0;
58const double MAXRES_PHASE = 0.10;
59const double sig_crd_0 = 100.0;
60const double sig_crd_p = 100.0;
61const double sig_clk_0 = 1000.0;
62const double sig_trp_0 = 0.01;
63const double sig_trp_p = 1e-6;
64const double sig_amb_0 = 100.0;
65const double sig_P3 = 1.0;
66const double sig_L3 = 0.01;
[2070]67
[2057]68// Constructor
69////////////////////////////////////////////////////////////////////////////
[2080]70bncParam::bncParam(bncParam::parType typeIn, int indexIn,
71 const QString& prnIn) {
72 type = typeIn;
73 index = indexIn;
74 prn = prnIn;
75 index_old = 0;
76 xx = 0.0;
[2057]77}
78
79// Destructor
80////////////////////////////////////////////////////////////////////////////
81bncParam::~bncParam() {
82}
83
[2060]84// Partial
85////////////////////////////////////////////////////////////////////////////
[2080]86double bncParam::partial(t_satData* satData, const QString& prnIn) {
[2060]87 if (type == CRD_X) {
[2109]88 return (xx - satData->xx(1)) / satData->rho;
[2060]89 }
90 else if (type == CRD_Y) {
[2109]91 return (xx - satData->xx(2)) / satData->rho;
[2060]92 }
93 else if (type == CRD_Z) {
[2109]94 return (xx - satData->xx(3)) / satData->rho;
[2060]95 }
96 else if (type == RECCLK) {
97 return 1.0;
98 }
[2084]99 else if (type == TROPO) {
100 return 1.0 / sin(satData->eleSat);
101 }
[2080]102 else if (type == AMB_L3) {
103 if (prnIn == prn) {
104 return 1.0;
105 }
106 else {
107 return 0.0;
108 }
109 }
[2060]110 return 0.0;
111}
112
[2058]113// Constructor
114////////////////////////////////////////////////////////////////////////////
[2113]115bncModel::bncModel(QByteArray staID) {
[2084]116
[2113]117 _staID = staID;
118
119 connect(this, SIGNAL(newMessage(QByteArray,bool)),
120 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
121
[2084]122 bncSettings settings;
123
124 _static = false;
125 if ( Qt::CheckState(settings.value("pppStatic").toInt()) == Qt::Checked) {
126 _static = true;
127 }
128
129 _usePhase = false;
130 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
131 _usePhase = true;
132 }
133
134 _estTropo = false;
135 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
136 _estTropo = true;
137 }
138
139 _xcBanc.ReSize(4); _xcBanc = 0.0;
140 _ellBanc.ReSize(3); _ellBanc = 0.0;
141
[2080]142 _params.push_back(new bncParam(bncParam::CRD_X, 1, ""));
143 _params.push_back(new bncParam(bncParam::CRD_Y, 2, ""));
144 _params.push_back(new bncParam(bncParam::CRD_Z, 3, ""));
145 _params.push_back(new bncParam(bncParam::RECCLK, 4, ""));
[2084]146 if (_estTropo) {
147 _params.push_back(new bncParam(bncParam::TROPO, 5, ""));
148 }
[2073]149
150 unsigned nPar = _params.size();
[2084]151
[2073]152 _QQ.ReSize(nPar);
153 _QQ = 0.0;
154
155 _QQ(1,1) = sig_crd_0 * sig_crd_0;
156 _QQ(2,2) = sig_crd_0 * sig_crd_0;
157 _QQ(3,3) = sig_crd_0 * sig_crd_0;
158 _QQ(4,4) = sig_clk_0 * sig_clk_0;
[2084]159 if (_estTropo) {
160 _QQ(5,5) = sig_trp_0 * sig_trp_0;
[2077]161 }
[2125]162
163 // NMEA Output
164 // -----------
165 QString nmeaFileName = settings.value("nmeaFile").toString();
166 if (nmeaFileName.isEmpty()) {
167 _nmeaFile = 0;
168 _nmeaStream = 0;
169 }
170 else {
171 expandEnvVar(nmeaFileName);
172 _nmeaFile = new QFile(nmeaFileName);
173 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
174 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
175 }
176 else {
177 _nmeaFile->open(QIODevice::WriteOnly);
178 }
179 _nmeaStream = new QTextStream();
180 _nmeaStream->setDevice(_nmeaFile);
[2130]181 QDateTime dateTime = QDateTime::currentDateTime().toUTC();
182 QString nmStr = "GPRMC," + dateTime.time().toString("hhmmss")
[2171]183 + ",A,,,,,,,"
[2130]184 + dateTime.date().toString("ddMMyy")
[2171]185 + ",,";
[2130]186
187 writeNMEAstr(nmStr);
[2125]188 }
[2058]189}
190
191// Destructor
192////////////////////////////////////////////////////////////////////////////
193bncModel::~bncModel() {
[2126]194 delete _nmeaStream;
195 delete _nmeaFile;
[2058]196}
197
198// Bancroft Solution
199////////////////////////////////////////////////////////////////////////////
200t_irc bncModel::cmpBancroft(t_epoData* epoData) {
201
[2231]202 if (epoData->sizeGPS() < MINOBS) {
[2124]203 _log += "\nNot enough data";
[2058]204 return failure;
205 }
206
[2231]207 Matrix BB(epoData->sizeGPS(), 4);
[2058]208
[2231]209 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
[2058]210 int iObs = 0;
211 while (it.hasNext()) {
[2060]212 ++iObs;
[2058]213 it.next();
214 QString prn = it.key();
215 t_satData* satData = it.value();
216 BB(iObs, 1) = satData->xx(1);
217 BB(iObs, 2) = satData->xx(2);
218 BB(iObs, 3) = satData->xx(3);
219 BB(iObs, 4) = satData->P3 + satData->clk;
220 }
221
222 bancroft(BB, _xcBanc);
223
[2064]224 // Ellipsoidal Coordinates
225 // ------------------------
226 xyz2ell(_xcBanc.data(), _ellBanc.data());
[2063]227
[2064]228 // Compute Satellite Elevations
229 // ----------------------------
[2231]230 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
231 while (iGPS.hasNext()) {
232 iGPS.next();
233 QString prn = iGPS.key();
234 t_satData* satData = iGPS.value();
[2063]235
[2109]236 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
237 double rho = rr.norm_Frobenius();
[2064]238
239 double neu[3];
[2109]240 xyz2neu(_ellBanc.data(), rr.data(), neu);
[2064]241
242 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
243 if (neu[2] < 0) {
244 satData->eleSat *= -1.0;
245 }
246 satData->azSat = atan2(neu[1], neu[0]);
[2070]247
248 if (satData->eleSat < MINELE) {
249 delete satData;
[2231]250 iGPS.remove();
[2070]251 }
[2064]252 }
253
[2231]254 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
255 while (iGlo.hasNext()) {
256 iGlo.next();
257 QString prn = iGlo.key();
258 t_satData* satData = iGlo.value();
259
260 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
261 double rho = rr.norm_Frobenius();
262
263 double neu[3];
264 xyz2neu(_ellBanc.data(), rr.data(), neu);
265
266 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
267 if (neu[2] < 0) {
268 satData->eleSat *= -1.0;
269 }
270 satData->azSat = atan2(neu[1], neu[0]);
271
272 if (satData->eleSat < MINELE) {
273 delete satData;
274 iGlo.remove();
275 }
276 }
277
[2058]278 return success;
279}
[2060]280
281// Computed Value
282////////////////////////////////////////////////////////////////////////////
[2080]283double bncModel::cmpValue(t_satData* satData) {
[2060]284
[2073]285 ColumnVector xRec(3);
286 xRec(1) = x();
287 xRec(2) = y();
288 xRec(3) = z();
[2060]289
[2073]290 double rho0 = (satData->xx - xRec).norm_Frobenius();
[2060]291 double dPhi = t_CST::omega * rho0 / t_CST::c;
292
[2073]293 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
294 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
295 xRec(3) = z();
296
[2060]297 satData->rho = (satData->xx - xRec).norm_Frobenius();
298
[2084]299 double tropDelay = delay_saast(satData->eleSat) +
300 trp() / sin(satData->eleSat);
[2060]301
[2073]302 return satData->rho + clk() - satData->clk + tropDelay;
[2060]303}
304
[2063]305// Tropospheric Model (Saastamoinen)
306////////////////////////////////////////////////////////////////////////////
[2065]307double bncModel::delay_saast(double Ele) {
[2063]308
[2064]309 double height = _ellBanc(3);
[2063]310
[2064]311 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
312 double TT = 18.0 - height * 0.0065 + 273.15;
313 double hh = 50.0 * exp(-6.396e-4 * height);
[2063]314 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
315
[2064]316 double h_km = height / 1000.0;
[2063]317
318 if (h_km < 0.0) h_km = 0.0;
319 if (h_km > 5.0) h_km = 5.0;
320 int ii = int(h_km + 1);
321 double href = ii - 1;
322
323 double bCor[6];
324 bCor[0] = 1.156;
325 bCor[1] = 1.006;
326 bCor[2] = 0.874;
327 bCor[3] = 0.757;
328 bCor[4] = 0.654;
329 bCor[5] = 0.563;
330
331 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
332
333 double zen = M_PI/2.0 - Ele;
334
335 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
336}
337
[2073]338// Prediction Step of the Filter
339////////////////////////////////////////////////////////////////////////////
[2080]340void bncModel::predict(t_epoData* epoData) {
[2073]341
[2083]342 if (_usePhase) {
[2080]343
[2083]344 // Make a copy of QQ and xx, set parameter indices
345 // -----------------------------------------------
346 SymmetricMatrix QQ_old = _QQ;
347
348 for (int iPar = 1; iPar <= _params.size(); iPar++) {
349 _params[iPar-1]->index_old = _params[iPar-1]->index;
350 _params[iPar-1]->index = 0;
351 }
352
353 // Remove Ambiguity Parameters without observations
354 // ------------------------------------------------
355 int iPar = 0;
356 QMutableVectorIterator<bncParam*> it(_params);
357 while (it.hasNext()) {
358 bncParam* par = it.next();
359 bool removed = false;
360 if (par->type == bncParam::AMB_L3) {
[2231]361 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
362 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() ) {
[2083]363 removed = true;
364 delete par;
365 it.remove();
366 }
[2080]367 }
[2083]368 if (! removed) {
369 ++iPar;
370 par->index = iPar;
371 }
[2080]372 }
[2083]373
374 // Add new ambiguity parameters
375 // ----------------------------
[2231]376 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
377 while (iGPS.hasNext()) {
378 iGPS.next();
[2233]379 QString prn = iGPS.key();
380 t_satData* satData = iGPS.value();
[2231]381 bool found = false;
[2083]382 for (int iPar = 1; iPar <= _params.size(); iPar++) {
383 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
384 _params[iPar-1]->prn == prn) {
385 found = true;
386 break;
387 }
[2080]388 }
[2083]389 if (!found) {
390 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
391 _params.push_back(par);
392 }
[2080]393 }
[2231]394
395 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
396 while (iGlo.hasNext()) {
397 iGlo.next();
[2233]398 QString prn = iGlo.key();
399 t_satData* satData = iGlo.value();
[2231]400 bool found = false;
401 for (int iPar = 1; iPar <= _params.size(); iPar++) {
402 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
403 _params[iPar-1]->prn == prn) {
404 found = true;
405 break;
406 }
407 }
408 if (!found) {
409 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
410 _params.push_back(par);
[2233]411 par->xx = satData->P3 - cmpValue(satData);
[2231]412 }
413 }
[2083]414
415 int nPar = _params.size();
416 _QQ.ReSize(nPar); _QQ = 0.0;
417 for (int i1 = 1; i1 <= nPar; i1++) {
418 bncParam* p1 = _params[i1-1];
419 if (p1->index_old != 0) {
420 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
421 for (int i2 = 1; i2 <= nPar; i2++) {
422 bncParam* p2 = _params[i2-1];
423 if (p2->index_old != 0) {
424 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
425 }
[2080]426 }
427 }
428 }
[2083]429
430 for (int ii = 1; ii <= nPar; ii++) {
431 bncParam* par = _params[ii-1];
432 if (par->index_old == 0) {
433 _QQ(par->index, par->index) = sig_amb_0 * sig_amb_0;
434 }
435 par->index_old = par->index;
[2080]436 }
437 }
438
[2076]439 // Coordinates
440 // -----------
441 if (_static) {
442 if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
[2109]443 _params[0]->xx = _xcBanc(1);
444 _params[1]->xx = _xcBanc(2);
445 _params[2]->xx = _xcBanc(3);
[2076]446 }
447 }
448 else {
[2109]449 _params[0]->xx = _xcBanc(1);
450 _params[1]->xx = _xcBanc(2);
451 _params[2]->xx = _xcBanc(3);
[2073]452
[2076]453 _QQ(1,1) += sig_crd_p * sig_crd_p;
454 _QQ(2,2) += sig_crd_p * sig_crd_p;
455 _QQ(3,3) += sig_crd_p * sig_crd_p;
456 }
[2073]457
[2076]458 // Receiver Clocks
459 // ---------------
[2109]460 _params[3]->xx = _xcBanc(4);
[2073]461 for (int iPar = 1; iPar <= _params.size(); iPar++) {
462 _QQ(iPar, 4) = 0.0;
463 }
464 _QQ(4,4) = sig_clk_0 * sig_clk_0;
465
[2084]466 // Tropospheric Delay
467 // ------------------
468 if (_estTropo) {
469 _QQ(5,5) += sig_trp_p * sig_trp_p;
470 }
[2073]471}
472
[2060]473// Update Step of the Filter (currently just a single-epoch solution)
474////////////////////////////////////////////////////////////////////////////
475t_irc bncModel::update(t_epoData* epoData) {
476
[2124]477 _log = "Precise Point Positioning";
478
[2143]479 _time = epoData->tt;
480
[2112]481 SymmetricMatrix QQsav;
[2109]482 ColumnVector dx;
[2112]483 ColumnVector vv;
[2073]484
[2113]485 // Loop over all outliers
486 // ----------------------
[2108]487 do {
488
489 // Bancroft Solution
490 // -----------------
491 if (cmpBancroft(epoData) != success) {
[2124]492 _log += "\nBancroft failed";
493 emit newMessage(_log, false);
[2108]494 return failure;
495 }
[2080]496
[2231]497 if (epoData->sizeGPS() < MINOBS) {
[2124]498 _log += "\nNot enough data";
499 emit newMessage(_log, false);
[2116]500 return failure;
501 }
502
[2108]503 // Status Prediction
504 // -----------------
505 predict(epoData);
506
[2109]507 // Create First-Design Matrix
508 // --------------------------
[2108]509 unsigned nPar = _params.size();
[2231]510 unsigned nObs = 0;
511 if (_usePhase) {
[2233]512 nObs = 2 * epoData->sizeGPS(); // TODO: + epoData->sizeGlo();
[2231]513 }
514 else {
515 nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
516 }
[2108]517
518 Matrix AA(nObs, nPar); // first design matrix
519 ColumnVector ll(nObs); // tems observed-computed
520 SymmetricMatrix PP(nObs); PP = 0.0;
521
522 unsigned iObs = 0;
[2231]523
524 // GPS code and (optionally) phase observations
525 // --------------------------------------------
526 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
527 while (itGPS.hasNext()) {
[2083]528 ++iObs;
[2231]529 itGPS.next();
530 QString prn = itGPS.key();
531 t_satData* satData = itGPS.value();
[2108]532
533 double rhoCmp = cmpValue(satData);
534
[2117]535 double ellWgtCoeff = 1.0;
[2118]536 //// double eleD = satData->eleSat * 180.0 / M_PI;
537 //// if (eleD < 25.0) {
538 //// ellWgtCoeff = 2.5 - (eleD - 10.0) * 0.1;
539 //// ellWgtCoeff *= ellWgtCoeff;
540 //// }
[2117]541
[2108]542 ll(iObs) = satData->P3 - rhoCmp;
[2117]543 PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3) / ellWgtCoeff;
[2083]544 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[2108]545 AA(iObs, iPar) = _params[iPar-1]->partial(satData, "");
[2083]546 }
[2108]547
548 if (_usePhase) {
549 ++iObs;
550 ll(iObs) = satData->L3 - rhoCmp;
[2117]551 PP(iObs,iObs) = 1.0 / (sig_L3 * sig_L3) / ellWgtCoeff;
[2108]552 for (int iPar = 1; iPar <= _params.size(); iPar++) {
553 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
554 _params[iPar-1]->prn == prn) {
[2109]555 ll(iObs) -= _params[iPar-1]->xx;
[2108]556 }
557 AA(iObs, iPar) = _params[iPar-1]->partial(satData, prn);
558 }
559 }
[2080]560 }
[2231]561
562 // Glonass phase observations
563 // --------------------------
564 if (_usePhase) {
565 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
566 while (itGlo.hasNext()) {
[2233]567 //// TODO ++iObs;
[2231]568 itGlo.next();
569 QString prn = itGlo.key();
570 t_satData* satData = itGlo.value();
571
[2233]572 //// beg test
[2231]573 double rhoCmp = cmpValue(satData);
[2233]574 cout.setf(ios::fixed);
575 cout << prn.toAscii().data() << " "
576 << setprecision(3) << rhoCmp << " "
577 << setprecision(3) << satData->P3 << " "
578 << setprecision(3) << satData->L3 << " " << endl;
[2232]579
580 //// end test
[2231]581 }
582 }
583
[2112]584 // Compute Filter Update
[2108]585 // ---------------------
[2112]586 QQsav = _QQ;
587
588 Matrix ATP = AA.t() * PP;
[2109]589 SymmetricMatrix NN = _QQ.i();
[2112]590 NN << NN + ATP * AA;
591 _QQ = NN.i();
592 dx = _QQ * ATP * ll;
593 vv = ll - AA * dx;
[2060]594
[2231]595 } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
[2233]596 epoData->satDataGlo) != 0);
[2111]597
[2109]598 // Set Solution Vector
599 // -------------------
[2124]600 ostringstream str1;
601 str1.setf(ios::fixed);
[2073]602 QVectorIterator<bncParam*> itPar(_params);
[2060]603 while (itPar.hasNext()) {
604 bncParam* par = itPar.next();
[2109]605 par->xx += dx(par->index);
[2124]606 if (par->type == bncParam::RECCLK) {
607 str1 << "\n clk = " << setw(6) << setprecision(3) << par->xx
608 << " +- " << setw(6) << setprecision(3)
609 << sqrt(_QQ(par->index,par->index));
610 }
611 else if (par->type == bncParam::AMB_L3) {
612 str1 << "\n amb " << par->prn.toAscii().data() << " = "
613 << setw(6) << setprecision(3) << par->xx
614 << " +- " << setw(6) << setprecision(3)
615 << sqrt(_QQ(par->index,par->index));
616 }
[2212]617 else if (par->type == bncParam::TROPO) {
618 str1 << "\n trp = " << par->prn.toAscii().data()
619 << setw(7) << setprecision(3) << delay_saast(M_PI/2.0) << " "
[2213]620 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
[2212]621 << " +- " << setw(6) << setprecision(3)
622 << sqrt(_QQ(par->index,par->index));
623 }
[2060]624 }
[2124]625 _log += str1.str().c_str();
[2060]626
[2113]627 // Message (both log file and screen)
628 // ----------------------------------
[2124]629 ostringstream str2;
630 str2.setf(ios::fixed);
[2165]631 str2 << _staID.data() << ": PPP "
[2231]632 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
633 << setw(14) << setprecision(3) << x() << " +- "
634 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
635 << setw(14) << setprecision(3) << y() << " +- "
636 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
637 << setw(14) << setprecision(3) << z() << " +- "
[2124]638 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
[2114]639 if (_estTropo) {
[2231]640 str2 << " " << setw(6) << setprecision(3) << trp() << " +- "
[2124]641 << setw(6) << setprecision(3) << sqrt(_QQ(5,5));
[2114]642 }
[2113]643
[2124]644 emit newMessage(_log, false);
645 emit newMessage(QByteArray(str2.str().c_str()), true);
[2113]646
[2131]647 // NMEA Output
648 // -----------
[2181]649 double xyz[3];
650 xyz[0] = x();
651 xyz[1] = y();
652 xyz[2] = z();
653 double ell[3];
654 xyz2ell(xyz, ell);
655 double phiDeg = ell[0] * 180 / M_PI;
656 double lamDeg = ell[1] * 180 / M_PI;
[2132]657
[2181]658 char phiCh = 'N';
659 if (phiDeg < 0) {
660 phiDeg = -phiDeg;
661 phiCh = 'S';
662 }
663 char lamCh = 'E';
664 if (lamDeg < 0) {
665 lamDeg = -lamDeg;
666 lamCh = 'W';
667 }
[2132]668
[2181]669 double dop = 2.0; // TODO
[2133]670
[2181]671 ostringstream str3;
672 str3.setf(ios::fixed);
673 str3 << "GPGGA,"
674 << epoData->tt.timestr(0,0) << ','
675 << setw(2) << setfill('0') << int(phiDeg)
676 << setw(10) << setprecision(7) << setfill('0')
677 << fmod(60*phiDeg,60) << ',' << phiCh << ','
678 << setw(2) << setfill('0') << int(lamDeg)
679 << setw(10) << setprecision(7) << setfill('0')
680 << fmod(60*lamDeg,60) << ',' << lamCh
[2231]681 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
[2181]682 << setw(3) << setprecision(1) << dop << ','
683 << setprecision(3) << ell[2] << ",M,0.0,M,,,";
684
685 writeNMEAstr(QString(str3.str().c_str()));
[2131]686
[2060]687 return success;
688}
[2112]689
690// Outlier Detection
691////////////////////////////////////////////////////////////////////////////
692int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
693 const ColumnVector& vv,
[2231]694 QMap<QString, t_satData*>& satDataGPS,
695 QMap<QString, t_satData*>& satDataGlo) {
[2112]696
[2231]697 double vvMaxCodeGPS = 0.0;
698 double vvMaxPhaseGPS = 0.0;
699 double vvMaxPhaseGlo = 0.0;
700 QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
701 QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
702 QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
[2112]703
704 int ii = 0;
[2231]705
706 // GPS code and (optionally) phase residuals
707 // -----------------------------------------
708 QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
709 while (itGPS.hasNext()) {
710 itGPS.next();
[2112]711 ++ii;
712
[2231]713 if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
714 vvMaxCodeGPS = fabs(vv(ii));
715 itMaxCodeGPS = itGPS;
[2112]716 }
717
718 if (_usePhase) {
719 ++ii;
[2231]720 if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
721 vvMaxPhaseGPS = fabs(vv(ii));
722 itMaxPhaseGPS = itGPS;
[2112]723 }
724 }
725 }
[2231]726
[2233]727//// // Glonass phase residuals
728//// // -----------------------
729//// if (_usePhase) {
730//// QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
731//// while (itGlo.hasNext()) {
732//// itGlo.next();
733//// ++ii;
734//// if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
735//// vvMaxPhaseGlo = fabs(vv(ii));
736//// itMaxPhaseGlo = itGlo;
737//// }
738//// }
739//// }
[2112]740
[2231]741 if (vvMaxCodeGPS > MAXRES_CODE) {
742 QString prn = itMaxCodeGPS.key();
743 t_satData* satData = itMaxCodeGPS.value();
[2112]744 delete satData;
[2231]745 itMaxCodeGPS.remove();
[2112]746 _QQ = QQsav;
[2114]747
[2124]748 _log += "\nOutlier Code " + prn.toAscii() + " "
[2231]749 + QByteArray::number(vvMaxCodeGPS, 'f', 3);
[2114]750
[2112]751 return 1;
752 }
[2231]753 else if (vvMaxPhaseGPS > MAXRES_PHASE) {
754 QString prn = itMaxPhaseGPS.key();
755 t_satData* satData = itMaxPhaseGPS.value();
[2112]756 delete satData;
[2231]757 itMaxPhaseGPS.remove();
[2112]758 _QQ = QQsav;
[2114]759
[2124]760 _log += "\nOutlier Phase " + prn.toAscii() + " "
[2231]761 + QByteArray::number(vvMaxPhaseGPS, 'f', 3);
[2114]762
[2112]763 return 1;
764 }
[2231]765 else if (vvMaxPhaseGlo > MAXRES_PHASE) {
766 QString prn = itMaxPhaseGlo.key();
767 t_satData* satData = itMaxPhaseGlo.value();
768 delete satData;
769 itMaxPhaseGlo.remove();
770 _QQ = QQsav;
771
772 _log += "\nOutlier Phase " + prn.toAscii() + " "
773 + QByteArray::number(vvMaxPhaseGlo, 'f', 3);
774
775 return 1;
776 }
777
[2112]778 return 0;
779}
[2130]780
781//
782////////////////////////////////////////////////////////////////////////////
783void bncModel::writeNMEAstr(const QString& nmStr) {
784
785 unsigned char XOR = 0;
786 for (int ii = 0; ii < nmStr.length(); ii++) {
787 XOR ^= (unsigned char) nmStr[ii].toAscii();
788 }
[2181]789
790 QString outStr = '$' + nmStr
791 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
[2130]792
[2178]793 if (_nmeaStream) {
[2181]794 *_nmeaStream << outStr;
[2178]795 _nmeaStream->flush();
796 }
[2130]797
[2181]798 emit newNMEAstr(outStr.toAscii());
[2130]799}
Note: See TracBrowser for help on using the repository browser.