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

Last change on this file since 2787 was 2787, checked in by mervart, 13 years ago
File size: 40.1 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#include "bnctides.h"
53
54using namespace std;
55
56const unsigned MINOBS = 4;
57const double MINELE_GPS = 10.0 * M_PI / 180.0;
58const double MINELE_GLO = 10.0 * M_PI / 180.0;
59const double MINELE_GAL = 10.0 * M_PI / 180.0;
60const double MAXRES_CODE_GPS = 10.0;
61const double MAXRES_PHASE_GPS = 0.10;
62const double MAXRES_PHASE_GLO = 0.05;
63const double MAXRES_CODE_GAL = 10.0;
64const double MAXRES_PHASE_GAL = 0.10;
65
66// Constructor
67////////////////////////////////////////////////////////////////////////////
68bncParam::bncParam(bncParam::parType typeIn, int indexIn,
69 const QString& prnIn) {
70 type = typeIn;
71 index = indexIn;
72 prn = prnIn;
73 index_old = 0;
74 xx = 0.0;
75
76}
77
78// Destructor
79////////////////////////////////////////////////////////////////////////////
80bncParam::~bncParam() {
81}
82
83// Partial
84////////////////////////////////////////////////////////////////////////////
85double bncParam::partial(t_satData* satData, bool phase) {
86
87 // Coordinates
88 // -----------
89 if (type == CRD_X) {
90 return (xx - satData->xx(1)) / satData->rho;
91 }
92 else if (type == CRD_Y) {
93 return (xx - satData->xx(2)) / satData->rho;
94 }
95 else if (type == CRD_Z) {
96 return (xx - satData->xx(3)) / satData->rho;
97 }
98
99 // Receiver Clocks
100 // ---------------
101 else if (type == RECCLK) {
102 return 1.0;
103 }
104
105 // Troposphere
106 // -----------
107 else if (type == TROPO) {
108 return 1.0 / sin(satData->eleSat);
109 }
110
111 // Galileo Offset
112 // --------------
113 else if (type == GALILEO_OFFSET) {
114 if (satData->prn[0] == 'E') {
115 return 1.0;
116 }
117 else {
118 return 0.0;
119 }
120 }
121
122 // Ambiguities
123 // -----------
124 else if (type == AMB_L3) {
125 if (phase && satData->prn == prn) {
126 return 1.0;
127 }
128 else {
129 return 0.0;
130 }
131 }
132
133 // Default return
134 // --------------
135 return 0.0;
136}
137
138// Constructor
139////////////////////////////////////////////////////////////////////////////
140bncModel::bncModel(QByteArray staID) {
141
142 _staID = staID;
143
144 bncSettings settings;
145
146 // Observation Sigmas
147 // ------------------
148 _sigP3 = 5.0;
149 if (!settings.value("pppSigmaCode").toString().isEmpty()) {
150 _sigP3 = settings.value("pppSigmaCode").toDouble();
151 }
152 _sigL3 = 0.02;
153 if (!settings.value("pppSigmaPhase").toString().isEmpty()) {
154 _sigL3 = settings.value("pppSigmaPhase").toDouble();
155 }
156
157 // Parameter Sigmas
158 // ----------------
159 _sigCrd0 = 100.0;
160 if (!settings.value("pppSigCrd0").toString().isEmpty()) {
161 _sigCrd0 = settings.value("pppSigCrd0").toDouble();
162 }
163 _sigCrdP = 100.0;
164 if (!settings.value("pppSigCrdP").toString().isEmpty()) {
165 _sigCrdP = settings.value("pppSigCrdP").toDouble();
166 }
167 _sigTrp0 = 0.1;
168 if (!settings.value("pppSigTrp0").toString().isEmpty()) {
169 _sigTrp0 = settings.value("pppSigTrp0").toDouble();
170 }
171 _sigTrpP = 1e-6;
172 if (!settings.value("pppSigTrpP").toString().isEmpty()) {
173 _sigTrpP = settings.value("pppSigTrpP").toDouble();
174 }
175 _sigClk0 = 1000.0;
176 _sigAmb0 = 1000.0;
177 _sigGalileoOffset0 = 1000.0;
178 _sigGalileoOffsetP = 0.0;
179
180 // Quick-Start Mode
181 // ----------------
182 _quickStart = 0;
183 if (settings.value("pppRefCrdX").toString() != "" &&
184 settings.value("pppRefCrdY").toString() != "" &&
185 settings.value("pppRefCrdZ").toString() != "" &&
186 !settings.value("pppQuickStart").toString().isEmpty()) {
187 _quickStart = settings.value("pppQuickStart").toDouble();
188 }
189
190 connect(this, SIGNAL(newMessage(QByteArray,bool)),
191 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
192
193 _usePhase = false;
194 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
195 _usePhase = true;
196 }
197
198 _estTropo = false;
199 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
200 _estTropo = true;
201 }
202
203 _xcBanc.ReSize(4); _xcBanc = 0.0;
204 _ellBanc.ReSize(3); _ellBanc = 0.0;
205
206 if (_usePhase &&
207 Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
208 _useGlonass = true;
209 }
210 else {
211 _useGlonass = false;
212 }
213
214 if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
215 _useGalileo = true;
216 }
217 else {
218 _useGalileo = false;
219 }
220
221 int nextPar = 0;
222 _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
223 _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
224 _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
225 _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
226 if (_estTropo) {
227 _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
228 }
229 if (_useGalileo) {
230 _params.push_back(new bncParam(bncParam::GALILEO_OFFSET, ++nextPar, ""));
231 }
232
233 unsigned nPar = _params.size();
234
235 _QQ.ReSize(nPar);
236
237 _QQ = 0.0;
238
239 for (int iPar = 1; iPar <= _params.size(); iPar++) {
240 bncParam* pp = _params[iPar-1];
241 if (pp->isCrd()) {
242 _QQ(iPar,iPar) = _sigCrd0 * _sigCrd0;
243 }
244 else if (pp->type == bncParam::RECCLK) {
245 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
246 }
247 else if (pp->type == bncParam::TROPO) {
248 _QQ(iPar,iPar) = _sigTrp0 * _sigTrp0;
249 }
250 else if (pp->type == bncParam::GALILEO_OFFSET) {
251 _QQ(iPar,iPar) = _sigGalileoOffset0 * _sigGalileoOffset0;
252 }
253 }
254
255 // NMEA Output
256 // -----------
257 QString nmeaFileName = settings.value("nmeaFile").toString();
258 if (nmeaFileName.isEmpty()) {
259 _nmeaFile = 0;
260 _nmeaStream = 0;
261 }
262 else {
263 expandEnvVar(nmeaFileName);
264 _nmeaFile = new QFile(nmeaFileName);
265 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
266 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
267 }
268 else {
269 _nmeaFile->open(QIODevice::WriteOnly);
270 }
271 _nmeaStream = new QTextStream();
272 _nmeaStream->setDevice(_nmeaFile);
273 }
274}
275
276// Destructor
277////////////////////////////////////////////////////////////////////////////
278bncModel::~bncModel() {
279 delete _nmeaStream;
280 delete _nmeaFile;
281 for (int ii = 0; ii < _posAverage.size(); ++ii) {
282 delete _posAverage[ii];
283 }
284}
285
286// Bancroft Solution
287////////////////////////////////////////////////////////////////////////////
288t_irc bncModel::cmpBancroft(t_epoData* epoData) {
289
290 if (epoData->sizeGPS() < MINOBS) {
291 _log += "bncModel::cmpBancroft: not enough data\n";
292 return failure;
293 }
294
295 Matrix BB(epoData->sizeGPS(), 4);
296
297 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
298 int iObs = 0;
299 while (it.hasNext()) {
300 ++iObs;
301 it.next();
302 QString prn = it.key();
303 t_satData* satData = it.value();
304 BB(iObs, 1) = satData->xx(1);
305 BB(iObs, 2) = satData->xx(2);
306 BB(iObs, 3) = satData->xx(3);
307 BB(iObs, 4) = satData->P3 + satData->clk;
308 }
309
310 bancroft(BB, _xcBanc);
311
312 // Ellipsoidal Coordinates
313 // ------------------------
314 xyz2ell(_xcBanc.data(), _ellBanc.data());
315
316 // Compute Satellite Elevations
317 // ----------------------------
318 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
319 while (iGPS.hasNext()) {
320 iGPS.next();
321 QString prn = iGPS.key();
322 t_satData* satData = iGPS.value();
323
324 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
325 double rho = rr.norm_Frobenius();
326
327 double neu[3];
328 xyz2neu(_ellBanc.data(), rr.data(), neu);
329
330 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
331 if (neu[2] < 0) {
332 satData->eleSat *= -1.0;
333 }
334 satData->azSat = atan2(neu[1], neu[0]);
335
336 if (satData->eleSat < MINELE_GPS) {
337 delete satData;
338 iGPS.remove();
339 }
340 }
341
342 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
343 while (iGlo.hasNext()) {
344 iGlo.next();
345 QString prn = iGlo.key();
346 t_satData* satData = iGlo.value();
347
348 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
349 double rho = rr.norm_Frobenius();
350
351 double neu[3];
352 xyz2neu(_ellBanc.data(), rr.data(), neu);
353
354 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
355 if (neu[2] < 0) {
356 satData->eleSat *= -1.0;
357 }
358 satData->azSat = atan2(neu[1], neu[0]);
359
360 if (satData->eleSat < MINELE_GLO) {
361 delete satData;
362 iGlo.remove();
363 }
364 }
365
366 QMutableMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
367 while (iGal.hasNext()) {
368 iGal.next();
369 QString prn = iGal.key();
370 t_satData* satData = iGal.value();
371
372 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
373 double rho = rr.norm_Frobenius();
374
375 double neu[3];
376 xyz2neu(_ellBanc.data(), rr.data(), neu);
377
378 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
379 if (neu[2] < 0) {
380 satData->eleSat *= -1.0;
381 }
382 satData->azSat = atan2(neu[1], neu[0]);
383
384 if (satData->eleSat < MINELE_GAL) {
385 delete satData;
386 iGal.remove();
387 }
388 }
389
390 return success;
391}
392
393// Computed Value
394////////////////////////////////////////////////////////////////////////////
395double bncModel::cmpValue(t_satData* satData, bool phase) {
396
397 ColumnVector xRec(3);
398 xRec(1) = x();
399 xRec(2) = y();
400 xRec(3) = z();
401
402 double rho0 = (satData->xx - xRec).norm_Frobenius();
403 double dPhi = t_CST::omega * rho0 / t_CST::c;
404
405 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
406 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
407 xRec(3) = z();
408
409 tides(_time, xRec);
410
411 satData->rho = (satData->xx - xRec).norm_Frobenius();
412
413 double tropDelay = delay_saast(satData->eleSat) +
414 trp() / sin(satData->eleSat);
415
416 double wind = 0.0;
417 if (phase) {
418 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
419 }
420
421 double offset = 0.0;
422 if (satData->prn[0] == 'E') {
423 offset = Galileo_offset();
424 }
425
426 return satData->rho + clk() + offset - satData->clk + tropDelay + wind;
427}
428
429// Tropospheric Model (Saastamoinen)
430////////////////////////////////////////////////////////////////////////////
431double bncModel::delay_saast(double Ele) {
432
433 double xyz[3];
434 xyz[0] = x();
435 xyz[1] = y();
436 xyz[2] = z();
437 double ell[3];
438 xyz2ell(xyz, ell);
439 double height = ell[2];
440
441 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
442 double TT = 18.0 - height * 0.0065 + 273.15;
443 double hh = 50.0 * exp(-6.396e-4 * height);
444 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
445
446 double h_km = height / 1000.0;
447
448 if (h_km < 0.0) h_km = 0.0;
449 if (h_km > 5.0) h_km = 5.0;
450 int ii = int(h_km + 1);
451 double href = ii - 1;
452
453 double bCor[6];
454 bCor[0] = 1.156;
455 bCor[1] = 1.006;
456 bCor[2] = 0.874;
457 bCor[3] = 0.757;
458 bCor[4] = 0.654;
459 bCor[5] = 0.563;
460
461 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
462
463 double zen = M_PI/2.0 - Ele;
464
465 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
466}
467
468// Prediction Step of the Filter
469////////////////////////////////////////////////////////////////////////////
470void bncModel::predict(t_epoData* epoData) {
471
472 bncSettings settings;
473
474 bool firstCrd = false;
475 if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
476 firstCrd = true;
477 _startTime = QDateTime::currentDateTime();
478 }
479
480 // Use different white noise for Quick-Start mode
481 // ----------------------------------------------
482 double sigCrdP_used = _sigCrdP;
483 if ( _quickStart > 0.0 &&
484 _quickStart > _startTime.secsTo(QDateTime::currentDateTime()) ) {
485 sigCrdP_used = 0.0;
486 }
487
488 // Predict Parameter values, add white noise
489 // -----------------------------------------
490 for (int iPar = 1; iPar <= _params.size(); iPar++) {
491 bncParam* pp = _params[iPar-1];
492
493 // Coordinates
494 // -----------
495 if (pp->type == bncParam::CRD_X) {
496 if (firstCrd) {
497 if (settings.value("pppRefCrdX").toString() != "" &&
498 settings.value("pppRefCrdY").toString() != "" &&
499 settings.value("pppRefCrdZ").toString() != "") {
500 pp->xx = settings.value("pppRefCrdX").toDouble();
501 }
502 else {
503 pp->xx = _xcBanc(1);
504 }
505 }
506 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
507 }
508 else if (pp->type == bncParam::CRD_Y) {
509 if (firstCrd) {
510 if (settings.value("pppRefCrdX").toString() != "" &&
511 settings.value("pppRefCrdY").toString() != "" &&
512 settings.value("pppRefCrdZ").toString() != "") {
513 pp->xx = settings.value("pppRefCrdY").toDouble();
514 }
515 else {
516 pp->xx = _xcBanc(2);
517 }
518 }
519 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
520 }
521 else if (pp->type == bncParam::CRD_Z) {
522 if (firstCrd) {
523 if (settings.value("pppRefCrdX").toString() != "" &&
524 settings.value("pppRefCrdY").toString() != "" &&
525 settings.value("pppRefCrdZ").toString() != "") {
526 pp->xx = settings.value("pppRefCrdZ").toDouble();
527 }
528 else {
529 pp->xx = _xcBanc(3);
530 }
531 }
532 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
533 }
534
535 // Receiver Clocks
536 // ---------------
537 else if (pp->type == bncParam::RECCLK) {
538 pp->xx = _xcBanc(4);
539 for (int jj = 1; jj <= _params.size(); jj++) {
540 _QQ(iPar, jj) = 0.0;
541 }
542 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
543 }
544
545 // Tropospheric Delay
546 // ------------------
547 else if (pp->type == bncParam::TROPO) {
548 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
549 }
550
551 // Galileo Offset
552 // --------------
553 else if (pp->type == bncParam::GALILEO_OFFSET) {
554 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
555 }
556 }
557
558 // Add New Ambiguities if necessary
559 // --------------------------------
560 if (_usePhase) {
561
562 // Make a copy of QQ and xx, set parameter indices
563 // -----------------------------------------------
564 SymmetricMatrix QQ_old = _QQ;
565
566 for (int iPar = 1; iPar <= _params.size(); iPar++) {
567 _params[iPar-1]->index_old = _params[iPar-1]->index;
568 _params[iPar-1]->index = 0;
569 }
570
571 // Remove Ambiguity Parameters without observations
572 // ------------------------------------------------
573 int iPar = 0;
574 QMutableVectorIterator<bncParam*> it(_params);
575 while (it.hasNext()) {
576 bncParam* par = it.next();
577 bool removed = false;
578 if (par->type == bncParam::AMB_L3) {
579 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
580 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() &&
581 epoData->satDataGal.find(par->prn) == epoData->satDataGal.end() ) {
582 removed = true;
583 delete par;
584 it.remove();
585 }
586 }
587 if (! removed) {
588 ++iPar;
589 par->index = iPar;
590 }
591 }
592
593 // Add new ambiguity parameters
594 // ----------------------------
595 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
596 while (iGPS.hasNext()) {
597 iGPS.next();
598 QString prn = iGPS.key();
599 t_satData* satData = iGPS.value();
600 bool found = false;
601 for (int iPar = 1; iPar <= _params.size(); iPar++) {
602 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
603 _params[iPar-1]->prn == prn) {
604 found = true;
605 break;
606 }
607 }
608 if (!found) {
609 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
610 _params.push_back(par);
611 par->xx = satData->L3 - cmpValue(satData, true);
612 }
613 }
614
615 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
616 while (iGlo.hasNext()) {
617 iGlo.next();
618 QString prn = iGlo.key();
619 t_satData* satData = iGlo.value();
620 bool found = false;
621 for (int iPar = 1; iPar <= _params.size(); iPar++) {
622 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
623 _params[iPar-1]->prn == prn) {
624 found = true;
625 break;
626 }
627 }
628 if (!found) {
629 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
630 _params.push_back(par);
631 par->xx = satData->L3 - cmpValue(satData, true);
632 }
633 }
634
635 QMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
636 while (iGal.hasNext()) {
637 iGal.next();
638 QString prn = iGal.key();
639 t_satData* satData = iGal.value();
640 bool found = false;
641 for (int iPar = 1; iPar <= _params.size(); iPar++) {
642 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
643 _params[iPar-1]->prn == prn) {
644 found = true;
645 break;
646 }
647 }
648 if (!found) {
649 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
650 _params.push_back(par);
651 par->xx = satData->L3 - cmpValue(satData, true);
652 }
653 }
654
655 int nPar = _params.size();
656 _QQ.ReSize(nPar); _QQ = 0.0;
657 for (int i1 = 1; i1 <= nPar; i1++) {
658 bncParam* p1 = _params[i1-1];
659 if (p1->index_old != 0) {
660 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
661 for (int i2 = 1; i2 <= nPar; i2++) {
662 bncParam* p2 = _params[i2-1];
663 if (p2->index_old != 0) {
664 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
665 }
666 }
667 }
668 }
669
670 for (int ii = 1; ii <= nPar; ii++) {
671 bncParam* par = _params[ii-1];
672 if (par->index_old == 0) {
673 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
674 }
675 par->index_old = par->index;
676 }
677 }
678}
679
680// Update Step of the Filter (currently just a single-epoch solution)
681////////////////////////////////////////////////////////////////////////////
682t_irc bncModel::update(t_epoData* epoData) {
683
684 bncSettings settings;
685
686 _log.clear();
687
688 _time = epoData->tt;
689
690 _log += "Single Point Positioning of Epoch "
691 + QByteArray(_time.timestr(1).c_str()) +
692 "\n--------------------------------------------------------------\n";
693
694 SymmetricMatrix QQsav;
695 ColumnVector dx;
696 ColumnVector vv;
697
698 // Loop over all outliers
699 // ----------------------
700 do {
701
702 // Bancroft Solution
703 // -----------------
704 if (cmpBancroft(epoData) != success) {
705 emit newMessage(_log, false);
706 return failure;
707 }
708
709 // Status Prediction
710 // -----------------
711 predict(epoData);
712
713 // Create First-Design Matrix
714 // --------------------------
715 unsigned nPar = _params.size();
716 unsigned nObs = 0;
717 if (_usePhase) {
718 nObs = 2 * (epoData->sizeGPS() + epoData->sizeGal()) + epoData->sizeGlo();
719 }
720 else {
721 nObs = epoData->sizeGPS() + epoData->sizeGal(); // Glonass code not used
722 }
723
724 if (nObs < nPar) {
725 _log += "bncModel::update: nObs < nPar\n";
726 emit newMessage(_log, false);
727 return failure;
728 }
729
730 Matrix AA(nObs, nPar); // first design matrix
731 ColumnVector ll(nObs); // tems observed-computed
732 DiagonalMatrix PP(nObs); PP = 0.0;
733
734 unsigned iObs = 0;
735
736 // GPS code and (optionally) phase observations
737 // --------------------------------------------
738 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
739 while (itGPS.hasNext()) {
740 ++iObs;
741 itGPS.next();
742 QString prn = itGPS.key();
743 t_satData* satData = itGPS.value();
744
745 ll(iObs) = satData->P3 - cmpValue(satData, false);
746 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3);
747 for (int iPar = 1; iPar <= _params.size(); iPar++) {
748 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
749 }
750
751 if (_usePhase) {
752 ++iObs;
753 ll(iObs) = satData->L3 - cmpValue(satData, true);
754 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
755 for (int iPar = 1; iPar <= _params.size(); iPar++) {
756 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
757 _params[iPar-1]->prn == prn) {
758 ll(iObs) -= _params[iPar-1]->xx;
759 }
760 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
761 }
762 }
763 }
764
765 // Glonass phase observations
766 // --------------------------
767 if (_usePhase) {
768 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
769 while (itGlo.hasNext()) {
770 ++iObs;
771 itGlo.next();
772 QString prn = itGlo.key();
773 t_satData* satData = itGlo.value();
774
775 ll(iObs) = satData->L3 - cmpValue(satData, true);
776 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
777 for (int iPar = 1; iPar <= _params.size(); iPar++) {
778 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
779 _params[iPar-1]->prn == prn) {
780 ll(iObs) -= _params[iPar-1]->xx;
781 }
782 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
783 }
784 }
785 }
786
787 // Galileo code and (optionally) phase observations
788 // ------------------------------------------------
789 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
790 while (itGal.hasNext()) {
791 ++iObs;
792 itGal.next();
793 QString prn = itGal.key();
794 t_satData* satData = itGal.value();
795
796 ll(iObs) = satData->P3 - cmpValue(satData, false);
797 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3);
798 for (int iPar = 1; iPar <= _params.size(); iPar++) {
799 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
800 }
801
802 if (_usePhase) {
803 ++iObs;
804 ll(iObs) = satData->L3 - cmpValue(satData, true);
805 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
806 for (int iPar = 1; iPar <= _params.size(); iPar++) {
807 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
808 _params[iPar-1]->prn == prn) {
809 ll(iObs) -= _params[iPar-1]->xx;
810 }
811 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
812 }
813 }
814 }
815
816 // Compute Filter Update
817 // ---------------------
818 QQsav = _QQ;
819
820 kalman(AA, ll, PP, _QQ, dx);
821
822 vv = ll - AA * dx;
823
824 ostringstream strA;
825 strA.setf(ios::fixed);
826 ColumnVector vv_code(epoData->sizeGPS());
827 ColumnVector vv_phase(epoData->sizeGPS());
828 ColumnVector vv_glo(epoData->sizeGlo());
829 ColumnVector vv_gal_code(epoData->sizeGal());
830 ColumnVector vv_gal_phase(epoData->sizeGal());
831
832 for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
833 if (_usePhase) {
834 vv_code(iobs) = vv(2*iobs-1);
835 vv_phase(iobs) = vv(2*iobs);
836 }
837 else {
838 vv_code(iobs) = vv(iobs);
839 }
840 }
841 if (_useGlonass) {
842 for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
843 vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
844 }
845 }
846 if (_useGalileo) {
847 for (unsigned iobs = 1; iobs <= epoData->sizeGal(); ++iobs) {
848 if (_usePhase) {
849 vv_gal_code(iobs) = vv(2*iobs-1);
850 vv_gal_phase(iobs) = vv(2*iobs);
851 }
852 else {
853 vv_gal_code(iobs) = vv(iobs);
854 }
855 }
856 }
857
858 strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
859 if (_usePhase) {
860 strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
861 }
862 if (_useGlonass) {
863 strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
864 }
865 if (_useGalileo) {
866 strA << "Galileo code " << setw(8) << setprecision(3) << vv_gal_code.t();
867 if (_usePhase) {
868 strA << "Galileo phase " << setw(8) << setprecision(3) << vv_gal_phase.t();
869 }
870 }
871 _log += strA.str().c_str();
872
873 } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
874 epoData->satDataGlo, epoData->satDataGal) != 0);
875
876 // Remember the Epoch-specific Results for the computation of means
877 // ----------------------------------------------------------------
878 pppPos* newPos = new pppPos;
879 newPos->time = epoData->tt;
880
881 // Set Solution Vector
882 // -------------------
883 ostringstream strB;
884 strB.setf(ios::fixed);
885 QVectorIterator<bncParam*> itPar(_params);
886 while (itPar.hasNext()) {
887 bncParam* par = itPar.next();
888 par->xx += dx(par->index);
889
890 if (par->type == bncParam::RECCLK) {
891 strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
892 << " +- " << setw(6) << setprecision(3)
893 << sqrt(_QQ(par->index,par->index));
894 }
895 else if (par->type == bncParam::AMB_L3) {
896 strB << "\n amb " << par->prn.toAscii().data() << " = "
897 << setw(6) << setprecision(3) << par->xx
898 << " +- " << setw(6) << setprecision(3)
899 << sqrt(_QQ(par->index,par->index));
900 }
901 else if (par->type == bncParam::TROPO) {
902 double aprTrp = delay_saast(M_PI/2.0);
903 strB << "\n trp = " << par->prn.toAscii().data()
904 << setw(7) << setprecision(3) << aprTrp << " "
905 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
906 << " +- " << setw(6) << setprecision(3)
907 << sqrt(_QQ(par->index,par->index));
908 newPos->xnt[6] = aprTrp + par->xx;
909 }
910 else if (par->type == bncParam::GALILEO_OFFSET) {
911 strB << "\n offset = " << setw(6) << setprecision(3) << par->xx
912 << " +- " << setw(6) << setprecision(3)
913 << sqrt(_QQ(par->index,par->index));
914 }
915 }
916 strB << '\n';
917 _log += strB.str().c_str();
918 emit newMessage(_log, false);
919
920 // Final Message (both log file and screen)
921 // ----------------------------------------
922 ostringstream strC;
923 strC.setf(ios::fixed);
924 strC << _staID.data() << " PPP "
925 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
926 << setw(14) << setprecision(3) << x() << " +- "
927 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
928 << setw(14) << setprecision(3) << y() << " +- "
929 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
930 << setw(14) << setprecision(3) << z() << " +- "
931 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
932
933 // NEU Output
934 // ----------
935 if (settings.value("pppRefCrdX").toString() != "" &&
936 settings.value("pppRefCrdY").toString() != "" &&
937 settings.value("pppRefCrdZ").toString() != "") {
938
939 double xyzRef[3];
940 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
941 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
942 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
943
944 newPos->xnt[0] = x() - xyzRef[0];
945 newPos->xnt[1] = y() - xyzRef[1];
946 newPos->xnt[2] = z() - xyzRef[2];
947
948 double ellRef[3];
949 xyz2ell(xyzRef, ellRef);
950 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
951
952 strC << " NEU "
953 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
954 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
955 << setw(8) << setprecision(3) << newPos->xnt[5];
956
957 }
958
959 emit newMessage(QByteArray(strC.str().c_str()), true);
960
961 if (settings.value("pppAverage").toString() == "") {
962 delete newPos;
963 }
964 else {
965
966 _posAverage.push_back(newPos);
967
968 // Time Span for Average Computation
969 // ---------------------------------
970 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
971 if (tRangeAverage < 0) {
972 tRangeAverage = 0;
973 }
974 if (tRangeAverage > 86400) {
975 tRangeAverage = 86400;
976 }
977
978 // Compute the Mean
979 // ----------------
980 ColumnVector mean(7); mean = 0.0;
981
982 QMutableVectorIterator<pppPos*> it(_posAverage);
983 while (it.hasNext()) {
984 pppPos* pp = it.next();
985 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
986 delete pp;
987 it.remove();
988 }
989 else {
990 for (int ii = 0; ii < 7; ++ii) {
991 mean[ii] += pp->xnt[ii];
992 }
993 }
994 }
995
996 int nn = _posAverage.size();
997
998 if (nn > 0) {
999
1000 mean /= nn;
1001
1002 // Compute the Deviation
1003 // ---------------------
1004 ColumnVector std(7); std = 0.0;
1005 QVectorIterator<pppPos*> it2(_posAverage);
1006 while (it2.hasNext()) {
1007 pppPos* pp = it2.next();
1008 for (int ii = 0; ii < 7; ++ii) {
1009 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
1010 }
1011 }
1012 for (int ii = 0; ii < 7; ++ii) {
1013 std[ii] = sqrt(std[ii] / nn);
1014 }
1015
1016 ostringstream strD; strD.setf(ios::fixed);
1017 strD << _staID.data() << " AVE-XYZ "
1018 << epoData->tt.timestr(1) << " "
1019 << setw(13) << setprecision(3) << mean[0] << " +- "
1020 << setw(6) << setprecision(3) << std[0] << " "
1021 << setw(14) << setprecision(3) << mean[1] << " +- "
1022 << setw(6) << setprecision(3) << std[1] << " "
1023 << setw(14) << setprecision(3) << mean[2] << " +- "
1024 << setw(6) << setprecision(3) << std[2];
1025 emit newMessage(QByteArray(strD.str().c_str()), true);
1026
1027 ostringstream strE; strE.setf(ios::fixed);
1028 strE << _staID.data() << " AVE-NEU "
1029 << epoData->tt.timestr(1) << " "
1030 << setw(13) << setprecision(3) << mean[3] << " +- "
1031 << setw(6) << setprecision(3) << std[3] << " "
1032 << setw(14) << setprecision(3) << mean[4] << " +- "
1033 << setw(6) << setprecision(3) << std[4] << " "
1034 << setw(14) << setprecision(3) << mean[5] << " +- "
1035 << setw(6) << setprecision(3) << std[5];
1036
1037 emit newMessage(QByteArray(strE.str().c_str()), true);
1038
1039 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
1040 ostringstream strF; strF.setf(ios::fixed);
1041 strF << _staID.data() << " AVE-TRP "
1042 << epoData->tt.timestr(1) << " "
1043 << setw(13) << setprecision(3) << mean[6] << " +- "
1044 << setw(6) << setprecision(3) << std[6] << endl;
1045 emit newMessage(QByteArray(strF.str().c_str()), true);
1046 }
1047 }
1048 }
1049
1050 // NMEA Output
1051 // -----------
1052 double xyz[3];
1053 xyz[0] = x();
1054 xyz[1] = y();
1055 xyz[2] = z();
1056 double ell[3];
1057 xyz2ell(xyz, ell);
1058 double phiDeg = ell[0] * 180 / M_PI;
1059 double lamDeg = ell[1] * 180 / M_PI;
1060
1061 char phiCh = 'N';
1062 if (phiDeg < 0) {
1063 phiDeg = -phiDeg;
1064 phiCh = 'S';
1065 }
1066 char lamCh = 'E';
1067 if (lamDeg < 0) {
1068 lamDeg = -lamDeg;
1069 lamCh = 'W';
1070 }
1071
1072 string datestr = epoData->tt.datestr(0); // yyyymmdd
1073 ostringstream strRMC;
1074 strRMC.setf(ios::fixed);
1075 strRMC << "GPRMC,"
1076 << epoData->tt.timestr(0,0) << ",A,"
1077 << setw(2) << setfill('0') << int(phiDeg)
1078 << setw(6) << setprecision(3) << setfill('0')
1079 << fmod(60*phiDeg,60) << ',' << phiCh << ','
1080 << setw(3) << setfill('0') << int(lamDeg)
1081 << setw(6) << setprecision(3) << setfill('0')
1082 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
1083 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
1084 << datestr[2] << datestr[3] << ",,";
1085
1086 writeNMEAstr(QString(strRMC.str().c_str()));
1087
1088 double dop = 2.0; // TODO
1089
1090 ostringstream strGGA;
1091 strGGA.setf(ios::fixed);
1092 strGGA << "GPGGA,"
1093 << epoData->tt.timestr(0,0) << ','
1094 << setw(2) << setfill('0') << int(phiDeg)
1095 << setw(10) << setprecision(7) << setfill('0')
1096 << fmod(60*phiDeg,60) << ',' << phiCh << ','
1097 << setw(3) << setfill('0') << int(lamDeg)
1098 << setw(10) << setprecision(7) << setfill('0')
1099 << fmod(60*lamDeg,60) << ',' << lamCh
1100 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
1101 << setw(3) << setprecision(1) << dop << ','
1102 << setprecision(3) << ell[2] << ",M,0.0,M,,";
1103
1104 writeNMEAstr(QString(strGGA.str().c_str()));
1105
1106 return success;
1107}
1108
1109// Outlier Detection
1110////////////////////////////////////////////////////////////////////////////
1111int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
1112 const ColumnVector& vv,
1113 QMap<QString, t_satData*>& satDataGPS,
1114 QMap<QString, t_satData*>& satDataGlo,
1115 QMap<QString, t_satData*>& satDataGal) {
1116
1117 double vvMaxCodeGPS = 0.0;
1118 double vvMaxPhaseGPS = 0.0;
1119 double vvMaxPhaseGlo = 0.0;
1120 double vvMaxCodeGal = 0.0;
1121 double vvMaxPhaseGal = 0.0;
1122 QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
1123 QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
1124 QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
1125 QMutableMapIterator<QString, t_satData*> itMaxCodeGal(satDataGPS);
1126 QMutableMapIterator<QString, t_satData*> itMaxPhaseGal(satDataGPS);
1127
1128 int ii = 0;
1129
1130 // GPS code and (optionally) phase residuals
1131 // -----------------------------------------
1132 QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
1133 while (itGPS.hasNext()) {
1134 itGPS.next();
1135 ++ii;
1136
1137 if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
1138 vvMaxCodeGPS = fabs(vv(ii));
1139 itMaxCodeGPS = itGPS;
1140 }
1141
1142 if (_usePhase) {
1143 ++ii;
1144 if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
1145 vvMaxPhaseGPS = fabs(vv(ii));
1146 itMaxPhaseGPS = itGPS;
1147 }
1148 }
1149 }
1150
1151 // Glonass phase residuals
1152 // -----------------------
1153 if (_usePhase) {
1154 QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
1155 while (itGlo.hasNext()) {
1156 itGlo.next();
1157 ++ii;
1158 if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
1159 vvMaxPhaseGlo = fabs(vv(ii));
1160 itMaxPhaseGlo = itGlo;
1161 }
1162 }
1163 }
1164
1165 // Galileo code and (optionally) phase residuals
1166 // ---------------------------------------------
1167 QMutableMapIterator<QString, t_satData*> itGal(satDataGal);
1168 while (itGal.hasNext()) {
1169 itGal.next();
1170 ++ii;
1171
1172 if (vvMaxCodeGal == 0.0 || fabs(vv(ii)) > vvMaxCodeGal) {
1173 vvMaxCodeGal = fabs(vv(ii));
1174 itMaxCodeGal = itGal;
1175 }
1176
1177 if (_usePhase) {
1178 ++ii;
1179 if (vvMaxPhaseGal == 0.0 || fabs(vv(ii)) > vvMaxPhaseGal) {
1180 vvMaxPhaseGal = fabs(vv(ii));
1181 itMaxPhaseGal = itGal;
1182 }
1183 }
1184 }
1185
1186 if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
1187 QString prn = itMaxPhaseGlo.key();
1188 t_satData* satData = itMaxPhaseGlo.value();
1189 delete satData;
1190 itMaxPhaseGlo.remove();
1191 _QQ = QQsav;
1192
1193 _log += "Outlier Phase " + prn.toAscii() + " "
1194 + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
1195
1196 return 1;
1197 }
1198
1199 else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
1200 QString prn = itMaxCodeGPS.key();
1201 t_satData* satData = itMaxCodeGPS.value();
1202 delete satData;
1203 itMaxCodeGPS.remove();
1204 _QQ = QQsav;
1205
1206 _log += "Outlier Code " + prn.toAscii() + " "
1207 + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
1208
1209 return 1;
1210 }
1211 else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
1212 QString prn = itMaxPhaseGPS.key();
1213 t_satData* satData = itMaxPhaseGPS.value();
1214 delete satData;
1215 itMaxPhaseGPS.remove();
1216 _QQ = QQsav;
1217
1218 _log += "Outlier Phase " + prn.toAscii() + " "
1219 + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
1220
1221 return 1;
1222 }
1223
1224 else if (vvMaxCodeGal > MAXRES_CODE_GAL) {
1225 QString prn = itMaxCodeGal.key();
1226 t_satData* satData = itMaxCodeGal.value();
1227 delete satData;
1228 itMaxCodeGal.remove();
1229 _QQ = QQsav;
1230
1231 _log += "Outlier Code " + prn.toAscii() + " "
1232 + QByteArray::number(vvMaxCodeGal, 'f', 3) + "\n";
1233
1234 return 1;
1235 }
1236 else if (vvMaxPhaseGal > MAXRES_PHASE_GAL) {
1237 QString prn = itMaxPhaseGal.key();
1238 t_satData* satData = itMaxPhaseGal.value();
1239 delete satData;
1240 itMaxPhaseGal.remove();
1241 _QQ = QQsav;
1242
1243 _log += "Outlier Phase " + prn.toAscii() + " "
1244 + QByteArray::number(vvMaxPhaseGal, 'f', 3) + "\n";
1245
1246 return 1;
1247 }
1248
1249 return 0;
1250}
1251
1252//
1253////////////////////////////////////////////////////////////////////////////
1254void bncModel::writeNMEAstr(const QString& nmStr) {
1255
1256 unsigned char XOR = 0;
1257 for (int ii = 0; ii < nmStr.length(); ii++) {
1258 XOR ^= (unsigned char) nmStr[ii].toAscii();
1259 }
1260
1261 QString outStr = '$' + nmStr
1262 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
1263
1264 if (_nmeaStream) {
1265 *_nmeaStream << outStr;
1266 _nmeaStream->flush();
1267 }
1268
1269 emit newNMEAstr(outStr.toAscii());
1270}
1271
1272////
1273//////////////////////////////////////////////////////////////////////////////
1274void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1275 const DiagonalMatrix& PP,
1276 SymmetricMatrix& QQ, ColumnVector& dx) {
1277
1278 int nObs = AA.Nrows();
1279 int nPar = AA.Ncols();
1280
1281 UpperTriangularMatrix SS = Cholesky(QQ).t();
1282
1283 Matrix SA = SS*AA.t();
1284 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
1285 for (int ii = 1; ii <= nObs; ++ii) {
1286 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
1287 }
1288
1289 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
1290 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
1291
1292 UpperTriangularMatrix UU;
1293 QRZ(SRF, UU);
1294
1295 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
1296 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
1297 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
1298
1299 UpperTriangularMatrix SHi = SH_rt.i();
1300
1301 Matrix KT = SHi * YY;
1302 SymmetricMatrix Hi; Hi << SHi * SHi.t();
1303
1304 dx = KT.t() * ll;
1305 QQ << (SS.t() * SS);
1306}
1307
1308// Phase Wind-Up Correction
1309///////////////////////////////////////////////////////////////////////////
1310double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1311 const ColumnVector& rRec) {
1312
1313 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1314
1315 // First time - initialize to zero
1316 // -------------------------------
1317 if (!_windUpTime.contains(prn)) {
1318 _windUpTime[prn] = Mjd;
1319 _windUpSum[prn] = 0.0;
1320 }
1321
1322 // Compute the correction for new time
1323 // -----------------------------------
1324 else if (_windUpTime[prn] != Mjd) {
1325 _windUpTime[prn] = Mjd;
1326
1327 // Unit Vector GPS Satellite --> Receiver
1328 // --------------------------------------
1329 ColumnVector rho = rRec - rSat;
1330 rho /= rho.norm_Frobenius();
1331
1332 // GPS Satellite unit Vectors sz, sy, sx
1333 // -------------------------------------
1334 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1335
1336 ColumnVector xSun = Sun(Mjd);
1337 xSun /= xSun.norm_Frobenius();
1338
1339 ColumnVector sy = crossproduct(sz, xSun);
1340 ColumnVector sx = crossproduct(sy, sz);
1341
1342 // Effective Dipole of the GPS Satellite Antenna
1343 // ---------------------------------------------
1344 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1345 - crossproduct(rho, sy);
1346
1347 // Receiver unit Vectors rx, ry
1348 // ----------------------------
1349 ColumnVector rx(3);
1350 ColumnVector ry(3);
1351
1352 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1353 double neu[3];
1354
1355 neu[0] = 1.0;
1356 neu[1] = 0.0;
1357 neu[2] = 0.0;
1358 neu2xyz(recEll, neu, rx.data());
1359
1360 neu[0] = 0.0;
1361 neu[1] = -1.0;
1362 neu[2] = 0.0;
1363 neu2xyz(recEll, neu, ry.data());
1364
1365 // Effective Dipole of the Receiver Antenna
1366 // ----------------------------------------
1367 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1368 + crossproduct(rho, ry);
1369
1370 // Resulting Effect
1371 // ----------------
1372 double alpha = DotProduct(dipSat,dipRec) /
1373 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1374
1375 if (alpha > 1.0) alpha = 1.0;
1376 if (alpha < -1.0) alpha = -1.0;
1377
1378 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1379
1380 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1381 dphi = -dphi;
1382 }
1383
1384 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1385 }
1386
1387 return _windUpSum[prn];
1388}
Note: See TracBrowser for help on using the repository browser.