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

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