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