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