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

Last change on this file since 2784 was 2784, checked in by mervart, 13 years ago
File size: 40.0 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 _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 double offset = 0.0;
417 if (satData->prn[0] == 'E') {
418 offset = Galileo_offset();
419 }
420
421 return satData->rho + clk() + offset - satData->clk + tropDelay + wind;
422}
423
424// Tropospheric Model (Saastamoinen)
425////////////////////////////////////////////////////////////////////////////
426double bncModel::delay_saast(double Ele) {
427
428 double xyz[3];
429 xyz[0] = x();
430 xyz[1] = y();
431 xyz[2] = z();
432 double ell[3];
433 xyz2ell(xyz, ell);
434 double height = ell[2];
435
436 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
437 double TT = 18.0 - height * 0.0065 + 273.15;
438 double hh = 50.0 * exp(-6.396e-4 * height);
439 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
440
441 double h_km = height / 1000.0;
442
443 if (h_km < 0.0) h_km = 0.0;
444 if (h_km > 5.0) h_km = 5.0;
445 int ii = int(h_km + 1);
446 double href = ii - 1;
447
448 double bCor[6];
449 bCor[0] = 1.156;
450 bCor[1] = 1.006;
451 bCor[2] = 0.874;
452 bCor[3] = 0.757;
453 bCor[4] = 0.654;
454 bCor[5] = 0.563;
455
456 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
457
458 double zen = M_PI/2.0 - Ele;
459
460 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
461}
462
463// Prediction Step of the Filter
464////////////////////////////////////////////////////////////////////////////
465void bncModel::predict(t_epoData* epoData) {
466
467 bncSettings settings;
468
469 bool firstCrd = false;
470 if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
471 firstCrd = true;
472 _startTime = QDateTime::currentDateTime();
473 }
474
475 // Use different white noise for Quick-Start mode
476 // ----------------------------------------------
477 double sigCrdP_used = _sigCrdP;
478 if ( _quickStart > 0.0 &&
479 _quickStart > _startTime.secsTo(QDateTime::currentDateTime()) ) {
480 sigCrdP_used = 0.0;
481 }
482
483 // Predict Parameter values, add white noise
484 // -----------------------------------------
485 for (int iPar = 1; iPar <= _params.size(); iPar++) {
486 bncParam* pp = _params[iPar-1];
487
488 // Coordinates
489 // -----------
490 if (pp->type == bncParam::CRD_X) {
491 if (firstCrd) {
492 if (settings.value("pppRefCrdX").toString() != "" &&
493 settings.value("pppRefCrdY").toString() != "" &&
494 settings.value("pppRefCrdZ").toString() != "") {
495 pp->xx = settings.value("pppRefCrdX").toDouble();
496 }
497 else {
498 pp->xx = _xcBanc(1);
499 }
500 }
501 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
502 }
503 else if (pp->type == bncParam::CRD_Y) {
504 if (firstCrd) {
505 if (settings.value("pppRefCrdX").toString() != "" &&
506 settings.value("pppRefCrdY").toString() != "" &&
507 settings.value("pppRefCrdZ").toString() != "") {
508 pp->xx = settings.value("pppRefCrdY").toDouble();
509 }
510 else {
511 pp->xx = _xcBanc(2);
512 }
513 }
514 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
515 }
516 else if (pp->type == bncParam::CRD_Z) {
517 if (firstCrd) {
518 if (settings.value("pppRefCrdX").toString() != "" &&
519 settings.value("pppRefCrdY").toString() != "" &&
520 settings.value("pppRefCrdZ").toString() != "") {
521 pp->xx = settings.value("pppRefCrdZ").toDouble();
522 }
523 else {
524 pp->xx = _xcBanc(3);
525 }
526 }
527 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
528 }
529
530 // Receiver Clocks
531 // ---------------
532 else if (pp->type == bncParam::RECCLK) {
533 pp->xx = _xcBanc(4);
534 for (int jj = 1; jj <= _params.size(); jj++) {
535 _QQ(iPar, jj) = 0.0;
536 }
537 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
538 }
539
540 // Tropospheric Delay
541 // ------------------
542 else if (pp->type == bncParam::TROPO) {
543 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
544 }
545
546 // Galileo Offset
547 // --------------
548 else if (pp->type == bncParam::GALILEO_OFFSET) {
549 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
550 }
551 }
552
553 // Add New Ambiguities if necessary
554 // --------------------------------
555 if (_usePhase) {
556
557 // Make a copy of QQ and xx, set parameter indices
558 // -----------------------------------------------
559 SymmetricMatrix QQ_old = _QQ;
560
561 for (int iPar = 1; iPar <= _params.size(); iPar++) {
562 _params[iPar-1]->index_old = _params[iPar-1]->index;
563 _params[iPar-1]->index = 0;
564 }
565
566 // Remove Ambiguity Parameters without observations
567 // ------------------------------------------------
568 int iPar = 0;
569 QMutableVectorIterator<bncParam*> it(_params);
570 while (it.hasNext()) {
571 bncParam* par = it.next();
572 bool removed = false;
573 if (par->type == bncParam::AMB_L3) {
574 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
575 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() &&
576 epoData->satDataGal.find(par->prn) == epoData->satDataGal.end() ) {
577 removed = true;
578 delete par;
579 it.remove();
580 }
581 }
582 if (! removed) {
583 ++iPar;
584 par->index = iPar;
585 }
586 }
587
588 // Add new ambiguity parameters
589 // ----------------------------
590 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
591 while (iGPS.hasNext()) {
592 iGPS.next();
593 QString prn = iGPS.key();
594 t_satData* satData = iGPS.value();
595 bool found = false;
596 for (int iPar = 1; iPar <= _params.size(); iPar++) {
597 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
598 _params[iPar-1]->prn == prn) {
599 found = true;
600 break;
601 }
602 }
603 if (!found) {
604 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
605 _params.push_back(par);
606 par->xx = satData->L3 - cmpValue(satData, true);
607 }
608 }
609
610 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
611 while (iGlo.hasNext()) {
612 iGlo.next();
613 QString prn = iGlo.key();
614 t_satData* satData = iGlo.value();
615 bool found = false;
616 for (int iPar = 1; iPar <= _params.size(); iPar++) {
617 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
618 _params[iPar-1]->prn == prn) {
619 found = true;
620 break;
621 }
622 }
623 if (!found) {
624 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
625 _params.push_back(par);
626 par->xx = satData->L3 - cmpValue(satData, true);
627 }
628 }
629
630 QMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
631 while (iGal.hasNext()) {
632 iGal.next();
633 QString prn = iGal.key();
634 t_satData* satData = iGal.value();
635 bool found = false;
636 for (int iPar = 1; iPar <= _params.size(); iPar++) {
637 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
638 _params[iPar-1]->prn == prn) {
639 found = true;
640 break;
641 }
642 }
643 if (!found) {
644 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
645 _params.push_back(par);
646 par->xx = satData->L3 - cmpValue(satData, true);
647 }
648 }
649
650 int nPar = _params.size();
651 _QQ.ReSize(nPar); _QQ = 0.0;
652 for (int i1 = 1; i1 <= nPar; i1++) {
653 bncParam* p1 = _params[i1-1];
654 if (p1->index_old != 0) {
655 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
656 for (int i2 = 1; i2 <= nPar; i2++) {
657 bncParam* p2 = _params[i2-1];
658 if (p2->index_old != 0) {
659 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
660 }
661 }
662 }
663 }
664
665 for (int ii = 1; ii <= nPar; ii++) {
666 bncParam* par = _params[ii-1];
667 if (par->index_old == 0) {
668 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
669 }
670 par->index_old = par->index;
671 }
672 }
673}
674
675// Update Step of the Filter (currently just a single-epoch solution)
676////////////////////////////////////////////////////////////////////////////
677t_irc bncModel::update(t_epoData* epoData) {
678
679 bncSettings settings;
680
681 _log.clear();
682
683 _time = epoData->tt;
684
685 _log += "Single Point Positioning of Epoch "
686 + QByteArray(_time.timestr(1).c_str()) +
687 "\n--------------------------------------------------------------\n";
688
689 SymmetricMatrix QQsav;
690 ColumnVector dx;
691 ColumnVector vv;
692
693 // Loop over all outliers
694 // ----------------------
695 do {
696
697 // Bancroft Solution
698 // -----------------
699 if (cmpBancroft(epoData) != success) {
700 emit newMessage(_log, false);
701 return failure;
702 }
703
704 // Status Prediction
705 // -----------------
706 predict(epoData);
707
708 // Create First-Design Matrix
709 // --------------------------
710 unsigned nPar = _params.size();
711 unsigned nObs = 0;
712 if (_usePhase) {
713 nObs = 2 * (epoData->sizeGPS() + epoData->sizeGal()) + epoData->sizeGlo();
714 }
715 else {
716 nObs = epoData->sizeGPS() + epoData->sizeGal(); // Glonass code not used
717 }
718
719 if (nObs < nPar) {
720 _log += "bncModel::update: nObs < nPar\n";
721 emit newMessage(_log, false);
722 return failure;
723 }
724
725 Matrix AA(nObs, nPar); // first design matrix
726 ColumnVector ll(nObs); // tems observed-computed
727 DiagonalMatrix PP(nObs); PP = 0.0;
728
729 unsigned iObs = 0;
730
731 // GPS code and (optionally) phase observations
732 // --------------------------------------------
733 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
734 while (itGPS.hasNext()) {
735 ++iObs;
736 itGPS.next();
737 QString prn = itGPS.key();
738 t_satData* satData = itGPS.value();
739
740 ll(iObs) = satData->P3 - cmpValue(satData, false);
741 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3);
742 for (int iPar = 1; iPar <= _params.size(); iPar++) {
743 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
744 }
745
746 if (_usePhase) {
747 ++iObs;
748 ll(iObs) = satData->L3 - cmpValue(satData, true);
749 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
750 for (int iPar = 1; iPar <= _params.size(); iPar++) {
751 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
752 _params[iPar-1]->prn == prn) {
753 ll(iObs) -= _params[iPar-1]->xx;
754 }
755 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
756 }
757 }
758 }
759
760 // Glonass phase observations
761 // --------------------------
762 if (_usePhase) {
763 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
764 while (itGlo.hasNext()) {
765 ++iObs;
766 itGlo.next();
767 QString prn = itGlo.key();
768 t_satData* satData = itGlo.value();
769
770 ll(iObs) = satData->L3 - cmpValue(satData, true);
771 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
772 for (int iPar = 1; iPar <= _params.size(); iPar++) {
773 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
774 _params[iPar-1]->prn == prn) {
775 ll(iObs) -= _params[iPar-1]->xx;
776 }
777 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
778 }
779 }
780 }
781
782 // Galileo code and (optionally) phase observations
783 // ------------------------------------------------
784 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
785 while (itGal.hasNext()) {
786 ++iObs;
787 itGal.next();
788 QString prn = itGal.key();
789 t_satData* satData = itGal.value();
790
791 ll(iObs) = satData->P3 - cmpValue(satData, false);
792 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3);
793 for (int iPar = 1; iPar <= _params.size(); iPar++) {
794 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
795 }
796
797 if (_usePhase) {
798 ++iObs;
799 ll(iObs) = satData->L3 - cmpValue(satData, true);
800 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
801 for (int iPar = 1; iPar <= _params.size(); iPar++) {
802 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
803 _params[iPar-1]->prn == prn) {
804 ll(iObs) -= _params[iPar-1]->xx;
805 }
806 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
807 }
808 }
809 }
810
811 // Compute Filter Update
812 // ---------------------
813 QQsav = _QQ;
814
815 kalman(AA, ll, PP, _QQ, dx);
816
817 vv = ll - AA * dx;
818
819 ostringstream strA;
820 strA.setf(ios::fixed);
821 ColumnVector vv_code(epoData->sizeGPS());
822 ColumnVector vv_phase(epoData->sizeGPS());
823 ColumnVector vv_glo(epoData->sizeGlo());
824 ColumnVector vv_gal_code(epoData->sizeGal());
825 ColumnVector vv_gal_phase(epoData->sizeGal());
826
827 for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
828 if (_usePhase) {
829 vv_code(iobs) = vv(2*iobs-1);
830 vv_phase(iobs) = vv(2*iobs);
831 }
832 else {
833 vv_code(iobs) = vv(iobs);
834 }
835 }
836 if (_useGlonass) {
837 for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
838 vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
839 }
840 }
841 if (_useGalileo) {
842 for (unsigned iobs = 1; iobs <= epoData->sizeGal(); ++iobs) {
843 if (_usePhase) {
844 vv_gal_code(iobs) = vv(2*iobs-1);
845 vv_gal_phase(iobs) = vv(2*iobs);
846 }
847 else {
848 vv_gal_code(iobs) = vv(iobs);
849 }
850 }
851 }
852
853 strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
854 if (_usePhase) {
855 strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
856 }
857 if (_useGlonass) {
858 strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
859 }
860 if (_useGalileo) {
861 strA << "Galileo code " << setw(8) << setprecision(3) << vv_gal_code.t();
862 if (_usePhase) {
863 strA << "Galileo phase " << setw(8) << setprecision(3) << vv_gal_phase.t();
864 }
865 }
866 _log += strA.str().c_str();
867
868 } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
869 epoData->satDataGlo, epoData->satDataGal) != 0);
870
871 // Remember the Epoch-specific Results for the computation of means
872 // ----------------------------------------------------------------
873 pppPos* newPos = new pppPos;
874 newPos->time = epoData->tt;
875
876 // Set Solution Vector
877 // -------------------
878 ostringstream strB;
879 strB.setf(ios::fixed);
880 QVectorIterator<bncParam*> itPar(_params);
881 while (itPar.hasNext()) {
882 bncParam* par = itPar.next();
883 par->xx += dx(par->index);
884
885 if (par->type == bncParam::RECCLK) {
886 strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
887 << " +- " << setw(6) << setprecision(3)
888 << sqrt(_QQ(par->index,par->index));
889 }
890 else if (par->type == bncParam::AMB_L3) {
891 strB << "\n amb " << par->prn.toAscii().data() << " = "
892 << setw(6) << setprecision(3) << par->xx
893 << " +- " << setw(6) << setprecision(3)
894 << sqrt(_QQ(par->index,par->index));
895 }
896 else if (par->type == bncParam::TROPO) {
897 double aprTrp = delay_saast(M_PI/2.0);
898 strB << "\n trp = " << par->prn.toAscii().data()
899 << setw(7) << setprecision(3) << aprTrp << " "
900 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
901 << " +- " << setw(6) << setprecision(3)
902 << sqrt(_QQ(par->index,par->index));
903 newPos->xnt[6] = aprTrp + par->xx;
904 }
905 else if (par->type == bncParam::GALILEO_OFFSET) {
906 strB << "\n offset = " << setw(6) << setprecision(3) << par->xx
907 << " +- " << setw(6) << setprecision(3)
908 << sqrt(_QQ(par->index,par->index));
909 }
910 }
911 strB << '\n';
912 _log += strB.str().c_str();
913 emit newMessage(_log, false);
914
915 // Final Message (both log file and screen)
916 // ----------------------------------------
917 ostringstream strC;
918 strC.setf(ios::fixed);
919 strC << _staID.data() << " PPP "
920 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
921 << setw(14) << setprecision(3) << x() << " +- "
922 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
923 << setw(14) << setprecision(3) << y() << " +- "
924 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
925 << setw(14) << setprecision(3) << z() << " +- "
926 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
927
928 // NEU Output
929 // ----------
930 if (settings.value("pppRefCrdX").toString() != "" &&
931 settings.value("pppRefCrdY").toString() != "" &&
932 settings.value("pppRefCrdZ").toString() != "") {
933
934 double xyzRef[3];
935 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
936 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
937 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
938
939 newPos->xnt[0] = x() - xyzRef[0];
940 newPos->xnt[1] = y() - xyzRef[1];
941 newPos->xnt[2] = z() - xyzRef[2];
942
943 double ellRef[3];
944 xyz2ell(xyzRef, ellRef);
945 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
946
947 strC << " NEU "
948 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
949 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
950 << setw(8) << setprecision(3) << newPos->xnt[5];
951
952 }
953
954 emit newMessage(QByteArray(strC.str().c_str()), true);
955
956 if (settings.value("pppAverage").toString() == "") {
957 delete newPos;
958 }
959 else {
960
961 _posAverage.push_back(newPos);
962
963 // Time Span for Average Computation
964 // ---------------------------------
965 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
966 if (tRangeAverage < 0) {
967 tRangeAverage = 0;
968 }
969 if (tRangeAverage > 86400) {
970 tRangeAverage = 86400;
971 }
972
973 // Compute the Mean
974 // ----------------
975 ColumnVector mean(7); mean = 0.0;
976
977 QMutableVectorIterator<pppPos*> it(_posAverage);
978 while (it.hasNext()) {
979 pppPos* pp = it.next();
980 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
981 delete pp;
982 it.remove();
983 }
984 else {
985 for (int ii = 0; ii < 7; ++ii) {
986 mean[ii] += pp->xnt[ii];
987 }
988 }
989 }
990
991 int nn = _posAverage.size();
992
993 if (nn > 0) {
994
995 mean /= nn;
996
997 // Compute the Deviation
998 // ---------------------
999 ColumnVector std(7); std = 0.0;
1000 QVectorIterator<pppPos*> it2(_posAverage);
1001 while (it2.hasNext()) {
1002 pppPos* pp = it2.next();
1003 for (int ii = 0; ii < 7; ++ii) {
1004 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
1005 }
1006 }
1007 for (int ii = 0; ii < 7; ++ii) {
1008 std[ii] = sqrt(std[ii] / nn);
1009 }
1010
1011 ostringstream strD; strD.setf(ios::fixed);
1012 strD << _staID.data() << " AVE-XYZ "
1013 << epoData->tt.timestr(1) << " "
1014 << setw(13) << setprecision(3) << mean[0] << " +- "
1015 << setw(6) << setprecision(3) << std[0] << " "
1016 << setw(14) << setprecision(3) << mean[1] << " +- "
1017 << setw(6) << setprecision(3) << std[1] << " "
1018 << setw(14) << setprecision(3) << mean[2] << " +- "
1019 << setw(6) << setprecision(3) << std[2];
1020 emit newMessage(QByteArray(strD.str().c_str()), true);
1021
1022 ostringstream strE; strE.setf(ios::fixed);
1023 strE << _staID.data() << " AVE-NEU "
1024 << epoData->tt.timestr(1) << " "
1025 << setw(13) << setprecision(3) << mean[3] << " +- "
1026 << setw(6) << setprecision(3) << std[3] << " "
1027 << setw(14) << setprecision(3) << mean[4] << " +- "
1028 << setw(6) << setprecision(3) << std[4] << " "
1029 << setw(14) << setprecision(3) << mean[5] << " +- "
1030 << setw(6) << setprecision(3) << std[5];
1031
1032 emit newMessage(QByteArray(strE.str().c_str()), true);
1033
1034 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
1035 ostringstream strF; strF.setf(ios::fixed);
1036 strF << _staID.data() << " AVE-TRP "
1037 << epoData->tt.timestr(1) << " "
1038 << setw(13) << setprecision(3) << mean[6] << " +- "
1039 << setw(6) << setprecision(3) << std[6] << endl;
1040 emit newMessage(QByteArray(strF.str().c_str()), true);
1041 }
1042 }
1043 }
1044
1045 // NMEA Output
1046 // -----------
1047 double xyz[3];
1048 xyz[0] = x();
1049 xyz[1] = y();
1050 xyz[2] = z();
1051 double ell[3];
1052 xyz2ell(xyz, ell);
1053 double phiDeg = ell[0] * 180 / M_PI;
1054 double lamDeg = ell[1] * 180 / M_PI;
1055
1056 char phiCh = 'N';
1057 if (phiDeg < 0) {
1058 phiDeg = -phiDeg;
1059 phiCh = 'S';
1060 }
1061 char lamCh = 'E';
1062 if (lamDeg < 0) {
1063 lamDeg = -lamDeg;
1064 lamCh = 'W';
1065 }
1066
1067 string datestr = epoData->tt.datestr(0); // yyyymmdd
1068 ostringstream strRMC;
1069 strRMC.setf(ios::fixed);
1070 strRMC << "GPRMC,"
1071 << epoData->tt.timestr(0,0) << ",A,"
1072 << setw(2) << setfill('0') << int(phiDeg)
1073 << setw(6) << setprecision(3) << setfill('0')
1074 << fmod(60*phiDeg,60) << ',' << phiCh << ','
1075 << setw(3) << setfill('0') << int(lamDeg)
1076 << setw(6) << setprecision(3) << setfill('0')
1077 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
1078 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
1079 << datestr[2] << datestr[3] << ",,";
1080
1081 writeNMEAstr(QString(strRMC.str().c_str()));
1082
1083 double dop = 2.0; // TODO
1084
1085 ostringstream strGGA;
1086 strGGA.setf(ios::fixed);
1087 strGGA << "GPGGA,"
1088 << epoData->tt.timestr(0,0) << ','
1089 << setw(2) << setfill('0') << int(phiDeg)
1090 << setw(10) << setprecision(7) << setfill('0')
1091 << fmod(60*phiDeg,60) << ',' << phiCh << ','
1092 << setw(3) << setfill('0') << int(lamDeg)
1093 << setw(10) << setprecision(7) << setfill('0')
1094 << fmod(60*lamDeg,60) << ',' << lamCh
1095 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
1096 << setw(3) << setprecision(1) << dop << ','
1097 << setprecision(3) << ell[2] << ",M,0.0,M,,";
1098
1099 writeNMEAstr(QString(strGGA.str().c_str()));
1100
1101 return success;
1102}
1103
1104// Outlier Detection
1105////////////////////////////////////////////////////////////////////////////
1106int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
1107 const ColumnVector& vv,
1108 QMap<QString, t_satData*>& satDataGPS,
1109 QMap<QString, t_satData*>& satDataGlo,
1110 QMap<QString, t_satData*>& satDataGal) {
1111
1112 double vvMaxCodeGPS = 0.0;
1113 double vvMaxPhaseGPS = 0.0;
1114 double vvMaxPhaseGlo = 0.0;
1115 double vvMaxCodeGal = 0.0;
1116 double vvMaxPhaseGal = 0.0;
1117 QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
1118 QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
1119 QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
1120 QMutableMapIterator<QString, t_satData*> itMaxCodeGal(satDataGPS);
1121 QMutableMapIterator<QString, t_satData*> itMaxPhaseGal(satDataGPS);
1122
1123 int ii = 0;
1124
1125 // GPS code and (optionally) phase residuals
1126 // -----------------------------------------
1127 QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
1128 while (itGPS.hasNext()) {
1129 itGPS.next();
1130 ++ii;
1131
1132 if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
1133 vvMaxCodeGPS = fabs(vv(ii));
1134 itMaxCodeGPS = itGPS;
1135 }
1136
1137 if (_usePhase) {
1138 ++ii;
1139 if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
1140 vvMaxPhaseGPS = fabs(vv(ii));
1141 itMaxPhaseGPS = itGPS;
1142 }
1143 }
1144 }
1145
1146 // Glonass phase residuals
1147 // -----------------------
1148 if (_usePhase) {
1149 QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
1150 while (itGlo.hasNext()) {
1151 itGlo.next();
1152 ++ii;
1153 if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
1154 vvMaxPhaseGlo = fabs(vv(ii));
1155 itMaxPhaseGlo = itGlo;
1156 }
1157 }
1158 }
1159
1160 // Galileo code and (optionally) phase residuals
1161 // ---------------------------------------------
1162 QMutableMapIterator<QString, t_satData*> itGal(satDataGal);
1163 while (itGal.hasNext()) {
1164 itGal.next();
1165 ++ii;
1166
1167 if (vvMaxCodeGal == 0.0 || fabs(vv(ii)) > vvMaxCodeGal) {
1168 vvMaxCodeGal = fabs(vv(ii));
1169 itMaxCodeGal = itGal;
1170 }
1171
1172 if (_usePhase) {
1173 ++ii;
1174 if (vvMaxPhaseGal == 0.0 || fabs(vv(ii)) > vvMaxPhaseGal) {
1175 vvMaxPhaseGal = fabs(vv(ii));
1176 itMaxPhaseGal = itGal;
1177 }
1178 }
1179 }
1180
1181 if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
1182 QString prn = itMaxPhaseGlo.key();
1183 t_satData* satData = itMaxPhaseGlo.value();
1184 delete satData;
1185 itMaxPhaseGlo.remove();
1186 _QQ = QQsav;
1187
1188 _log += "Outlier Phase " + prn.toAscii() + " "
1189 + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
1190
1191 return 1;
1192 }
1193
1194 else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
1195 QString prn = itMaxCodeGPS.key();
1196 t_satData* satData = itMaxCodeGPS.value();
1197 delete satData;
1198 itMaxCodeGPS.remove();
1199 _QQ = QQsav;
1200
1201 _log += "Outlier Code " + prn.toAscii() + " "
1202 + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
1203
1204 return 1;
1205 }
1206 else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
1207 QString prn = itMaxPhaseGPS.key();
1208 t_satData* satData = itMaxPhaseGPS.value();
1209 delete satData;
1210 itMaxPhaseGPS.remove();
1211 _QQ = QQsav;
1212
1213 _log += "Outlier Phase " + prn.toAscii() + " "
1214 + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
1215
1216 return 1;
1217 }
1218
1219 else if (vvMaxCodeGal > MAXRES_CODE_GAL) {
1220 QString prn = itMaxCodeGal.key();
1221 t_satData* satData = itMaxCodeGal.value();
1222 delete satData;
1223 itMaxCodeGal.remove();
1224 _QQ = QQsav;
1225
1226 _log += "Outlier Code " + prn.toAscii() + " "
1227 + QByteArray::number(vvMaxCodeGal, 'f', 3) + "\n";
1228
1229 return 1;
1230 }
1231 else if (vvMaxPhaseGal > MAXRES_PHASE_GAL) {
1232 QString prn = itMaxPhaseGal.key();
1233 t_satData* satData = itMaxPhaseGal.value();
1234 delete satData;
1235 itMaxPhaseGal.remove();
1236 _QQ = QQsav;
1237
1238 _log += "Outlier Phase " + prn.toAscii() + " "
1239 + QByteArray::number(vvMaxPhaseGal, 'f', 3) + "\n";
1240
1241 return 1;
1242 }
1243
1244 return 0;
1245}
1246
1247//
1248////////////////////////////////////////////////////////////////////////////
1249void bncModel::writeNMEAstr(const QString& nmStr) {
1250
1251 unsigned char XOR = 0;
1252 for (int ii = 0; ii < nmStr.length(); ii++) {
1253 XOR ^= (unsigned char) nmStr[ii].toAscii();
1254 }
1255
1256 QString outStr = '$' + nmStr
1257 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
1258
1259 if (_nmeaStream) {
1260 *_nmeaStream << outStr;
1261 _nmeaStream->flush();
1262 }
1263
1264 emit newNMEAstr(outStr.toAscii());
1265}
1266
1267////
1268//////////////////////////////////////////////////////////////////////////////
1269void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1270 const DiagonalMatrix& PP,
1271 SymmetricMatrix& QQ, ColumnVector& dx) {
1272
1273 int nObs = AA.Nrows();
1274 int nPar = AA.Ncols();
1275
1276 UpperTriangularMatrix SS = Cholesky(QQ).t();
1277
1278 Matrix SA = SS*AA.t();
1279 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
1280 for (int ii = 1; ii <= nObs; ++ii) {
1281 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
1282 }
1283
1284 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
1285 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
1286
1287 UpperTriangularMatrix UU;
1288 QRZ(SRF, UU);
1289
1290 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
1291 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
1292 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
1293
1294 UpperTriangularMatrix SHi = SH_rt.i();
1295
1296 Matrix KT = SHi * YY;
1297 SymmetricMatrix Hi; Hi << SHi * SHi.t();
1298
1299 dx = KT.t() * ll;
1300 QQ << (SS.t() * SS);
1301}
1302
1303// Phase Wind-Up Correction
1304///////////////////////////////////////////////////////////////////////////
1305double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1306 const ColumnVector& rRec) {
1307
1308 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1309
1310 // First time - initialize to zero
1311 // -------------------------------
1312 if (!_windUpTime.contains(prn)) {
1313 _windUpTime[prn] = Mjd;
1314 _windUpSum[prn] = 0.0;
1315 }
1316
1317 // Compute the correction for new time
1318 // -----------------------------------
1319 else if (_windUpTime[prn] != Mjd) {
1320 _windUpTime[prn] = Mjd;
1321
1322 // Unit Vector GPS Satellite --> Receiver
1323 // --------------------------------------
1324 ColumnVector rho = rRec - rSat;
1325 rho /= rho.norm_Frobenius();
1326
1327 // GPS Satellite unit Vectors sz, sy, sx
1328 // -------------------------------------
1329 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1330
1331 ColumnVector xSun = Sun(Mjd);
1332 xSun /= xSun.norm_Frobenius();
1333
1334 ColumnVector sy = crossproduct(sz, xSun);
1335 ColumnVector sx = crossproduct(sy, sz);
1336
1337 // Effective Dipole of the GPS Satellite Antenna
1338 // ---------------------------------------------
1339 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1340 - crossproduct(rho, sy);
1341
1342 // Receiver unit Vectors rx, ry
1343 // ----------------------------
1344 ColumnVector rx(3);
1345 ColumnVector ry(3);
1346
1347 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1348 double neu[3];
1349
1350 neu[0] = 1.0;
1351 neu[1] = 0.0;
1352 neu[2] = 0.0;
1353 neu2xyz(recEll, neu, rx.data());
1354
1355 neu[0] = 0.0;
1356 neu[1] = -1.0;
1357 neu[2] = 0.0;
1358 neu2xyz(recEll, neu, ry.data());
1359
1360 // Effective Dipole of the Receiver Antenna
1361 // ----------------------------------------
1362 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1363 + crossproduct(rho, ry);
1364
1365 // Resulting Effect
1366 // ----------------
1367 double alpha = DotProduct(dipSat,dipRec) /
1368 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1369
1370 if (alpha > 1.0) alpha = 1.0;
1371 if (alpha < -1.0) alpha = -1.0;
1372
1373 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1374
1375 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1376 dphi = -dphi;
1377 }
1378
1379 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1380 }
1381
1382 return _windUpSum[prn];
1383}
Note: See TracBrowser for help on using the repository browser.