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 |
|
---|
54 | using namespace std;
|
---|
55 |
|
---|
56 | const unsigned MINOBS = 4;
|
---|
57 | const double MINELE_GPS = 10.0 * M_PI / 180.0;
|
---|
58 | const double MINELE_GLO = 10.0 * M_PI / 180.0;
|
---|
59 | const double MAXRES_CODE_GPS = 10.0;
|
---|
60 | const double MAXRES_PHASE_GPS = 0.10;
|
---|
61 | const double MAXRES_PHASE_GLO = 0.05;
|
---|
62 | const double sig_crd_0 = 100.0;
|
---|
63 | const double sig_crd_p = 100.0;
|
---|
64 | const double sig_clk_0 = 1000.0;
|
---|
65 | const double sig_trp_0 = 0.10;
|
---|
66 | const double sig_trp_p = 1e-8;
|
---|
67 | const double sig_amb_0_GPS = 1000.0;
|
---|
68 | const double sig_amb_0_GLO = 1000.0;
|
---|
69 | const double sig_L3_GPS = 0.02;
|
---|
70 | const double sig_L3_GLO = 0.05;
|
---|
71 |
|
---|
72 | // Constructor
|
---|
73 | ////////////////////////////////////////////////////////////////////////////
|
---|
74 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
75 | const QString& prnIn) {
|
---|
76 | type = typeIn;
|
---|
77 | index = indexIn;
|
---|
78 | prn = prnIn;
|
---|
79 | index_old = 0;
|
---|
80 | xx = 0.0;
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Destructor
|
---|
85 | ////////////////////////////////////////////////////////////////////////////
|
---|
86 | bncParam::~bncParam() {
|
---|
87 | }
|
---|
88 |
|
---|
89 | // Partial
|
---|
90 | ////////////////////////////////////////////////////////////////////////////
|
---|
91 | double bncParam::partial(t_satData* satData, bool phase) {
|
---|
92 |
|
---|
93 | // Coordinates
|
---|
94 | // -----------
|
---|
95 | if (type == CRD_X) {
|
---|
96 | return (xx - satData->xx(1)) / satData->rho;
|
---|
97 | }
|
---|
98 | else if (type == CRD_Y) {
|
---|
99 | return (xx - satData->xx(2)) / satData->rho;
|
---|
100 | }
|
---|
101 | else if (type == CRD_Z) {
|
---|
102 | return (xx - satData->xx(3)) / satData->rho;
|
---|
103 | }
|
---|
104 |
|
---|
105 | // Receiver Clocks
|
---|
106 | // ---------------
|
---|
107 | else if (type == RECCLK) {
|
---|
108 | return 1.0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | // Troposphere
|
---|
112 | // -----------
|
---|
113 | else if (type == TROPO) {
|
---|
114 | return 1.0 / sin(satData->eleSat);
|
---|
115 | }
|
---|
116 |
|
---|
117 | // Ambiguities
|
---|
118 | // -----------
|
---|
119 | else if (type == AMB_L3) {
|
---|
120 | if (phase && satData->prn == prn) {
|
---|
121 | return 1.0;
|
---|
122 | }
|
---|
123 | else {
|
---|
124 | return 0.0;
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | // Default return
|
---|
129 | // --------------
|
---|
130 | return 0.0;
|
---|
131 | }
|
---|
132 |
|
---|
133 | // Constructor
|
---|
134 | ////////////////////////////////////////////////////////////////////////////
|
---|
135 | bncModel::bncModel(QByteArray staID) {
|
---|
136 |
|
---|
137 | _staID = staID;
|
---|
138 |
|
---|
139 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
140 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
141 |
|
---|
142 | bncSettings settings;
|
---|
143 |
|
---|
144 | _static = false;
|
---|
145 | if ( Qt::CheckState(settings.value("pppStatic").toInt()) == Qt::Checked) {
|
---|
146 | _static = true;
|
---|
147 | }
|
---|
148 |
|
---|
149 | _usePhase = false;
|
---|
150 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
|
---|
151 | _usePhase = true;
|
---|
152 | }
|
---|
153 |
|
---|
154 | _estTropo = false;
|
---|
155 | if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
|
---|
156 | _estTropo = true;
|
---|
157 | }
|
---|
158 |
|
---|
159 | _xcBanc.ReSize(4); _xcBanc = 0.0;
|
---|
160 | _ellBanc.ReSize(3); _ellBanc = 0.0;
|
---|
161 |
|
---|
162 | if (_usePhase &&
|
---|
163 | Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
|
---|
164 | _useGlonass = true;
|
---|
165 | }
|
---|
166 | else {
|
---|
167 | _useGlonass = false;
|
---|
168 | }
|
---|
169 |
|
---|
170 | int nextPar = 0;
|
---|
171 | _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
|
---|
172 | _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
|
---|
173 | _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
|
---|
174 | _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
|
---|
175 | if (_estTropo) {
|
---|
176 | _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
|
---|
177 | }
|
---|
178 |
|
---|
179 | unsigned nPar = _params.size();
|
---|
180 |
|
---|
181 | _QQ.ReSize(nPar);
|
---|
182 |
|
---|
183 | _QQ = 0.0;
|
---|
184 |
|
---|
185 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
186 | bncParam* pp = _params[iPar-1];
|
---|
187 | if (pp->isCrd()) {
|
---|
188 | _QQ(iPar,iPar) = sig_crd_0 * sig_crd_0;
|
---|
189 | }
|
---|
190 | else if (pp->type == bncParam::RECCLK) {
|
---|
191 | _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
|
---|
192 | }
|
---|
193 | else if (pp->type == bncParam::TROPO) {
|
---|
194 | _QQ(iPar,iPar) = sig_trp_0 * sig_trp_0;
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | // NMEA Output
|
---|
199 | // -----------
|
---|
200 | QString nmeaFileName = settings.value("nmeaFile").toString();
|
---|
201 | if (nmeaFileName.isEmpty()) {
|
---|
202 | _nmeaFile = 0;
|
---|
203 | _nmeaStream = 0;
|
---|
204 | }
|
---|
205 | else {
|
---|
206 | expandEnvVar(nmeaFileName);
|
---|
207 | _nmeaFile = new QFile(nmeaFileName);
|
---|
208 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
209 | _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
210 | }
|
---|
211 | else {
|
---|
212 | _nmeaFile->open(QIODevice::WriteOnly);
|
---|
213 | }
|
---|
214 | _nmeaStream = new QTextStream();
|
---|
215 | _nmeaStream->setDevice(_nmeaFile);
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | // Destructor
|
---|
220 | ////////////////////////////////////////////////////////////////////////////
|
---|
221 | bncModel::~bncModel() {
|
---|
222 | delete _nmeaStream;
|
---|
223 | delete _nmeaFile;
|
---|
224 | }
|
---|
225 |
|
---|
226 | // Bancroft Solution
|
---|
227 | ////////////////////////////////////////////////////////////////////////////
|
---|
228 | t_irc bncModel::cmpBancroft(t_epoData* epoData) {
|
---|
229 |
|
---|
230 | if (epoData->sizeGPS() < MINOBS) {
|
---|
231 | _log += "bncModel::cmpBancroft: not enough data\n";
|
---|
232 | return failure;
|
---|
233 | }
|
---|
234 |
|
---|
235 | Matrix BB(epoData->sizeGPS(), 4);
|
---|
236 |
|
---|
237 | QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
|
---|
238 | int iObs = 0;
|
---|
239 | while (it.hasNext()) {
|
---|
240 | ++iObs;
|
---|
241 | it.next();
|
---|
242 | QString prn = it.key();
|
---|
243 | t_satData* satData = it.value();
|
---|
244 | BB(iObs, 1) = satData->xx(1);
|
---|
245 | BB(iObs, 2) = satData->xx(2);
|
---|
246 | BB(iObs, 3) = satData->xx(3);
|
---|
247 | BB(iObs, 4) = satData->P3 + satData->clk;
|
---|
248 | }
|
---|
249 |
|
---|
250 | bancroft(BB, _xcBanc);
|
---|
251 |
|
---|
252 | // Ellipsoidal Coordinates
|
---|
253 | // ------------------------
|
---|
254 | xyz2ell(_xcBanc.data(), _ellBanc.data());
|
---|
255 |
|
---|
256 | // Compute Satellite Elevations
|
---|
257 | // ----------------------------
|
---|
258 | QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
---|
259 | while (iGPS.hasNext()) {
|
---|
260 | iGPS.next();
|
---|
261 | QString prn = iGPS.key();
|
---|
262 | t_satData* satData = iGPS.value();
|
---|
263 |
|
---|
264 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
265 | double rho = rr.norm_Frobenius();
|
---|
266 |
|
---|
267 | double neu[3];
|
---|
268 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
269 |
|
---|
270 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
271 | if (neu[2] < 0) {
|
---|
272 | satData->eleSat *= -1.0;
|
---|
273 | }
|
---|
274 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
275 |
|
---|
276 | if (satData->eleSat < MINELE_GPS) {
|
---|
277 | delete satData;
|
---|
278 | iGPS.remove();
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
---|
283 | while (iGlo.hasNext()) {
|
---|
284 | iGlo.next();
|
---|
285 | QString prn = iGlo.key();
|
---|
286 | t_satData* satData = iGlo.value();
|
---|
287 |
|
---|
288 | ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
|
---|
289 | double rho = rr.norm_Frobenius();
|
---|
290 |
|
---|
291 | double neu[3];
|
---|
292 | xyz2neu(_ellBanc.data(), rr.data(), neu);
|
---|
293 |
|
---|
294 | satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
|
---|
295 | if (neu[2] < 0) {
|
---|
296 | satData->eleSat *= -1.0;
|
---|
297 | }
|
---|
298 | satData->azSat = atan2(neu[1], neu[0]);
|
---|
299 |
|
---|
300 | if (satData->eleSat < MINELE_GLO) {
|
---|
301 | delete satData;
|
---|
302 | iGlo.remove();
|
---|
303 | }
|
---|
304 | }
|
---|
305 |
|
---|
306 | return success;
|
---|
307 | }
|
---|
308 |
|
---|
309 | // Computed Value
|
---|
310 | ////////////////////////////////////////////////////////////////////////////
|
---|
311 | double bncModel::cmpValue(t_satData* satData) {
|
---|
312 |
|
---|
313 | ColumnVector xRec(3);
|
---|
314 | xRec(1) = x();
|
---|
315 | xRec(2) = y();
|
---|
316 | xRec(3) = z();
|
---|
317 |
|
---|
318 | double rho0 = (satData->xx - xRec).norm_Frobenius();
|
---|
319 | double dPhi = t_CST::omega * rho0 / t_CST::c;
|
---|
320 |
|
---|
321 | xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
|
---|
322 | xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
|
---|
323 | xRec(3) = z();
|
---|
324 |
|
---|
325 | tides(_time, xRec);
|
---|
326 |
|
---|
327 | satData->rho = (satData->xx - xRec).norm_Frobenius();
|
---|
328 |
|
---|
329 | double tropDelay = delay_saast(satData->eleSat) +
|
---|
330 | trp() / sin(satData->eleSat);
|
---|
331 |
|
---|
332 | return satData->rho + clk() - satData->clk + tropDelay;
|
---|
333 | }
|
---|
334 |
|
---|
335 | // Tropospheric Model (Saastamoinen)
|
---|
336 | ////////////////////////////////////////////////////////////////////////////
|
---|
337 | double bncModel::delay_saast(double Ele) {
|
---|
338 |
|
---|
339 | double height = _ellBanc(3);
|
---|
340 |
|
---|
341 | double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
|
---|
342 | double TT = 18.0 - height * 0.0065 + 273.15;
|
---|
343 | double hh = 50.0 * exp(-6.396e-4 * height);
|
---|
344 | double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
|
---|
345 |
|
---|
346 | double h_km = height / 1000.0;
|
---|
347 |
|
---|
348 | if (h_km < 0.0) h_km = 0.0;
|
---|
349 | if (h_km > 5.0) h_km = 5.0;
|
---|
350 | int ii = int(h_km + 1);
|
---|
351 | double href = ii - 1;
|
---|
352 |
|
---|
353 | double bCor[6];
|
---|
354 | bCor[0] = 1.156;
|
---|
355 | bCor[1] = 1.006;
|
---|
356 | bCor[2] = 0.874;
|
---|
357 | bCor[3] = 0.757;
|
---|
358 | bCor[4] = 0.654;
|
---|
359 | bCor[5] = 0.563;
|
---|
360 |
|
---|
361 | double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
|
---|
362 |
|
---|
363 | double zen = M_PI/2.0 - Ele;
|
---|
364 |
|
---|
365 | return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
|
---|
366 | }
|
---|
367 |
|
---|
368 | // Prediction Step of the Filter
|
---|
369 | ////////////////////////////////////////////////////////////////////////////
|
---|
370 | void bncModel::predict(t_epoData* epoData) {
|
---|
371 |
|
---|
372 | bool firstCrd = x() == 0.0 && y() == 0.0 && z() == 0.0;
|
---|
373 |
|
---|
374 | // Predict Parameter values, add white noise
|
---|
375 | // -----------------------------------------
|
---|
376 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
377 | bncParam* pp = _params[iPar-1];
|
---|
378 |
|
---|
379 | // Coordinates
|
---|
380 | // -----------
|
---|
381 | if (pp->type == bncParam::CRD_X) {
|
---|
382 | if (firstCrd || !_static) {
|
---|
383 | pp->xx = _xcBanc(1);
|
---|
384 | }
|
---|
385 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
386 | }
|
---|
387 | else if (pp->type == bncParam::CRD_Y) {
|
---|
388 | if (firstCrd || !_static) {
|
---|
389 | pp->xx = _xcBanc(2);
|
---|
390 | }
|
---|
391 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
392 | }
|
---|
393 | else if (pp->type == bncParam::CRD_Z) {
|
---|
394 | if (firstCrd || !_static) {
|
---|
395 | pp->xx = _xcBanc(3);
|
---|
396 | }
|
---|
397 | _QQ(iPar,iPar) += sig_crd_p * sig_crd_p;
|
---|
398 | }
|
---|
399 |
|
---|
400 | // Receiver Clocks
|
---|
401 | // ---------------
|
---|
402 | else if (pp->type == bncParam::RECCLK) {
|
---|
403 | pp->xx = _xcBanc(4);
|
---|
404 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
405 | _QQ(iPar, jj) = 0.0;
|
---|
406 | }
|
---|
407 | _QQ(iPar,iPar) = sig_clk_0 * sig_clk_0;
|
---|
408 | }
|
---|
409 |
|
---|
410 | // Tropospheric Delay
|
---|
411 | // ------------------
|
---|
412 | else if (pp->type == bncParam::TROPO) {
|
---|
413 | _QQ(iPar,iPar) += sig_trp_p * sig_trp_p;
|
---|
414 | }
|
---|
415 | }
|
---|
416 |
|
---|
417 | // Add New Ambiguities if necessary
|
---|
418 | // --------------------------------
|
---|
419 | if (_usePhase) {
|
---|
420 |
|
---|
421 | // Make a copy of QQ and xx, set parameter indices
|
---|
422 | // -----------------------------------------------
|
---|
423 | SymmetricMatrix QQ_old = _QQ;
|
---|
424 |
|
---|
425 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
426 | _params[iPar-1]->index_old = _params[iPar-1]->index;
|
---|
427 | _params[iPar-1]->index = 0;
|
---|
428 | }
|
---|
429 |
|
---|
430 | // Remove Ambiguity Parameters without observations
|
---|
431 | // ------------------------------------------------
|
---|
432 | int iPar = 0;
|
---|
433 | QMutableVectorIterator<bncParam*> it(_params);
|
---|
434 | while (it.hasNext()) {
|
---|
435 | bncParam* par = it.next();
|
---|
436 | bool removed = false;
|
---|
437 | if (par->type == bncParam::AMB_L3) {
|
---|
438 | if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
|
---|
439 | epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() ) {
|
---|
440 | removed = true;
|
---|
441 | delete par;
|
---|
442 | it.remove();
|
---|
443 | }
|
---|
444 | }
|
---|
445 | if (! removed) {
|
---|
446 | ++iPar;
|
---|
447 | par->index = iPar;
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | // Add new ambiguity parameters
|
---|
452 | // ----------------------------
|
---|
453 | QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
|
---|
454 | while (iGPS.hasNext()) {
|
---|
455 | iGPS.next();
|
---|
456 | QString prn = iGPS.key();
|
---|
457 | t_satData* satData = iGPS.value();
|
---|
458 | bool found = false;
|
---|
459 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
460 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
461 | _params[iPar-1]->prn == prn) {
|
---|
462 | found = true;
|
---|
463 | break;
|
---|
464 | }
|
---|
465 | }
|
---|
466 | if (!found) {
|
---|
467 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
468 | _params.push_back(par);
|
---|
469 | par->xx = satData->L3 - cmpValue(satData);
|
---|
470 | }
|
---|
471 | }
|
---|
472 |
|
---|
473 | QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
|
---|
474 | while (iGlo.hasNext()) {
|
---|
475 | iGlo.next();
|
---|
476 | QString prn = iGlo.key();
|
---|
477 | t_satData* satData = iGlo.value();
|
---|
478 | bool found = false;
|
---|
479 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
480 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
481 | _params[iPar-1]->prn == prn) {
|
---|
482 | found = true;
|
---|
483 | break;
|
---|
484 | }
|
---|
485 | }
|
---|
486 | if (!found) {
|
---|
487 | bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
|
---|
488 | _params.push_back(par);
|
---|
489 | par->xx = satData->L3 - cmpValue(satData);
|
---|
490 | }
|
---|
491 | }
|
---|
492 |
|
---|
493 | int nPar = _params.size();
|
---|
494 | _QQ.ReSize(nPar); _QQ = 0.0;
|
---|
495 | for (int i1 = 1; i1 <= nPar; i1++) {
|
---|
496 | bncParam* p1 = _params[i1-1];
|
---|
497 | if (p1->index_old != 0) {
|
---|
498 | _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
|
---|
499 | for (int i2 = 1; i2 <= nPar; i2++) {
|
---|
500 | bncParam* p2 = _params[i2-1];
|
---|
501 | if (p2->index_old != 0) {
|
---|
502 | _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
|
---|
503 | }
|
---|
504 | }
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | for (int ii = 1; ii <= nPar; ii++) {
|
---|
509 | bncParam* par = _params[ii-1];
|
---|
510 | if (par->index_old == 0) {
|
---|
511 | if (par->prn[0] == 'R') {
|
---|
512 | _QQ(par->index, par->index) = sig_amb_0_GLO * sig_amb_0_GLO;
|
---|
513 | }
|
---|
514 | else {
|
---|
515 | _QQ(par->index, par->index) = sig_amb_0_GPS * sig_amb_0_GPS;
|
---|
516 | }
|
---|
517 | }
|
---|
518 | par->index_old = par->index;
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | }
|
---|
523 |
|
---|
524 | // Update Step of the Filter (currently just a single-epoch solution)
|
---|
525 | ////////////////////////////////////////////////////////////////////////////
|
---|
526 | t_irc bncModel::update(t_epoData* epoData) {
|
---|
527 |
|
---|
528 | bncSettings settings;
|
---|
529 | double sig_P3;
|
---|
530 | sig_P3 = 5.0;
|
---|
531 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked ) {
|
---|
532 | sig_P3 = settings.value("pppSigmaCode").toDouble();
|
---|
533 | if (sig_P3 < 0.3 || sig_P3 > 50.0) {
|
---|
534 | sig_P3 = 5.0;
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | _log.clear();
|
---|
539 |
|
---|
540 | _time = epoData->tt;
|
---|
541 |
|
---|
542 | _log += "Single Point Positioning of Epoch "
|
---|
543 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
544 | "\n--------------------------------------------------------------\n";
|
---|
545 |
|
---|
546 | SymmetricMatrix QQsav;
|
---|
547 | ColumnVector dx;
|
---|
548 | ColumnVector vv;
|
---|
549 |
|
---|
550 | // Loop over all outliers
|
---|
551 | // ----------------------
|
---|
552 | do {
|
---|
553 |
|
---|
554 | // Bancroft Solution
|
---|
555 | // -----------------
|
---|
556 | if (cmpBancroft(epoData) != success) {
|
---|
557 | emit newMessage(_log, false);
|
---|
558 | return failure;
|
---|
559 | }
|
---|
560 |
|
---|
561 | // Status Prediction
|
---|
562 | // -----------------
|
---|
563 | predict(epoData);
|
---|
564 |
|
---|
565 | // Create First-Design Matrix
|
---|
566 | // --------------------------
|
---|
567 | unsigned nPar = _params.size();
|
---|
568 | unsigned nObs = 0;
|
---|
569 | if (_usePhase) {
|
---|
570 | nObs = 2 * epoData->sizeGPS() + epoData->sizeGlo();
|
---|
571 | }
|
---|
572 | else {
|
---|
573 | nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
|
---|
574 | }
|
---|
575 |
|
---|
576 | if (nObs < nPar) {
|
---|
577 | _log += "bncModel::update: nObs < nPar\n";
|
---|
578 | emit newMessage(_log, false);
|
---|
579 | return failure;
|
---|
580 | }
|
---|
581 |
|
---|
582 | Matrix AA(nObs, nPar); // first design matrix
|
---|
583 | ColumnVector ll(nObs); // tems observed-computed
|
---|
584 | DiagonalMatrix PP(nObs); PP = 0.0;
|
---|
585 |
|
---|
586 | unsigned iObs = 0;
|
---|
587 |
|
---|
588 | // GPS code and (optionally) phase observations
|
---|
589 | // --------------------------------------------
|
---|
590 | QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
|
---|
591 | while (itGPS.hasNext()) {
|
---|
592 | ++iObs;
|
---|
593 | itGPS.next();
|
---|
594 | QString prn = itGPS.key();
|
---|
595 | t_satData* satData = itGPS.value();
|
---|
596 |
|
---|
597 | double rhoCmp = cmpValue(satData);
|
---|
598 |
|
---|
599 | ll(iObs) = satData->P3 - rhoCmp;
|
---|
600 | PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3);
|
---|
601 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
602 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
|
---|
603 | }
|
---|
604 |
|
---|
605 | if (_usePhase) {
|
---|
606 | ++iObs;
|
---|
607 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
608 | PP(iObs,iObs) = 1.0 / (sig_L3_GPS * sig_L3_GPS);
|
---|
609 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
610 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
611 | _params[iPar-1]->prn == prn) {
|
---|
612 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
613 | }
|
---|
614 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
615 | }
|
---|
616 | }
|
---|
617 | }
|
---|
618 |
|
---|
619 | // Glonass phase observations
|
---|
620 | // --------------------------
|
---|
621 | if (_usePhase) {
|
---|
622 | QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
|
---|
623 | while (itGlo.hasNext()) {
|
---|
624 | ++iObs;
|
---|
625 | itGlo.next();
|
---|
626 | QString prn = itGlo.key();
|
---|
627 | t_satData* satData = itGlo.value();
|
---|
628 |
|
---|
629 | double rhoCmp = cmpValue(satData);
|
---|
630 |
|
---|
631 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
632 |
|
---|
633 | PP(iObs,iObs) = 1.0 / (sig_L3_GLO * sig_L3_GLO);
|
---|
634 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
635 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
636 | _params[iPar-1]->prn == prn) {
|
---|
637 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
638 | }
|
---|
639 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
640 | }
|
---|
641 | }
|
---|
642 | }
|
---|
643 |
|
---|
644 | // Compute Filter Update
|
---|
645 | // ---------------------
|
---|
646 | QQsav = _QQ;
|
---|
647 |
|
---|
648 | kalman(AA, ll, PP, _QQ, dx);
|
---|
649 |
|
---|
650 | vv = ll - AA * dx;
|
---|
651 |
|
---|
652 | ostringstream strA;
|
---|
653 | strA.setf(ios::fixed);
|
---|
654 | ColumnVector vv_code(epoData->sizeGPS());
|
---|
655 | ColumnVector vv_phase(epoData->sizeGPS());
|
---|
656 | ColumnVector vv_glo(epoData->sizeGlo());
|
---|
657 |
|
---|
658 | for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
|
---|
659 | if (_usePhase) {
|
---|
660 | vv_code(iobs) = vv(2*iobs-1);
|
---|
661 | vv_phase(iobs) = vv(2*iobs);
|
---|
662 | }
|
---|
663 | else {
|
---|
664 | vv_code(iobs) = vv(iobs);
|
---|
665 | }
|
---|
666 | }
|
---|
667 | if (_useGlonass) {
|
---|
668 | for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
|
---|
669 | vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
|
---|
670 | }
|
---|
671 | }
|
---|
672 |
|
---|
673 | strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
|
---|
674 | if (_usePhase) {
|
---|
675 | strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
|
---|
676 | }
|
---|
677 | if (_useGlonass) {
|
---|
678 | strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
|
---|
679 | }
|
---|
680 | _log += strA.str().c_str();
|
---|
681 |
|
---|
682 | } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
|
---|
683 | epoData->satDataGlo) != 0);
|
---|
684 |
|
---|
685 | // Set Solution Vector
|
---|
686 | // -------------------
|
---|
687 | ostringstream strB;
|
---|
688 | strB.setf(ios::fixed);
|
---|
689 | QVectorIterator<bncParam*> itPar(_params);
|
---|
690 | while (itPar.hasNext()) {
|
---|
691 | bncParam* par = itPar.next();
|
---|
692 | par->xx += dx(par->index);
|
---|
693 |
|
---|
694 | if (par->type == bncParam::RECCLK) {
|
---|
695 | strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
|
---|
696 | << " +- " << setw(6) << setprecision(3)
|
---|
697 | << sqrt(_QQ(par->index,par->index));
|
---|
698 | }
|
---|
699 | else if (par->type == bncParam::AMB_L3) {
|
---|
700 | strB << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
701 | << setw(6) << setprecision(3) << par->xx
|
---|
702 | << " +- " << setw(6) << setprecision(3)
|
---|
703 | << sqrt(_QQ(par->index,par->index));
|
---|
704 | }
|
---|
705 | else if (par->type == bncParam::TROPO) {
|
---|
706 | strB << "\n trp = " << par->prn.toAscii().data()
|
---|
707 | << setw(7) << setprecision(3) << delay_saast(M_PI/2.0) << " "
|
---|
708 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
---|
709 | << " +- " << setw(6) << setprecision(3)
|
---|
710 | << sqrt(_QQ(par->index,par->index));
|
---|
711 | }
|
---|
712 | }
|
---|
713 | strB << '\n';
|
---|
714 | _log += strB.str().c_str();
|
---|
715 | emit newMessage(_log, false);
|
---|
716 |
|
---|
717 | // Final Message (both log file and screen)
|
---|
718 | // ----------------------------------------
|
---|
719 | ostringstream strC;
|
---|
720 | strC.setf(ios::fixed);
|
---|
721 | strC << _staID.data() << " PPP "
|
---|
722 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
723 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
724 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
725 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
726 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
727 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
728 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
729 |
|
---|
730 | // NEU Output
|
---|
731 | // ----------
|
---|
732 | if (settings.value("pppOrigin").toString() == "X Y Z") {
|
---|
733 | double xyzRef[3];
|
---|
734 | double ellRef[3];
|
---|
735 | double _xyz[3];
|
---|
736 | double _neu[3];
|
---|
737 | xyzRef[0] = settings.value("pppRefCrdX").toDouble();
|
---|
738 | xyzRef[1] = settings.value("pppRefCrdY").toDouble();
|
---|
739 | xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
|
---|
740 | _xyz[0] = x() - xyzRef[0];
|
---|
741 | _xyz[1] = y() - xyzRef[1];
|
---|
742 | _xyz[2] = z() - xyzRef[2];
|
---|
743 | xyz2ell(xyzRef, ellRef);
|
---|
744 | xyz2neu(ellRef, _xyz, _neu);
|
---|
745 | strC << " NEU "
|
---|
746 | << setw(8) << setprecision(3) << _neu[0] << " "
|
---|
747 | << setw(8) << setprecision(3) << _neu[1] << " "
|
---|
748 | << setw(8) << setprecision(3) << _neu[2];
|
---|
749 | }
|
---|
750 |
|
---|
751 | strC << endl;
|
---|
752 |
|
---|
753 | emit newMessage(QByteArray(strC.str().c_str()), true);
|
---|
754 |
|
---|
755 | // NMEA Output
|
---|
756 | // -----------
|
---|
757 | double xyz[3];
|
---|
758 | xyz[0] = x();
|
---|
759 | xyz[1] = y();
|
---|
760 | xyz[2] = z();
|
---|
761 | double ell[3];
|
---|
762 | xyz2ell(xyz, ell);
|
---|
763 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
764 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
765 |
|
---|
766 | char phiCh = 'N';
|
---|
767 | if (phiDeg < 0) {
|
---|
768 | phiDeg = -phiDeg;
|
---|
769 | phiCh = 'S';
|
---|
770 | }
|
---|
771 | char lamCh = 'E';
|
---|
772 | if (lamDeg < 0) {
|
---|
773 | lamDeg = -lamDeg;
|
---|
774 | lamCh = 'W';
|
---|
775 | }
|
---|
776 |
|
---|
777 | string datestr = epoData->tt.datestr(0); // yyyymmdd
|
---|
778 | ostringstream strRMC;
|
---|
779 | strRMC.setf(ios::fixed);
|
---|
780 | strRMC << "GPRMC,"
|
---|
781 | << epoData->tt.timestr(0,0) << ",A,"
|
---|
782 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
783 | << setw(6) << setprecision(3) << setfill('0')
|
---|
784 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
785 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
786 | << setw(6) << setprecision(3) << setfill('0')
|
---|
787 | << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
|
---|
788 | << datestr[6] << datestr[7] << datestr[4] << datestr[5]
|
---|
789 | << datestr[2] << datestr[3] << ",,";
|
---|
790 |
|
---|
791 | writeNMEAstr(QString(strRMC.str().c_str()));
|
---|
792 |
|
---|
793 | double dop = 2.0; // TODO
|
---|
794 |
|
---|
795 | ostringstream strGGA;
|
---|
796 | strGGA.setf(ios::fixed);
|
---|
797 | strGGA << "GPGGA,"
|
---|
798 | << epoData->tt.timestr(0,0) << ','
|
---|
799 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
800 | << setw(10) << setprecision(7) << setfill('0')
|
---|
801 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
802 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
803 | << setw(10) << setprecision(7) << setfill('0')
|
---|
804 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
805 | << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
|
---|
806 | << setw(3) << setprecision(1) << dop << ','
|
---|
807 | << setprecision(3) << ell[2] << ",M,0.0,M,,";
|
---|
808 |
|
---|
809 | writeNMEAstr(QString(strGGA.str().c_str()));
|
---|
810 |
|
---|
811 | return success;
|
---|
812 | }
|
---|
813 |
|
---|
814 | // Outlier Detection
|
---|
815 | ////////////////////////////////////////////////////////////////////////////
|
---|
816 | int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
|
---|
817 | const ColumnVector& vv,
|
---|
818 | QMap<QString, t_satData*>& satDataGPS,
|
---|
819 | QMap<QString, t_satData*>& satDataGlo) {
|
---|
820 |
|
---|
821 | double vvMaxCodeGPS = 0.0;
|
---|
822 | double vvMaxPhaseGPS = 0.0;
|
---|
823 | double vvMaxPhaseGlo = 0.0;
|
---|
824 | QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
|
---|
825 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
|
---|
826 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
|
---|
827 |
|
---|
828 | int ii = 0;
|
---|
829 |
|
---|
830 | // GPS code and (optionally) phase residuals
|
---|
831 | // -----------------------------------------
|
---|
832 | QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
|
---|
833 | while (itGPS.hasNext()) {
|
---|
834 | itGPS.next();
|
---|
835 | ++ii;
|
---|
836 |
|
---|
837 | if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
|
---|
838 | vvMaxCodeGPS = fabs(vv(ii));
|
---|
839 | itMaxCodeGPS = itGPS;
|
---|
840 | }
|
---|
841 |
|
---|
842 | if (_usePhase) {
|
---|
843 | ++ii;
|
---|
844 | if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
|
---|
845 | vvMaxPhaseGPS = fabs(vv(ii));
|
---|
846 | itMaxPhaseGPS = itGPS;
|
---|
847 | }
|
---|
848 | }
|
---|
849 | }
|
---|
850 |
|
---|
851 | // Glonass phase residuals
|
---|
852 | // -----------------------
|
---|
853 | if (_usePhase) {
|
---|
854 | QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
|
---|
855 | while (itGlo.hasNext()) {
|
---|
856 | itGlo.next();
|
---|
857 | ++ii;
|
---|
858 | if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
|
---|
859 | vvMaxPhaseGlo = fabs(vv(ii));
|
---|
860 | itMaxPhaseGlo = itGlo;
|
---|
861 | }
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
|
---|
866 | QString prn = itMaxPhaseGlo.key();
|
---|
867 | t_satData* satData = itMaxPhaseGlo.value();
|
---|
868 | delete satData;
|
---|
869 | itMaxPhaseGlo.remove();
|
---|
870 | _QQ = QQsav;
|
---|
871 |
|
---|
872 | _log += "Outlier Phase " + prn.toAscii() + " "
|
---|
873 | + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
|
---|
874 |
|
---|
875 | return 1;
|
---|
876 | }
|
---|
877 |
|
---|
878 | else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
|
---|
879 | QString prn = itMaxCodeGPS.key();
|
---|
880 | t_satData* satData = itMaxCodeGPS.value();
|
---|
881 | delete satData;
|
---|
882 | itMaxCodeGPS.remove();
|
---|
883 | _QQ = QQsav;
|
---|
884 |
|
---|
885 | _log += "Outlier Code " + prn.toAscii() + " "
|
---|
886 | + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
|
---|
887 |
|
---|
888 | return 1;
|
---|
889 | }
|
---|
890 | else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
|
---|
891 | QString prn = itMaxPhaseGPS.key();
|
---|
892 | t_satData* satData = itMaxPhaseGPS.value();
|
---|
893 | delete satData;
|
---|
894 | itMaxPhaseGPS.remove();
|
---|
895 | _QQ = QQsav;
|
---|
896 |
|
---|
897 | _log += "Outlier Phase " + prn.toAscii() + " "
|
---|
898 | + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
|
---|
899 |
|
---|
900 | return 1;
|
---|
901 | }
|
---|
902 |
|
---|
903 | return 0;
|
---|
904 | }
|
---|
905 |
|
---|
906 | //
|
---|
907 | ////////////////////////////////////////////////////////////////////////////
|
---|
908 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
---|
909 |
|
---|
910 | unsigned char XOR = 0;
|
---|
911 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
912 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
913 | }
|
---|
914 |
|
---|
915 | QString outStr = '$' + nmStr
|
---|
916 | + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
---|
917 |
|
---|
918 | if (_nmeaStream) {
|
---|
919 | *_nmeaStream << outStr;
|
---|
920 | _nmeaStream->flush();
|
---|
921 | }
|
---|
922 |
|
---|
923 | emit newNMEAstr(outStr.toAscii());
|
---|
924 | }
|
---|
925 |
|
---|
926 |
|
---|
927 | ////
|
---|
928 | //////////////////////////////////////////////////////////////////////////////
|
---|
929 | void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
|
---|
930 | const DiagonalMatrix& PP,
|
---|
931 | SymmetricMatrix& QQ, ColumnVector& dx) {
|
---|
932 |
|
---|
933 | int nObs = AA.Nrows();
|
---|
934 | int nPar = AA.Ncols();
|
---|
935 |
|
---|
936 | UpperTriangularMatrix SS = Cholesky(QQ).t();
|
---|
937 |
|
---|
938 | Matrix SA = SS*AA.t();
|
---|
939 | Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
|
---|
940 | for (int ii = 1; ii <= nObs; ++ii) {
|
---|
941 | SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
|
---|
942 | }
|
---|
943 |
|
---|
944 | SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
|
---|
945 | SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
|
---|
946 |
|
---|
947 | UpperTriangularMatrix UU;
|
---|
948 | QRZ(SRF, UU);
|
---|
949 |
|
---|
950 | SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
|
---|
951 | UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
|
---|
952 | Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
|
---|
953 |
|
---|
954 | UpperTriangularMatrix SHi = SH_rt.i();
|
---|
955 |
|
---|
956 | Matrix KT = SHi * YY;
|
---|
957 | SymmetricMatrix Hi; Hi << SHi * SHi.t();
|
---|
958 |
|
---|
959 | dx = KT.t() * ll;
|
---|
960 | QQ << (SS.t() * SS);
|
---|
961 | }
|
---|
962 |
|
---|
963 | // Phase Wind-Up Correction
|
---|
964 | ///////////////////////////////////////////////////////////////////////////
|
---|
965 | double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
|
---|
966 | const ColumnVector& rRec) {
|
---|
967 |
|
---|
968 | double Mjd = _time.mjd() + _time.daysec() / 86400.0;
|
---|
969 |
|
---|
970 | // First time - initialize to zero
|
---|
971 | // -------------------------------
|
---|
972 | if (!_windUpTime.contains(prn)) {
|
---|
973 | _windUpTime[prn] = Mjd;
|
---|
974 | _windUpSum[prn] = 0.0;
|
---|
975 | }
|
---|
976 |
|
---|
977 | // Compute the correction for new time
|
---|
978 | // -----------------------------------
|
---|
979 | else if (_windUpTime[prn] != Mjd) {
|
---|
980 | _windUpTime[prn] = Mjd;
|
---|
981 |
|
---|
982 | // Unit Vector GPS Satellite --> Receiver
|
---|
983 | // --------------------------------------
|
---|
984 | ColumnVector rho = rRec - rSat;
|
---|
985 | rho /= rho.norm_Frobenius();
|
---|
986 |
|
---|
987 | // GPS Satellite unit Vectors sz, sy, sx
|
---|
988 | // -------------------------------------
|
---|
989 | ColumnVector sz = -rSat / rSat.norm_Frobenius();
|
---|
990 |
|
---|
991 | ColumnVector xSun = Sun(Mjd);
|
---|
992 | xSun /= xSun.norm_Frobenius();
|
---|
993 |
|
---|
994 | ColumnVector sy = crossproduct(sz, xSun);
|
---|
995 | ColumnVector sx = crossproduct(sy, sz);
|
---|
996 |
|
---|
997 | // Effective Dipole of the GPS Satellite Antenna
|
---|
998 | // ---------------------------------------------
|
---|
999 | ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
|
---|
1000 | - crossproduct(rho, sy);
|
---|
1001 |
|
---|
1002 | // Receiver unit Vectors rx, ry
|
---|
1003 | // ----------------------------
|
---|
1004 | ColumnVector rx(3);
|
---|
1005 | ColumnVector ry(3);
|
---|
1006 |
|
---|
1007 | double recEll[3]; xyz2ell(rRec.data(), recEll) ;
|
---|
1008 | double neu[3];
|
---|
1009 |
|
---|
1010 | neu[0] = 1.0;
|
---|
1011 | neu[1] = 0.0;
|
---|
1012 | neu[2] = 0.0;
|
---|
1013 | neu2xyz(recEll, neu, rx.data());
|
---|
1014 |
|
---|
1015 | neu[0] = 0.0;
|
---|
1016 | neu[1] = -1.0;
|
---|
1017 | neu[2] = 0.0;
|
---|
1018 | neu2xyz(recEll, neu, ry.data());
|
---|
1019 |
|
---|
1020 | // Effective Dipole of the Receiver Antenna
|
---|
1021 | // ----------------------------------------
|
---|
1022 | ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
|
---|
1023 | + crossproduct(rho, ry);
|
---|
1024 |
|
---|
1025 | // Resulting Effect
|
---|
1026 | // ----------------
|
---|
1027 | double alpha = DotProduct(dipSat,dipRec) /
|
---|
1028 | (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
|
---|
1029 |
|
---|
1030 | if (alpha > 1.0) alpha = 1.0;
|
---|
1031 | if (alpha < -1.0) alpha = -1.0;
|
---|
1032 |
|
---|
1033 | double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
|
---|
1034 |
|
---|
1035 | if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
|
---|
1036 | dphi = -dphi;
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | return _windUpSum[prn];
|
---|
1043 | }
|
---|