1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Client
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: bncComb
|
---|
6 | *
|
---|
7 | * Purpose: Combinations of Orbit/Clock Corrections
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 22-Jan-2011
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <newmatio.h>
|
---|
18 | #include <iomanip>
|
---|
19 | #include <sstream>
|
---|
20 |
|
---|
21 | #include "bnccomb.h"
|
---|
22 | #include "bncapp.h"
|
---|
23 | #include "upload/bncrtnetdecoder.h"
|
---|
24 | #include "bncsettings.h"
|
---|
25 | #include "bncmodel.h"
|
---|
26 | #include "bncutils.h"
|
---|
27 | #include "bncpppclient.h"
|
---|
28 | #include "bncsp3.h"
|
---|
29 | #include "bncantex.h"
|
---|
30 | #include "bnctides.h"
|
---|
31 |
|
---|
32 | const int moduloTime = 10;
|
---|
33 |
|
---|
34 | const double sig0_offAC = 1000.0;
|
---|
35 | const double sig0_offACSat = 100.0;
|
---|
36 | const double sigP_offACSat = 0.1;
|
---|
37 | const double sig0_clkSat = 100.0;
|
---|
38 |
|
---|
39 | const double sigObs = 0.05;
|
---|
40 |
|
---|
41 | const int MAXPRN_GPS = 32;
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 | // Constructor
|
---|
46 | ////////////////////////////////////////////////////////////////////////////
|
---|
47 | cmbParam::cmbParam(parType type_, int index_,
|
---|
48 | const QString& ac_, const QString& prn_) {
|
---|
49 |
|
---|
50 | type = type_;
|
---|
51 | index = index_;
|
---|
52 | AC = ac_;
|
---|
53 | prn = prn_;
|
---|
54 | xx = 0.0;
|
---|
55 | eph = 0;
|
---|
56 |
|
---|
57 | if (type == offAC) {
|
---|
58 | epoSpec = true;
|
---|
59 | sig0 = sig0_offAC;
|
---|
60 | sigP = sig0;
|
---|
61 | }
|
---|
62 | else if (type == offACSat) {
|
---|
63 | epoSpec = false;
|
---|
64 | sig0 = sig0_offACSat;
|
---|
65 | sigP = sigP_offACSat;
|
---|
66 | }
|
---|
67 | else if (type == clkSat) {
|
---|
68 | epoSpec = true;
|
---|
69 | sig0 = sig0_clkSat;
|
---|
70 | sigP = sig0;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | // Destructor
|
---|
75 | ////////////////////////////////////////////////////////////////////////////
|
---|
76 | cmbParam::~cmbParam() {
|
---|
77 | }
|
---|
78 |
|
---|
79 | // Partial
|
---|
80 | ////////////////////////////////////////////////////////////////////////////
|
---|
81 | double cmbParam::partial(const QString& AC_, const QString& prn_) {
|
---|
82 |
|
---|
83 | if (type == offAC) {
|
---|
84 | if (AC == AC_) {
|
---|
85 | return 1.0;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | else if (type == offACSat) {
|
---|
89 | if (AC == AC_ && prn == prn_) {
|
---|
90 | return 1.0;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | else if (type == clkSat) {
|
---|
94 | if (prn == prn_) {
|
---|
95 | return 1.0;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | return 0.0;
|
---|
100 | }
|
---|
101 |
|
---|
102 | //
|
---|
103 | ////////////////////////////////////////////////////////////////////////////
|
---|
104 | QString cmbParam::toString() const {
|
---|
105 |
|
---|
106 | QString outStr;
|
---|
107 |
|
---|
108 | if (type == offAC) {
|
---|
109 | outStr = "AC offset " + AC;
|
---|
110 | }
|
---|
111 | else if (type == offACSat) {
|
---|
112 | outStr = "Sat Offset " + AC + " " + prn;
|
---|
113 | }
|
---|
114 | else if (type == clkSat) {
|
---|
115 | outStr = "Clk Corr " + prn;
|
---|
116 | }
|
---|
117 |
|
---|
118 | return outStr;
|
---|
119 | }
|
---|
120 |
|
---|
121 | // Constructor
|
---|
122 | ////////////////////////////////////////////////////////////////////////////
|
---|
123 | bncComb::bncComb() {
|
---|
124 |
|
---|
125 | bncSettings settings;
|
---|
126 |
|
---|
127 | QStringList combineStreams = settings.value("combineStreams").toStringList();
|
---|
128 |
|
---|
129 | _masterMissingEpochs = 0;
|
---|
130 |
|
---|
131 | if (combineStreams.size() >= 1 && !combineStreams[0].isEmpty()) {
|
---|
132 | QListIterator<QString> it(combineStreams);
|
---|
133 | while (it.hasNext()) {
|
---|
134 | QStringList hlp = it.next().split(" ");
|
---|
135 | cmbAC* newAC = new cmbAC();
|
---|
136 | newAC->mountPoint = hlp[0];
|
---|
137 | newAC->name = hlp[1];
|
---|
138 | newAC->weight = hlp[2].toDouble();
|
---|
139 | if (_masterOrbitAC.isEmpty()) {
|
---|
140 | _masterOrbitAC = newAC->name;
|
---|
141 | }
|
---|
142 | _ACs.append(newAC);
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | _rtnetDecoder = 0;
|
---|
147 |
|
---|
148 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
149 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
150 |
|
---|
151 |
|
---|
152 | // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
|
---|
153 | // ----------------------------------------------------------------------
|
---|
154 | int nextPar = 0;
|
---|
155 | QListIterator<cmbAC*> it(_ACs);
|
---|
156 | while (it.hasNext()) {
|
---|
157 | cmbAC* AC = it.next();
|
---|
158 | _params.push_back(new cmbParam(cmbParam::offAC, ++nextPar, AC->name, ""));
|
---|
159 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
160 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
161 | _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
|
---|
162 | AC->name, prn));
|
---|
163 | }
|
---|
164 | }
|
---|
165 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
166 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
167 | _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Initialize Variance-Covariance Matrix
|
---|
171 | // -------------------------------------
|
---|
172 | _QQ.ReSize(_params.size());
|
---|
173 | _QQ = 0.0;
|
---|
174 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
175 | cmbParam* pp = _params[iPar-1];
|
---|
176 | _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // ANTEX File
|
---|
180 | // ----------
|
---|
181 | _antex = 0;
|
---|
182 | QString antexFileName = settings.value("pppAntex").toString();
|
---|
183 | if (!antexFileName.isEmpty()) {
|
---|
184 | _antex = new bncAntex();
|
---|
185 | if (_antex->readFile(antexFileName) != success) {
|
---|
186 | emit newMessage("wrong ANTEX file", true);
|
---|
187 | delete _antex;
|
---|
188 | _antex = 0;
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | // Maximal Residuum
|
---|
193 | // ----------------
|
---|
194 | _MAXRES = settings.value("cmbMaxres").toDouble();
|
---|
195 | if (_MAXRES <= 0.0) {
|
---|
196 | _MAXRES = 999.0;
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | // Destructor
|
---|
201 | ////////////////////////////////////////////////////////////////////////////
|
---|
202 | bncComb::~bncComb() {
|
---|
203 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
204 | while (icAC.hasNext()) {
|
---|
205 | delete icAC.next();
|
---|
206 | }
|
---|
207 | delete _rtnetDecoder;
|
---|
208 | delete _antex;
|
---|
209 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
210 | delete _params[iPar-1];
|
---|
211 | }
|
---|
212 | QVectorIterator<cmbCorr*> itCorr(corrs());
|
---|
213 | while (itCorr.hasNext()) {
|
---|
214 | delete itCorr.next();
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | // Read and store one correction line
|
---|
219 | ////////////////////////////////////////////////////////////////////////////
|
---|
220 | void bncComb::processCorrLine(const QString& staID, const QString& line) {
|
---|
221 | QMutexLocker locker(&_mutex);
|
---|
222 |
|
---|
223 | // Find the AC Name
|
---|
224 | // ----------------
|
---|
225 | QString acName;
|
---|
226 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
227 | while (icAC.hasNext()) {
|
---|
228 | cmbAC* AC = icAC.next();
|
---|
229 | if (AC->mountPoint == staID) {
|
---|
230 | acName = AC->name;
|
---|
231 | break;
|
---|
232 | }
|
---|
233 | }
|
---|
234 | if (acName.isEmpty()) {
|
---|
235 | return;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // Read the Correction
|
---|
239 | // -------------------
|
---|
240 | cmbCorr* newCorr = new cmbCorr();
|
---|
241 | newCorr->acName = acName;
|
---|
242 | if (!newCorr->readLine(line) == success) {
|
---|
243 | delete newCorr;
|
---|
244 | return;
|
---|
245 | }
|
---|
246 |
|
---|
247 | // Check Modulo Time
|
---|
248 | // -----------------
|
---|
249 | if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
|
---|
250 | delete newCorr;
|
---|
251 | return;
|
---|
252 | }
|
---|
253 |
|
---|
254 | // Delete old corrections
|
---|
255 | // ----------------------
|
---|
256 | if (_resTime.valid() && newCorr->tt <= _resTime) {
|
---|
257 | delete newCorr;
|
---|
258 | return;
|
---|
259 | }
|
---|
260 |
|
---|
261 | // Check the Ephemeris
|
---|
262 | //--------------------
|
---|
263 | if (_eph.find(newCorr->prn) == _eph.end()) {
|
---|
264 | delete newCorr;
|
---|
265 | return;
|
---|
266 | }
|
---|
267 | else {
|
---|
268 | t_eph* lastEph = _eph[newCorr->prn]->last;
|
---|
269 | t_eph* prevEph = _eph[newCorr->prn]->prev;
|
---|
270 | if (lastEph && lastEph->IOD() == newCorr->iod) {
|
---|
271 | newCorr->eph = lastEph;
|
---|
272 | }
|
---|
273 | else if (prevEph && prevEph->IOD() == newCorr->iod) {
|
---|
274 | newCorr->eph = prevEph;
|
---|
275 | switchToLastEph(lastEph, newCorr);
|
---|
276 | }
|
---|
277 | else {
|
---|
278 | delete newCorr;
|
---|
279 | return;
|
---|
280 | }
|
---|
281 | }
|
---|
282 |
|
---|
283 | // Process previous Epoch(s)
|
---|
284 | // -------------------------
|
---|
285 | QListIterator<bncTime> itTime(_buffer.keys());
|
---|
286 | while (itTime.hasNext()) {
|
---|
287 | bncTime epoTime = itTime.next();
|
---|
288 | if (epoTime < newCorr->tt - moduloTime) {
|
---|
289 | _resTime = epoTime;
|
---|
290 | processEpoch();
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | // Merge or add the correction
|
---|
295 | // ---------------------------
|
---|
296 | QVector<cmbCorr*>& corrs = _buffer[newCorr->tt].corrs;
|
---|
297 | cmbCorr* existingCorr = 0;
|
---|
298 | QVectorIterator<cmbCorr*> itCorr(corrs);
|
---|
299 | while (itCorr.hasNext()) {
|
---|
300 | cmbCorr* hlp = itCorr.next();
|
---|
301 | if (hlp->prn == newCorr->prn && hlp->acName == newCorr->prn) {
|
---|
302 | existingCorr = hlp;
|
---|
303 | break;
|
---|
304 | }
|
---|
305 | }
|
---|
306 | if (existingCorr) {
|
---|
307 | delete newCorr;
|
---|
308 | existingCorr->readLine(line); // merge (multiple messages)
|
---|
309 | }
|
---|
310 | else {
|
---|
311 | corrs.append(newCorr);
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | // Change the correction so that it refers to last received ephemeris
|
---|
316 | ////////////////////////////////////////////////////////////////////////////
|
---|
317 | void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
|
---|
318 |
|
---|
319 | if (corr->eph == lastEph) {
|
---|
320 | return;
|
---|
321 | }
|
---|
322 |
|
---|
323 | ColumnVector oldXC(4);
|
---|
324 | ColumnVector oldVV(3);
|
---|
325 | corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
326 | oldXC.data(), oldVV.data());
|
---|
327 |
|
---|
328 | ColumnVector newXC(4);
|
---|
329 | ColumnVector newVV(3);
|
---|
330 | lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
331 | newXC.data(), newVV.data());
|
---|
332 |
|
---|
333 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
---|
334 | ColumnVector dV = newVV - oldVV;
|
---|
335 | double dC = newXC(4) - oldXC(4);
|
---|
336 |
|
---|
337 | ColumnVector dRAO(3);
|
---|
338 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
---|
339 |
|
---|
340 | ColumnVector dDotRAO(3);
|
---|
341 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
---|
342 |
|
---|
343 | QString msg = "switch corr " + corr->prn
|
---|
344 | + QString(" %1 -> %2 %3").arg(corr->iod,3)
|
---|
345 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
346 |
|
---|
347 | emit newMessage(msg.toAscii(), false);
|
---|
348 |
|
---|
349 | corr->iod = lastEph->IOD();
|
---|
350 | corr->eph = lastEph;
|
---|
351 | corr->rao += dRAO;
|
---|
352 | corr->dotRao += dDotRAO;
|
---|
353 | corr->dClk -= dC;
|
---|
354 | }
|
---|
355 |
|
---|
356 | // Process Epoch
|
---|
357 | ////////////////////////////////////////////////////////////////////////////
|
---|
358 | void bncComb::processEpoch() {
|
---|
359 |
|
---|
360 | int nPar = _params.size();
|
---|
361 |
|
---|
362 | _log.clear();
|
---|
363 |
|
---|
364 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
365 |
|
---|
366 | out << endl << "Combination:" << endl
|
---|
367 | << "------------------------------" << endl;
|
---|
368 |
|
---|
369 | // Observation Statistics
|
---|
370 | // ----------------------
|
---|
371 | bool masterPresent = false;
|
---|
372 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
373 | while (icAC.hasNext()) {
|
---|
374 | cmbAC* AC = icAC.next();
|
---|
375 | AC->numObs = 0;
|
---|
376 | QVectorIterator<cmbCorr*> itCorr(corrs());
|
---|
377 | while (itCorr.hasNext()) {
|
---|
378 | cmbCorr* corr = itCorr.next();
|
---|
379 | if (corr->acName == AC->name) {
|
---|
380 | AC->numObs += 1;
|
---|
381 | if (AC->name == _masterOrbitAC) {
|
---|
382 | masterPresent = true;
|
---|
383 | }
|
---|
384 | }
|
---|
385 | }
|
---|
386 | out << AC->name.toAscii().data() << ": " << AC->numObs << endl;
|
---|
387 | }
|
---|
388 |
|
---|
389 | // If Master not present, switch to another one
|
---|
390 | // --------------------------------------------
|
---|
391 | if (masterPresent) {
|
---|
392 | _masterMissingEpochs = 0;
|
---|
393 | }
|
---|
394 | else {
|
---|
395 | ++_masterMissingEpochs;
|
---|
396 | if (_masterMissingEpochs < 10) {
|
---|
397 | out << "Missing Master, Epoch skipped" << endl;
|
---|
398 | _buffer.remove(_resTime);
|
---|
399 | emit newMessage(_log, false);
|
---|
400 | return;
|
---|
401 | }
|
---|
402 | else {
|
---|
403 | _masterMissingEpochs = 0;
|
---|
404 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
405 | while (icAC.hasNext()) {
|
---|
406 | cmbAC* AC = icAC.next();
|
---|
407 | if (AC->numObs > 0) {
|
---|
408 | out << "Switching Master AC "
|
---|
409 | << _masterOrbitAC.toAscii().data() << " --> "
|
---|
410 | << AC->name.toAscii().data() << " "
|
---|
411 | << _resTime.datestr().c_str() << " "
|
---|
412 | << _resTime.timestr().c_str() << endl;
|
---|
413 | _masterOrbitAC = AC->name;
|
---|
414 | break;
|
---|
415 | }
|
---|
416 | }
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 | // Prediction Step
|
---|
421 | // ---------------
|
---|
422 | ColumnVector x0(nPar);
|
---|
423 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
424 | cmbParam* pp = _params[iPar-1];
|
---|
425 | //// QString prn = pp->prn;
|
---|
426 | //// if (!prn.isEmpty() && _eph.find(prn) != _eph.end()) {
|
---|
427 | //// switchToLastEph(_eph[prn]->last, pp);
|
---|
428 | //// }
|
---|
429 | if (pp->epoSpec) {
|
---|
430 | pp->xx = 0.0;
|
---|
431 | _QQ.Row(iPar) = 0.0;
|
---|
432 | _QQ.Column(iPar) = 0.0;
|
---|
433 | _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
434 | }
|
---|
435 | else {
|
---|
436 | _QQ(iPar,iPar) += pp->sigP * pp->sigP;
|
---|
437 | }
|
---|
438 | x0(iPar) = pp->xx;
|
---|
439 | }
|
---|
440 |
|
---|
441 | SymmetricMatrix QQ_sav = _QQ;
|
---|
442 |
|
---|
443 | ColumnVector dx;
|
---|
444 | QMap<QString, t_corr*> resCorr;
|
---|
445 |
|
---|
446 | // Update and outlier detection loop
|
---|
447 | // ---------------------------------
|
---|
448 | while (true) {
|
---|
449 |
|
---|
450 | Matrix AA;
|
---|
451 | ColumnVector ll;
|
---|
452 | DiagonalMatrix PP;
|
---|
453 |
|
---|
454 | if (createAmat(AA, ll, PP, x0, resCorr) != success) {
|
---|
455 | _buffer.remove(_resTime);
|
---|
456 | emit newMessage(_log, false);
|
---|
457 | return;
|
---|
458 | }
|
---|
459 |
|
---|
460 | bncModel::kalman(AA, ll, PP, _QQ, dx);
|
---|
461 | ColumnVector vv = ll - AA * dx;
|
---|
462 |
|
---|
463 | int maxResIndex;
|
---|
464 | double maxRes = vv.maximum_absolute_value1(maxResIndex);
|
---|
465 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
466 | out.setRealNumberPrecision(3);
|
---|
467 | out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
|
---|
468 | << " Maximum Residuum " << maxRes << ' '
|
---|
469 | << corrs()[maxResIndex-1]->acName << ' ' << corrs()[maxResIndex-1]->prn;
|
---|
470 |
|
---|
471 | if (maxRes > _MAXRES) {
|
---|
472 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
473 | cmbParam* pp = _params[iPar-1];
|
---|
474 | if (pp->type == cmbParam::offACSat &&
|
---|
475 | pp->AC == corrs()[maxResIndex-1]->acName &&
|
---|
476 | pp->prn == corrs()[maxResIndex-1]->prn) {
|
---|
477 | QQ_sav.Row(iPar) = 0.0;
|
---|
478 | QQ_sav.Column(iPar) = 0.0;
|
---|
479 | QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | out << " Outlier" << endl;
|
---|
484 | _QQ = QQ_sav;
|
---|
485 | corrs().remove(maxResIndex-1);
|
---|
486 | }
|
---|
487 | else {
|
---|
488 | out << " OK" << endl;
|
---|
489 | break;
|
---|
490 | }
|
---|
491 | }
|
---|
492 |
|
---|
493 | // Update Parameter Values
|
---|
494 | // -----------------------
|
---|
495 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
496 | cmbParam* pp = _params[iPar-1];
|
---|
497 | pp->xx += dx(iPar);
|
---|
498 | if (pp->type == cmbParam::clkSat) {
|
---|
499 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
---|
500 | resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
|
---|
501 | }
|
---|
502 | }
|
---|
503 | out << _resTime.datestr().c_str() << " "
|
---|
504 | << _resTime.timestr().c_str() << " ";
|
---|
505 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
506 | out.setFieldWidth(8);
|
---|
507 | out.setRealNumberPrecision(4);
|
---|
508 | out << pp->toString() << " "
|
---|
509 | << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
|
---|
510 | out.setFieldWidth(0);
|
---|
511 | }
|
---|
512 |
|
---|
513 | // Print Results
|
---|
514 | // -------------
|
---|
515 | printResults(out, resCorr);
|
---|
516 | dumpResults(resCorr);
|
---|
517 |
|
---|
518 | emit newMessage(_log, false);
|
---|
519 |
|
---|
520 | // Delete Data
|
---|
521 | // -----------
|
---|
522 | _buffer.remove(_resTime);
|
---|
523 | }
|
---|
524 |
|
---|
525 | // Print results
|
---|
526 | ////////////////////////////////////////////////////////////////////////////
|
---|
527 | void bncComb::printResults(QTextStream& out,
|
---|
528 | const QMap<QString, t_corr*>& resCorr) {
|
---|
529 |
|
---|
530 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
531 | while (it.hasNext()) {
|
---|
532 | it.next();
|
---|
533 | t_corr* corr = it.value();
|
---|
534 | const t_eph* eph = corr->eph;
|
---|
535 | if (eph) {
|
---|
536 | double xx, yy, zz, cc;
|
---|
537 | eph->position(_resTime.gpsw(), _resTime.gpssec(), xx, yy, zz, cc);
|
---|
538 |
|
---|
539 | out << _resTime.datestr().c_str() << " "
|
---|
540 | << _resTime.timestr().c_str() << " ";
|
---|
541 | out.setFieldWidth(3);
|
---|
542 | out << "Full Clock " << corr->prn << " " << corr->iod << " ";
|
---|
543 | out.setFieldWidth(14);
|
---|
544 | out << (cc + corr->dClk) * t_CST::c << endl;
|
---|
545 | out.setFieldWidth(0);
|
---|
546 | }
|
---|
547 | else {
|
---|
548 | out << "bncComb::printResuls bug" << endl;
|
---|
549 | }
|
---|
550 | }
|
---|
551 | }
|
---|
552 |
|
---|
553 | // Send results to RTNet Decoder and directly to PPP Client
|
---|
554 | ////////////////////////////////////////////////////////////////////////////
|
---|
555 | void bncComb::dumpResults(const QMap<QString, t_corr*>& resCorr) {
|
---|
556 |
|
---|
557 | ostringstream out; out.setf(std::ios::fixed);
|
---|
558 | QStringList corrLines;
|
---|
559 |
|
---|
560 | unsigned year, month, day, hour, minute;
|
---|
561 | double sec;
|
---|
562 | _resTime.civil_date(year, month, day);
|
---|
563 | _resTime.civil_time(hour, minute, sec);
|
---|
564 |
|
---|
565 | out << "* "
|
---|
566 | << setw(4) << year << " "
|
---|
567 | << setw(2) << month << " "
|
---|
568 | << setw(2) << day << " "
|
---|
569 | << setw(2) << hour << " "
|
---|
570 | << setw(2) << minute << " "
|
---|
571 | << setw(12) << setprecision(8) << sec << " "
|
---|
572 | << endl;
|
---|
573 |
|
---|
574 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
575 | while (it.hasNext()) {
|
---|
576 | it.next();
|
---|
577 | t_corr* corr = it.value();
|
---|
578 |
|
---|
579 | double dT = 60.0;
|
---|
580 |
|
---|
581 | for (int iTime = 1; iTime <= 2; iTime++) {
|
---|
582 |
|
---|
583 | bncTime time12 = (iTime == 1) ? _resTime : _resTime + dT;
|
---|
584 |
|
---|
585 | ColumnVector xc(4);
|
---|
586 | ColumnVector vv(3);
|
---|
587 | corr->eph->position(time12.gpsw(), time12.gpssec(),
|
---|
588 | xc.data(), vv.data());
|
---|
589 | bncPPPclient::applyCorr(time12, corr, xc, vv);
|
---|
590 |
|
---|
591 | // Relativistic Correction
|
---|
592 | // -----------------------
|
---|
593 | double relCorr = - 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
|
---|
594 | xc(4) -= relCorr;
|
---|
595 |
|
---|
596 | // Code Biases
|
---|
597 | // -----------
|
---|
598 | double dcbP1C1 = 0.0;
|
---|
599 | double dcbP1P2 = 0.0;
|
---|
600 |
|
---|
601 | // Correction Phase Center --> CoM
|
---|
602 | // -------------------------------
|
---|
603 | ColumnVector dx(3); dx = 0.0;
|
---|
604 | if (_antex) {
|
---|
605 | double Mjd = time12.mjd() + time12.daysec()/86400.0;
|
---|
606 | if (_antex->satCoMcorrection(corr->prn, Mjd, xc.Rows(1,3), dx) == success) {
|
---|
607 | xc(1) -= dx(1);
|
---|
608 | xc(2) -= dx(2);
|
---|
609 | xc(3) -= dx(3);
|
---|
610 | }
|
---|
611 | else {
|
---|
612 | cout << "antenna not found" << endl;
|
---|
613 | }
|
---|
614 | }
|
---|
615 |
|
---|
616 | if (iTime == 1) {
|
---|
617 | out << 'P' << corr->prn.toAscii().data()
|
---|
618 | << setw(14) << setprecision(6) << xc(1) / 1000.0
|
---|
619 | << setw(14) << setprecision(6) << xc(2) / 1000.0
|
---|
620 | << setw(14) << setprecision(6) << xc(3) / 1000.0
|
---|
621 | << setw(14) << setprecision(6) << xc(4) * 1e6
|
---|
622 | << setw(14) << setprecision(6) << relCorr * 1e6
|
---|
623 | << setw(8) << setprecision(3) << dx(1)
|
---|
624 | << setw(8) << setprecision(3) << dx(2)
|
---|
625 | << setw(8) << setprecision(3) << dx(3)
|
---|
626 | << setw(8) << setprecision(3) << dcbP1C1
|
---|
627 | << setw(8) << setprecision(3) << dcbP1P2
|
---|
628 | << setw(6) << setprecision(1) << dT;
|
---|
629 |
|
---|
630 | QString line;
|
---|
631 | int messageType = COTYPE_GPSCOMBINED;
|
---|
632 | int updateInt = 0;
|
---|
633 | line.sprintf("%d %d %d %.1f %s"
|
---|
634 | " %3d"
|
---|
635 | " %8.3f %8.3f %8.3f %8.3f"
|
---|
636 | " %10.5f %10.5f %10.5f %10.5f"
|
---|
637 | " %10.5f %10.5f %10.5f %10.5f INTERNAL",
|
---|
638 | messageType, updateInt, time12.gpsw(), time12.gpssec(),
|
---|
639 | corr->prn.toAscii().data(),
|
---|
640 | corr->iod,
|
---|
641 | corr->dClk * t_CST::c,
|
---|
642 | corr->rao[0],
|
---|
643 | corr->rao[1],
|
---|
644 | corr->rao[2],
|
---|
645 | corr->dotDClk * t_CST::c,
|
---|
646 | corr->dotRao[0],
|
---|
647 | corr->dotRao[1],
|
---|
648 | corr->dotRao[2],
|
---|
649 | corr->dotDotDClk * t_CST::c,
|
---|
650 | corr->dotDotRao[0],
|
---|
651 | corr->dotDotRao[1],
|
---|
652 | corr->dotDotRao[2]);
|
---|
653 | corrLines << line;
|
---|
654 | }
|
---|
655 | else {
|
---|
656 | out << setw(14) << setprecision(6) << xc(1) / 1000.0
|
---|
657 | << setw(14) << setprecision(6) << xc(2) / 1000.0
|
---|
658 | << setw(14) << setprecision(6) << xc(3) / 1000.0 << endl;
|
---|
659 | }
|
---|
660 | }
|
---|
661 |
|
---|
662 | delete corr;
|
---|
663 | }
|
---|
664 | out << "EOE" << endl; // End Of Epoch flag
|
---|
665 |
|
---|
666 | if (!_rtnetDecoder) {
|
---|
667 | _rtnetDecoder = new bncRtnetDecoder();
|
---|
668 | }
|
---|
669 |
|
---|
670 | vector<string> errmsg;
|
---|
671 | _rtnetDecoder->Decode((char*) out.str().data(), out.str().size(), errmsg);
|
---|
672 |
|
---|
673 | // Optionally send new Corrections to PPP
|
---|
674 | // --------------------------------------
|
---|
675 | bncApp* app = (bncApp*) qApp;
|
---|
676 | if (app->_bncPPPclient) {
|
---|
677 | app->_bncPPPclient->slotNewCorrections(corrLines);
|
---|
678 | }
|
---|
679 | }
|
---|
680 |
|
---|
681 | // Create First Design Matrix and Vector of Measurements
|
---|
682 | ////////////////////////////////////////////////////////////////////////////
|
---|
683 | t_irc bncComb::createAmat(Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
|
---|
684 | const ColumnVector& x0,
|
---|
685 | QMap<QString, t_corr*>& resCorr) {
|
---|
686 |
|
---|
687 | unsigned nPar = _params.size();
|
---|
688 | unsigned nObs = corrs().size();
|
---|
689 |
|
---|
690 | if (nObs == 0) {
|
---|
691 | return failure;
|
---|
692 | }
|
---|
693 |
|
---|
694 | const int nCon = 1 + MAXPRN_GPS;
|
---|
695 |
|
---|
696 | AA.ReSize(nObs+nCon, nPar); AA = 0.0;
|
---|
697 | ll.ReSize(nObs+nCon); ll = 0.0;
|
---|
698 | PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
|
---|
699 |
|
---|
700 | int iObs = 0;
|
---|
701 |
|
---|
702 | QVectorIterator<cmbCorr*> itCorr(corrs());
|
---|
703 | while (itCorr.hasNext()) {
|
---|
704 | cmbCorr* corr = itCorr.next();
|
---|
705 | QString prn = corr->prn;
|
---|
706 | switchToLastEph(_eph[prn]->last, corr);
|
---|
707 | ++iObs;
|
---|
708 |
|
---|
709 | if (corr->acName == _masterOrbitAC && resCorr.find(prn) == resCorr.end()) {
|
---|
710 | resCorr[prn] = new t_corr(*corr);
|
---|
711 | }
|
---|
712 |
|
---|
713 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
714 | cmbParam* pp = _params[iPar-1];
|
---|
715 | AA(iObs, iPar) = pp->partial(corr->acName, prn);
|
---|
716 | }
|
---|
717 |
|
---|
718 | ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
|
---|
719 | }
|
---|
720 |
|
---|
721 | // Regularization
|
---|
722 | // --------------
|
---|
723 | const double Ph = 1.e6;
|
---|
724 | PP(nObs+1) = Ph;
|
---|
725 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
726 | cmbParam* pp = _params[iPar-1];
|
---|
727 | if (AA.Column(iPar).maximum_absolute_value() > 0.0) {
|
---|
728 | if (pp->type == cmbParam::clkSat) {
|
---|
729 | AA(nObs+1, iPar) = 1.0;
|
---|
730 | }
|
---|
731 | }
|
---|
732 | }
|
---|
733 | int iCond = 1;
|
---|
734 | for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
|
---|
735 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
736 | ++iCond;
|
---|
737 | PP(nObs+iCond) = Ph;
|
---|
738 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
739 | cmbParam* pp = _params[iPar-1];
|
---|
740 | if (pp->type == cmbParam::offACSat && pp->prn == prn) {
|
---|
741 | AA(nObs+iCond, iPar) = 1.0;
|
---|
742 | }
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | return success;
|
---|
747 | }
|
---|
748 |
|
---|
749 | // Change the parameter so that it refers to last received ephemeris
|
---|
750 | ////////////////////////////////////////////////////////////////////////////
|
---|
751 | void bncComb::switchToLastEph(const t_eph* lastEph, cmbParam* pp) {
|
---|
752 |
|
---|
753 | if (pp->type != cmbParam::clkSat) {
|
---|
754 | return;
|
---|
755 | }
|
---|
756 |
|
---|
757 | if (pp->eph == 0) {
|
---|
758 | pp->eph = lastEph;
|
---|
759 | return;
|
---|
760 | }
|
---|
761 |
|
---|
762 | if (pp->eph == lastEph) {
|
---|
763 | return;
|
---|
764 | }
|
---|
765 |
|
---|
766 | ColumnVector oldXC(4);
|
---|
767 | ColumnVector oldVV(3);
|
---|
768 | pp->eph->position(_resTime.gpsw(), _resTime.gpssec(),
|
---|
769 | oldXC.data(), oldVV.data());
|
---|
770 |
|
---|
771 | ColumnVector newXC(4);
|
---|
772 | ColumnVector newVV(3);
|
---|
773 | lastEph->position(_resTime.gpsw(), _resTime.gpssec(),
|
---|
774 | newXC.data(), newVV.data());
|
---|
775 |
|
---|
776 | double dC = newXC(4) - oldXC(4);
|
---|
777 |
|
---|
778 | QString msg = "switch param " + pp->prn
|
---|
779 | + QString(" %1 -> %2 %3").arg(pp->eph->IOD(),3)
|
---|
780 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
781 |
|
---|
782 | emit newMessage(msg.toAscii(), false);
|
---|
783 |
|
---|
784 | pp->eph = lastEph;
|
---|
785 | pp->xx -= dC * t_CST::c;
|
---|
786 | }
|
---|
787 |
|
---|