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.05;
|
---|
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.10;
|
---|
65 | const double sig_trp_p = 1e-8;
|
---|
66 | const double sig_amb_0_GPS = 1000.0;
|
---|
67 | const double sig_amb_0_GLO = 1000.0;
|
---|
68 | const double sig_L3_GPS = 0.02;
|
---|
69 | const double sig_L3_GLO = 0.05;
|
---|
70 |
|
---|
71 | // Constructor
|
---|
72 | ////////////////////////////////////////////////////////////////////////////
|
---|
73 | bncParam::bncParam(bncParam::parType typeIn, int indexIn,
|
---|
74 | const QString& prnIn) {
|
---|
75 | type = typeIn;
|
---|
76 | index = indexIn;
|
---|
77 | prn = prnIn;
|
---|
78 | index_old = 0;
|
---|
79 | xx = 0.0;
|
---|
80 |
|
---|
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 += "bncModel::cmpBancroft: not enough data\n";
|
---|
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 | bncSettings settings;
|
---|
533 | double sig_P3;
|
---|
534 | sig_P3 = 5.0;
|
---|
535 | if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked ) {
|
---|
536 | sig_P3 = settings.value("pppSigmaCode").toDouble();
|
---|
537 | if (sig_P3 < 0.3 || sig_P3 > 50.0) {
|
---|
538 | sig_P3 = 5.0;
|
---|
539 | }
|
---|
540 | }
|
---|
541 |
|
---|
542 | _log.clear();
|
---|
543 |
|
---|
544 | _time = epoData->tt;
|
---|
545 |
|
---|
546 | _log += "Single Point Positioning of Epoch "
|
---|
547 | + QByteArray(_time.timestr(1).c_str()) +
|
---|
548 | "\n--------------------------------------------------------------\n";
|
---|
549 |
|
---|
550 | SymmetricMatrix QQsav;
|
---|
551 | ColumnVector dx;
|
---|
552 | ColumnVector vv;
|
---|
553 |
|
---|
554 | // Loop over all outliers
|
---|
555 | // ----------------------
|
---|
556 | do {
|
---|
557 |
|
---|
558 | // Bancroft Solution
|
---|
559 | // -----------------
|
---|
560 | if (cmpBancroft(epoData) != success) {
|
---|
561 | emit newMessage(_log, false);
|
---|
562 | return failure;
|
---|
563 | }
|
---|
564 |
|
---|
565 | // Status Prediction
|
---|
566 | // -----------------
|
---|
567 | predict(epoData);
|
---|
568 |
|
---|
569 | // Create First-Design Matrix
|
---|
570 | // --------------------------
|
---|
571 | unsigned nPar = _params.size();
|
---|
572 | unsigned nObs = 0;
|
---|
573 | if (_usePhase) {
|
---|
574 | nObs = 2 * epoData->sizeGPS() + epoData->sizeGlo();
|
---|
575 | }
|
---|
576 | else {
|
---|
577 | nObs = epoData->sizeGPS(); // Glonass pseudoranges are not used
|
---|
578 | }
|
---|
579 |
|
---|
580 | if (nObs < nPar) {
|
---|
581 | _log += "bncModel::update: nObs < nPar\n";
|
---|
582 | emit newMessage(_log, false);
|
---|
583 | return failure;
|
---|
584 | }
|
---|
585 |
|
---|
586 | Matrix AA(nObs, nPar); // first design matrix
|
---|
587 | ColumnVector ll(nObs); // tems observed-computed
|
---|
588 | DiagonalMatrix PP(nObs); PP = 0.0;
|
---|
589 |
|
---|
590 | unsigned iObs = 0;
|
---|
591 |
|
---|
592 | // GPS code and (optionally) phase observations
|
---|
593 | // --------------------------------------------
|
---|
594 | QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
|
---|
595 | while (itGPS.hasNext()) {
|
---|
596 | ++iObs;
|
---|
597 | itGPS.next();
|
---|
598 | QString prn = itGPS.key();
|
---|
599 | t_satData* satData = itGPS.value();
|
---|
600 |
|
---|
601 | double rhoCmp = cmpValue(satData);
|
---|
602 |
|
---|
603 | ll(iObs) = satData->P3 - rhoCmp;
|
---|
604 | PP(iObs,iObs) = 1.0 / (sig_P3 * sig_P3);
|
---|
605 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
606 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
|
---|
607 | }
|
---|
608 |
|
---|
609 | if (_usePhase) {
|
---|
610 | ++iObs;
|
---|
611 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
612 | PP(iObs,iObs) = 1.0 / (sig_L3_GPS * sig_L3_GPS);
|
---|
613 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
614 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
615 | _params[iPar-1]->prn == prn) {
|
---|
616 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
617 | }
|
---|
618 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
619 | }
|
---|
620 | }
|
---|
621 | }
|
---|
622 |
|
---|
623 | // Glonass phase observations
|
---|
624 | // --------------------------
|
---|
625 | if (_usePhase) {
|
---|
626 | QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
|
---|
627 | while (itGlo.hasNext()) {
|
---|
628 | ++iObs;
|
---|
629 | itGlo.next();
|
---|
630 | QString prn = itGlo.key();
|
---|
631 | t_satData* satData = itGlo.value();
|
---|
632 |
|
---|
633 | double rhoCmp = cmpValue(satData);
|
---|
634 |
|
---|
635 | ll(iObs) = satData->L3 - rhoCmp;
|
---|
636 |
|
---|
637 | PP(iObs,iObs) = 1.0 / (sig_L3_GLO * sig_L3_GLO);
|
---|
638 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
639 | if (_params[iPar-1]->type == bncParam::AMB_L3 &&
|
---|
640 | _params[iPar-1]->prn == prn) {
|
---|
641 | ll(iObs) -= _params[iPar-1]->xx;
|
---|
642 | }
|
---|
643 | AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
|
---|
644 | }
|
---|
645 | }
|
---|
646 | }
|
---|
647 |
|
---|
648 | // Compute Filter Update
|
---|
649 | // ---------------------
|
---|
650 | QQsav = _QQ;
|
---|
651 |
|
---|
652 | kalman(AA, ll, PP, _QQ, dx);
|
---|
653 |
|
---|
654 | vv = ll - AA * dx;
|
---|
655 |
|
---|
656 | ostringstream strA;
|
---|
657 | strA.setf(ios::fixed);
|
---|
658 | ColumnVector vv_code(epoData->sizeGPS());
|
---|
659 | ColumnVector vv_phase(epoData->sizeGPS());
|
---|
660 | ColumnVector vv_glo(epoData->sizeGlo());
|
---|
661 |
|
---|
662 | for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
|
---|
663 | if (_usePhase) {
|
---|
664 | vv_code(iobs) = vv(2*iobs-1);
|
---|
665 | vv_phase(iobs) = vv(2*iobs);
|
---|
666 | }
|
---|
667 | else {
|
---|
668 | vv_code(iobs) = vv(iobs);
|
---|
669 | }
|
---|
670 | }
|
---|
671 | if (_useGlonass) {
|
---|
672 | for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
|
---|
673 | vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
|
---|
674 | }
|
---|
675 | }
|
---|
676 |
|
---|
677 | strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
|
---|
678 | if (_usePhase) {
|
---|
679 | strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
|
---|
680 | }
|
---|
681 | if (_useGlonass) {
|
---|
682 | strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
|
---|
683 | }
|
---|
684 | _log += strA.str().c_str();
|
---|
685 |
|
---|
686 | } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
|
---|
687 | epoData->satDataGlo) != 0);
|
---|
688 |
|
---|
689 | // Set Solution Vector
|
---|
690 | // -------------------
|
---|
691 | ostringstream strB;
|
---|
692 | strB.setf(ios::fixed);
|
---|
693 | QVectorIterator<bncParam*> itPar(_params);
|
---|
694 | while (itPar.hasNext()) {
|
---|
695 | bncParam* par = itPar.next();
|
---|
696 | par->xx += dx(par->index);
|
---|
697 |
|
---|
698 | if (par->type == bncParam::RECCLK) {
|
---|
699 | strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
|
---|
700 | << " +- " << setw(6) << setprecision(3)
|
---|
701 | << sqrt(_QQ(par->index,par->index));
|
---|
702 | }
|
---|
703 | else if (par->type == bncParam::AMB_L3) {
|
---|
704 | strB << "\n amb " << par->prn.toAscii().data() << " = "
|
---|
705 | << setw(6) << setprecision(3) << par->xx
|
---|
706 | << " +- " << setw(6) << setprecision(3)
|
---|
707 | << sqrt(_QQ(par->index,par->index));
|
---|
708 | }
|
---|
709 | else if (par->type == bncParam::TROPO) {
|
---|
710 | strB << "\n trp = " << par->prn.toAscii().data()
|
---|
711 | << setw(7) << setprecision(3) << delay_saast(M_PI/2.0) << " "
|
---|
712 | << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
|
---|
713 | << " +- " << setw(6) << setprecision(3)
|
---|
714 | << sqrt(_QQ(par->index,par->index));
|
---|
715 | }
|
---|
716 | }
|
---|
717 | strB << '\n';
|
---|
718 | _log += strB.str().c_str();
|
---|
719 | emit newMessage(_log, false);
|
---|
720 |
|
---|
721 | // Final Message (both log file and screen)
|
---|
722 | // ----------------------------------------
|
---|
723 | ostringstream strC;
|
---|
724 | strC.setf(ios::fixed);
|
---|
725 | strC << _staID.data() << " PPP "
|
---|
726 | << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
|
---|
727 | << setw(14) << setprecision(3) << x() << " +- "
|
---|
728 | << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
|
---|
729 | << setw(14) << setprecision(3) << y() << " +- "
|
---|
730 | << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
|
---|
731 | << setw(14) << setprecision(3) << z() << " +- "
|
---|
732 | << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
|
---|
733 |
|
---|
734 | // NEU Output
|
---|
735 | // ----------
|
---|
736 | if (settings.value("pppOrigin").toString() == "X Y Z") {
|
---|
737 | double xyzRef[3];
|
---|
738 | double ellRef[3];
|
---|
739 | double _xyz[3];
|
---|
740 | double _neu[3];
|
---|
741 | xyzRef[0] = settings.value("pppRefCrdX").toDouble();
|
---|
742 | xyzRef[1] = settings.value("pppRefCrdY").toDouble();
|
---|
743 | xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
|
---|
744 | _xyz[0] = x() - xyzRef[0];
|
---|
745 | _xyz[1] = y() - xyzRef[1];
|
---|
746 | _xyz[2] = z() - xyzRef[2];
|
---|
747 | xyz2ell(xyzRef, ellRef);
|
---|
748 | xyz2neu(ellRef, _xyz, _neu);
|
---|
749 | strC << " NEU "
|
---|
750 | << setw(8) << setprecision(3) << _neu[0] << " "
|
---|
751 | << setw(8) << setprecision(3) << _neu[1] << " "
|
---|
752 | << setw(8) << setprecision(3) << _neu[2];
|
---|
753 | }
|
---|
754 |
|
---|
755 | strC << endl;
|
---|
756 |
|
---|
757 | emit newMessage(QByteArray(strC.str().c_str()), true);
|
---|
758 |
|
---|
759 | // NMEA Output
|
---|
760 | // -----------
|
---|
761 | double xyz[3];
|
---|
762 | xyz[0] = x();
|
---|
763 | xyz[1] = y();
|
---|
764 | xyz[2] = z();
|
---|
765 | double ell[3];
|
---|
766 | xyz2ell(xyz, ell);
|
---|
767 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
768 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
769 |
|
---|
770 | char phiCh = 'N';
|
---|
771 | if (phiDeg < 0) {
|
---|
772 | phiDeg = -phiDeg;
|
---|
773 | phiCh = 'S';
|
---|
774 | }
|
---|
775 | char lamCh = 'E';
|
---|
776 | if (lamDeg < 0) {
|
---|
777 | // lamDeg = -lamDeg; // GW, reason: RTKPlot cant handle 'W'
|
---|
778 | // lamCh = 'W'; // GW, reason: RTKPlot cant handle 'W'
|
---|
779 | lamDeg = 360. +lamDeg; // GW, reason: RTKPlot cant handle 'W'
|
---|
780 | }
|
---|
781 |
|
---|
782 | double dop = 2.0; // TODO
|
---|
783 |
|
---|
784 | ostringstream str3;
|
---|
785 | str3.setf(ios::fixed);
|
---|
786 | str3 << "GPGGA,"
|
---|
787 | << epoData->tt.timestr(0,0) << ','
|
---|
788 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
789 | << setw(10) << setprecision(7) << setfill('0')
|
---|
790 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
791 | << setw(2) << setfill('0') << int(lamDeg)
|
---|
792 | << setw(10) << setprecision(7) << setfill('0')
|
---|
793 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
794 | << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
|
---|
795 | << setw(3) << setprecision(1) << dop << ','
|
---|
796 | << setprecision(3) << ell[2] << ",M,0.0,M,,,";
|
---|
797 |
|
---|
798 | writeNMEAstr(QString(str3.str().c_str()));
|
---|
799 |
|
---|
800 | return success;
|
---|
801 | }
|
---|
802 |
|
---|
803 | // Outlier Detection
|
---|
804 | ////////////////////////////////////////////////////////////////////////////
|
---|
805 | int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
|
---|
806 | const ColumnVector& vv,
|
---|
807 | QMap<QString, t_satData*>& satDataGPS,
|
---|
808 | QMap<QString, t_satData*>& satDataGlo) {
|
---|
809 |
|
---|
810 | double vvMaxCodeGPS = 0.0;
|
---|
811 | double vvMaxPhaseGPS = 0.0;
|
---|
812 | double vvMaxPhaseGlo = 0.0;
|
---|
813 | QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
|
---|
814 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
|
---|
815 | QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
|
---|
816 |
|
---|
817 | int ii = 0;
|
---|
818 |
|
---|
819 | // GPS code and (optionally) phase residuals
|
---|
820 | // -----------------------------------------
|
---|
821 | QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
|
---|
822 | while (itGPS.hasNext()) {
|
---|
823 | itGPS.next();
|
---|
824 | ++ii;
|
---|
825 |
|
---|
826 | if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
|
---|
827 | vvMaxCodeGPS = fabs(vv(ii));
|
---|
828 | itMaxCodeGPS = itGPS;
|
---|
829 | }
|
---|
830 |
|
---|
831 | if (_usePhase) {
|
---|
832 | ++ii;
|
---|
833 | if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
|
---|
834 | vvMaxPhaseGPS = fabs(vv(ii));
|
---|
835 | itMaxPhaseGPS = itGPS;
|
---|
836 | }
|
---|
837 | }
|
---|
838 | }
|
---|
839 |
|
---|
840 | // Glonass phase residuals
|
---|
841 | // -----------------------
|
---|
842 | if (_usePhase) {
|
---|
843 | QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
|
---|
844 | while (itGlo.hasNext()) {
|
---|
845 | itGlo.next();
|
---|
846 | ++ii;
|
---|
847 | if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
|
---|
848 | vvMaxPhaseGlo = fabs(vv(ii));
|
---|
849 | itMaxPhaseGlo = itGlo;
|
---|
850 | }
|
---|
851 | }
|
---|
852 | }
|
---|
853 |
|
---|
854 | if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
|
---|
855 | QString prn = itMaxPhaseGlo.key();
|
---|
856 | t_satData* satData = itMaxPhaseGlo.value();
|
---|
857 | delete satData;
|
---|
858 | itMaxPhaseGlo.remove();
|
---|
859 | _QQ = QQsav;
|
---|
860 |
|
---|
861 | _log += "Outlier Phase " + prn.toAscii() + " "
|
---|
862 | + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
|
---|
863 |
|
---|
864 | return 1;
|
---|
865 | }
|
---|
866 |
|
---|
867 | else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
|
---|
868 | QString prn = itMaxCodeGPS.key();
|
---|
869 | t_satData* satData = itMaxCodeGPS.value();
|
---|
870 | delete satData;
|
---|
871 | itMaxCodeGPS.remove();
|
---|
872 | _QQ = QQsav;
|
---|
873 |
|
---|
874 | _log += "Outlier Code " + prn.toAscii() + " "
|
---|
875 | + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
|
---|
876 |
|
---|
877 | return 1;
|
---|
878 | }
|
---|
879 | else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
|
---|
880 | QString prn = itMaxPhaseGPS.key();
|
---|
881 | t_satData* satData = itMaxPhaseGPS.value();
|
---|
882 | delete satData;
|
---|
883 | itMaxPhaseGPS.remove();
|
---|
884 | _QQ = QQsav;
|
---|
885 |
|
---|
886 | _log += "Outlier Phase " + prn.toAscii() + " "
|
---|
887 | + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
|
---|
888 |
|
---|
889 | return 1;
|
---|
890 | }
|
---|
891 |
|
---|
892 | return 0;
|
---|
893 | }
|
---|
894 |
|
---|
895 | //
|
---|
896 | ////////////////////////////////////////////////////////////////////////////
|
---|
897 | void bncModel::writeNMEAstr(const QString& nmStr) {
|
---|
898 |
|
---|
899 | unsigned char XOR = 0;
|
---|
900 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
901 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
902 | }
|
---|
903 |
|
---|
904 | QString outStr = '$' + nmStr
|
---|
905 | + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
---|
906 |
|
---|
907 | if (_nmeaStream) {
|
---|
908 | *_nmeaStream << outStr;
|
---|
909 | _nmeaStream->flush();
|
---|
910 | }
|
---|
911 |
|
---|
912 | emit newNMEAstr(outStr.toAscii());
|
---|
913 | }
|
---|
914 |
|
---|
915 |
|
---|
916 | ////
|
---|
917 | //////////////////////////////////////////////////////////////////////////////
|
---|
918 | void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
|
---|
919 | const DiagonalMatrix& PP,
|
---|
920 | SymmetricMatrix& QQ, ColumnVector& dx) {
|
---|
921 |
|
---|
922 | int nObs = AA.Nrows();
|
---|
923 | int nPar = AA.Ncols();
|
---|
924 |
|
---|
925 | UpperTriangularMatrix SS = Cholesky(QQ).t();
|
---|
926 |
|
---|
927 | Matrix SA = SS*AA.t();
|
---|
928 | Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
|
---|
929 | for (int ii = 1; ii <= nObs; ++ii) {
|
---|
930 | SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
|
---|
931 | }
|
---|
932 |
|
---|
933 | SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
|
---|
934 | SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
|
---|
935 |
|
---|
936 | UpperTriangularMatrix UU;
|
---|
937 | QRZ(SRF, UU);
|
---|
938 |
|
---|
939 | SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
|
---|
940 | UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
|
---|
941 | Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
|
---|
942 |
|
---|
943 | UpperTriangularMatrix SHi = SH_rt.i();
|
---|
944 |
|
---|
945 | Matrix KT = SHi * YY;
|
---|
946 | SymmetricMatrix Hi; Hi << SHi * SHi.t();
|
---|
947 |
|
---|
948 | dx = KT.t() * ll;
|
---|
949 | QQ << (SS.t() * SS);
|
---|
950 | }
|
---|