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