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