1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Client
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: t_pppClient
|
---|
6 | *
|
---|
7 | * Purpose: PPP Client processing starts here
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 29-Jul-2014
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <QThreadStorage>
|
---|
18 |
|
---|
19 | #include <iostream>
|
---|
20 | #include <iomanip>
|
---|
21 | #include <cmath>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <stdexcept>
|
---|
25 |
|
---|
26 | #include "pppClient.h"
|
---|
27 | #include "pppEphPool.h"
|
---|
28 | #include "pppObsPool.h"
|
---|
29 | #include "bncconst.h"
|
---|
30 | #include "bncutils.h"
|
---|
31 | #include "pppStation.h"
|
---|
32 | #include "bncantex.h"
|
---|
33 | #include "pppFilter.h"
|
---|
34 |
|
---|
35 | using namespace BNC_PPP;
|
---|
36 | using namespace std;
|
---|
37 |
|
---|
38 | // Global variable holding thread-specific pointers
|
---|
39 | //////////////////////////////////////////////////////////////////////////////
|
---|
40 | QThreadStorage<t_pppClient*> CLIENTS;
|
---|
41 |
|
---|
42 | // Static function returning thread-specific pointer
|
---|
43 | //////////////////////////////////////////////////////////////////////////////
|
---|
44 | t_pppClient* t_pppClient::instance() {
|
---|
45 | return CLIENTS.localData();
|
---|
46 | }
|
---|
47 |
|
---|
48 | // Constructor
|
---|
49 | //////////////////////////////////////////////////////////////////////////////
|
---|
50 | t_pppClient::t_pppClient(const t_pppOptions* opt) {
|
---|
51 | _output = 0;
|
---|
52 | _opt = new t_pppOptions(*opt);
|
---|
53 | _log = new ostringstream();
|
---|
54 | _ephPool = new t_pppEphPool();
|
---|
55 | _obsPool = new t_pppObsPool();
|
---|
56 | _staRover = new t_pppStation();
|
---|
57 | _filter = new t_pppFilter();
|
---|
58 | _tides = new t_tides();
|
---|
59 | _antex = 0;
|
---|
60 | if (!_opt->_antexFileName.empty()) {
|
---|
61 | _antex = new bncAntex(_opt->_antexFileName.c_str());
|
---|
62 | }
|
---|
63 | if (!_opt->_blqFileName.empty()) {
|
---|
64 | if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
|
---|
65 | //_tides->printAllBlqSets();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | _offGlo = 0.0;
|
---|
69 | _offGal = 0.0;
|
---|
70 | _offBds = 0.0;
|
---|
71 | CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
|
---|
72 | }
|
---|
73 |
|
---|
74 | // Destructor
|
---|
75 | //////////////////////////////////////////////////////////////////////////////
|
---|
76 | t_pppClient::~t_pppClient() {
|
---|
77 | delete _log;
|
---|
78 | delete _opt;
|
---|
79 | delete _ephPool;
|
---|
80 | delete _obsPool;
|
---|
81 | delete _staRover;
|
---|
82 | if (_antex) {
|
---|
83 | delete _antex;
|
---|
84 | }
|
---|
85 | delete _filter;
|
---|
86 | delete _tides;
|
---|
87 | clearObs();
|
---|
88 | }
|
---|
89 |
|
---|
90 | //
|
---|
91 | //////////////////////////////////////////////////////////////////////////////
|
---|
92 | void t_pppClient::putEphemeris(const t_eph* eph) {
|
---|
93 | const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
|
---|
94 | const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
|
---|
95 | const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
|
---|
96 | const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
|
---|
97 | if (ephGPS) {
|
---|
98 | _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
|
---|
99 | }
|
---|
100 | else if (ephGlo) {
|
---|
101 | _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
|
---|
102 | }
|
---|
103 | else if (ephGal) {
|
---|
104 | _ephPool->putEphemeris(new t_ephGal(*ephGal));
|
---|
105 | }
|
---|
106 | else if (ephBDS) {
|
---|
107 | _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | //
|
---|
112 | //////////////////////////////////////////////////////////////////////////////
|
---|
113 | void t_pppClient::putTec(const t_vTec* vTec) {
|
---|
114 | _obsPool->putTec(new t_vTec(*vTec));
|
---|
115 | }
|
---|
116 |
|
---|
117 | //
|
---|
118 | //////////////////////////////////////////////////////////////////////////////
|
---|
119 | void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
|
---|
120 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
---|
121 | _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | //
|
---|
126 | //////////////////////////////////////////////////////////////////////////////
|
---|
127 | void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
|
---|
128 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
---|
129 | _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | //
|
---|
134 | //////////////////////////////////////////////////////////////////////////////
|
---|
135 | void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
|
---|
136 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
---|
137 | _obsPool->putCodeBias(new t_satCodeBias(*biases[ii]));
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | //
|
---|
142 | //////////////////////////////////////////////////////////////////////////////
|
---|
143 | void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
|
---|
144 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
---|
145 | _obsPool->putPhaseBias(new t_satPhaseBias(*biases[ii]));
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | //
|
---|
150 | //////////////////////////////////////////////////////////////////////////////
|
---|
151 | t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
|
---|
152 | vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
|
---|
153 |
|
---|
154 | // Default
|
---|
155 | // -------
|
---|
156 | epoTime.reset();
|
---|
157 | clearObs();
|
---|
158 |
|
---|
159 | // Create vector of valid observations
|
---|
160 | // -----------------------------------
|
---|
161 | for (unsigned ii = 0; ii < satObs.size(); ii++) {
|
---|
162 | char sys = satObs[ii]->_prn.system();
|
---|
163 | if (_opt->useSystem(sys)) {
|
---|
164 | t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
|
---|
165 | if (pppSatObs->isValid()) {
|
---|
166 | obsVector.push_back(pppSatObs);
|
---|
167 | }
|
---|
168 | else {
|
---|
169 | delete pppSatObs;
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Check whether data are synchronized, compute epoTime
|
---|
175 | // ----------------------------------------------------
|
---|
176 | const double MAXSYNC = 0.05; // synchronization limit
|
---|
177 | double meanDt = 0.0;
|
---|
178 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
179 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
180 | if (epoTime.undef()) {
|
---|
181 | epoTime = satObs->time();
|
---|
182 | }
|
---|
183 | else {
|
---|
184 | double dt = satObs->time() - epoTime;
|
---|
185 | if (fabs(dt) > MAXSYNC) {
|
---|
186 | LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
|
---|
187 | return failure;
|
---|
188 | }
|
---|
189 | meanDt += dt;
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (obsVector.size() > 0) {
|
---|
194 | epoTime += meanDt / obsVector.size();
|
---|
195 | }
|
---|
196 |
|
---|
197 | return success;
|
---|
198 | }
|
---|
199 |
|
---|
200 | //
|
---|
201 | //////////////////////////////////////////////////////////////////////////////
|
---|
202 | bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
|
---|
203 |
|
---|
204 | bool pseudoObsIono = false;
|
---|
205 |
|
---|
206 | if (_opt->_pseudoObsIono) {
|
---|
207 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
---|
208 | while (it != obsVector.end()) {
|
---|
209 | t_pppSatObs* satObs = *it;
|
---|
210 | pseudoObsIono = satObs->setPseudoObsIono(t_frequency::G1);
|
---|
211 | it++;
|
---|
212 | }
|
---|
213 | }
|
---|
214 | /*vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
---|
215 | while (it != obsVector.end()) {
|
---|
216 | t_pppSatObs* satObs = *it;
|
---|
217 | satObs->printObsMinusComputed();
|
---|
218 | it++;
|
---|
219 | }*/
|
---|
220 |
|
---|
221 | return pseudoObsIono;
|
---|
222 | }
|
---|
223 |
|
---|
224 | //
|
---|
225 | //////////////////////////////////////////////////////////////////////////////
|
---|
226 | void t_pppClient::useObsWithCodeBiasesOnly(std::vector<t_pppSatObs*>& obsVector) {
|
---|
227 |
|
---|
228 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
---|
229 | while (it != obsVector.end()) {
|
---|
230 | t_pppSatObs* pppSatObs = *it;
|
---|
231 | char sys = pppSatObs->prn().system();
|
---|
232 | bool codeBiasesAvailable = false;
|
---|
233 | t_frequency::type fType1 = t_lc::toFreq(sys,t_lc::c1);
|
---|
234 | t_frequency::type fType2 = t_lc::toFreq(sys,t_lc::c2);
|
---|
235 | if (pppSatObs->getCodeBias(fType1) &&
|
---|
236 | pppSatObs->getCodeBias(fType2)) {
|
---|
237 | codeBiasesAvailable = true;
|
---|
238 | }
|
---|
239 | if (codeBiasesAvailable) {
|
---|
240 | ++it;
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | it = obsVector.erase(it);
|
---|
244 | delete pppSatObs;
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | // Compute the Bancroft position, check for blunders
|
---|
252 | //////////////////////////////////////////////////////////////////////////////
|
---|
253 | t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
|
---|
254 | vector<t_pppSatObs*>& obsVector,
|
---|
255 | ColumnVector& xyzc, bool print) {
|
---|
256 |
|
---|
257 | t_lc::type tLC = t_lc::dummy;
|
---|
258 |
|
---|
259 | while (true) {
|
---|
260 | Matrix BB(obsVector.size(), 4);
|
---|
261 | int iObs = -1;
|
---|
262 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
263 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
264 | if (tLC == t_lc::dummy) {
|
---|
265 | if (satObs->isValid(t_lc::cIF)) {
|
---|
266 | tLC = t_lc::cIF;
|
---|
267 | }
|
---|
268 | else if (satObs->isValid(t_lc::c1)) {
|
---|
269 | tLC = t_lc::c1;
|
---|
270 | }
|
---|
271 | else if (satObs->isValid(t_lc::c2)) {
|
---|
272 | tLC = t_lc::c2;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | if ( satObs->isValid(tLC) &&
|
---|
276 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
---|
277 | ++iObs;
|
---|
278 | BB[iObs][0] = satObs->xc()[0];
|
---|
279 | BB[iObs][1] = satObs->xc()[1];
|
---|
280 | BB[iObs][2] = satObs->xc()[2];
|
---|
281 | BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
|
---|
282 | }
|
---|
283 | }
|
---|
284 | if (iObs + 1 < _opt->_minObs) {
|
---|
285 | LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
|
---|
286 | return failure;
|
---|
287 | }
|
---|
288 | BB = BB.Rows(1,iObs+1);
|
---|
289 | if (bancroft(BB, xyzc) != success) {
|
---|
290 | return failure;
|
---|
291 | }
|
---|
292 |
|
---|
293 | xyzc[3] /= t_CST::c;
|
---|
294 |
|
---|
295 | // Check Blunders
|
---|
296 | // --------------
|
---|
297 | const double BLUNDER = 100.0;
|
---|
298 | double maxRes = 0.0;
|
---|
299 | unsigned maxResIndex = 0;
|
---|
300 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
301 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
302 | if (satObs->isValid() &&
|
---|
303 | (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
|
---|
304 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
---|
305 | double res = rr.NormFrobenius() - satObs->obsValue(tLC)
|
---|
306 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
---|
307 | if (fabs(res) > maxRes) {
|
---|
308 | maxRes = fabs(res);
|
---|
309 | maxResIndex = ii;
|
---|
310 | }
|
---|
311 | }
|
---|
312 | }
|
---|
313 | if (maxRes < BLUNDER) {
|
---|
314 | if (print) {
|
---|
315 | LOG.setf(ios::fixed);
|
---|
316 | LOG << "\nPPP of Epoch ";
|
---|
317 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
---|
318 | LOG << "\n---------------------------------------------------------------\n";
|
---|
319 | LOG << string(epoTime) << " BANCROFT:" << ' '
|
---|
320 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
---|
321 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
---|
322 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
---|
323 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
---|
324 | }
|
---|
325 | break;
|
---|
326 | }
|
---|
327 | else {
|
---|
328 | t_pppSatObs* satObs = obsVector.at(maxResIndex);
|
---|
329 | LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
|
---|
330 | << " " << maxRes << endl;
|
---|
331 | delete satObs;
|
---|
332 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | return success;
|
---|
337 | }
|
---|
338 | // Compute A Priori Glonass Receiver Clock Offset
|
---|
339 | //////////////////////////////////////////////////////////////////////////////
|
---|
340 | double t_pppClient::cmpOffGlo(vector<t_pppSatObs*>& obsVector) {
|
---|
341 |
|
---|
342 | t_lc::type tLC = t_lc::dummy;
|
---|
343 | double offGlo = 0.0;
|
---|
344 |
|
---|
345 | if (OPT->useSystem('R')) {
|
---|
346 |
|
---|
347 | while (obsVector.size() > 0) {
|
---|
348 | offGlo = 0.0;
|
---|
349 | double maxRes = 0.0;
|
---|
350 | int maxResIndex = -1;
|
---|
351 | t_prn maxResPrn;
|
---|
352 | unsigned nObs = 0;
|
---|
353 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
354 | t_pppSatObs* satObs = obsVector.at(ii);
|
---|
355 | if (satObs->prn().system() == 'R') {
|
---|
356 | if (tLC == t_lc::dummy) {
|
---|
357 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
---|
358 | }
|
---|
359 | if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle)) {
|
---|
360 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
361 | ++nObs;
|
---|
362 | offGlo += ll;
|
---|
363 | if (fabs(ll) > fabs(maxRes)) {
|
---|
364 | maxRes = ll;
|
---|
365 | maxResIndex = ii;
|
---|
366 | maxResPrn = satObs->prn();
|
---|
367 | }
|
---|
368 | }
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (nObs > 0) {
|
---|
373 | offGlo = offGlo / nObs;
|
---|
374 | }
|
---|
375 | else {
|
---|
376 | offGlo = 0.0;
|
---|
377 | }
|
---|
378 |
|
---|
379 | if (fabs(maxRes) > 1000.0) {
|
---|
380 | LOG << "t_pppClient::cmpOffGlo outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
---|
381 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
382 | }
|
---|
383 | else {
|
---|
384 | break;
|
---|
385 | }
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | return offGlo;
|
---|
390 | }
|
---|
391 |
|
---|
392 | // Compute A Priori Galileo Receiver Clock Offset
|
---|
393 | //////////////////////////////////////////////////////////////////////////////
|
---|
394 | double t_pppClient::cmpOffGal(vector<t_pppSatObs*>& obsVector) {
|
---|
395 |
|
---|
396 | t_lc::type tLC = t_lc::dummy;
|
---|
397 | double offGal = 0.0;
|
---|
398 |
|
---|
399 | if (OPT->useSystem('E')) {
|
---|
400 |
|
---|
401 | while (obsVector.size() > 0) {
|
---|
402 | offGal = 0.0;
|
---|
403 | double maxRes = 0.0;
|
---|
404 | int maxResIndex = -1;
|
---|
405 | t_prn maxResPrn;
|
---|
406 | unsigned nObs = 0;
|
---|
407 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
408 | t_pppSatObs* satObs = obsVector.at(ii);
|
---|
409 | if (satObs->prn().system() == 'E') {
|
---|
410 | if (tLC == t_lc::dummy) {
|
---|
411 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
---|
412 | }
|
---|
413 | if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle)) {
|
---|
414 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
415 | ++nObs;
|
---|
416 | offGal += ll;
|
---|
417 | if (fabs(ll) > fabs(maxRes)) {
|
---|
418 | maxRes = ll;
|
---|
419 | maxResIndex = ii;
|
---|
420 | maxResPrn = satObs->prn();
|
---|
421 | }
|
---|
422 | }
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | if (nObs > 0) {
|
---|
427 | offGal = offGal / nObs;
|
---|
428 | }
|
---|
429 | else {
|
---|
430 | offGal = 0.0;
|
---|
431 | }
|
---|
432 |
|
---|
433 | if (fabs(maxRes) > 1000.0) {
|
---|
434 | LOG << "t_pppClient::cmpOffGal outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
---|
435 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
436 | }
|
---|
437 | else {
|
---|
438 | break;
|
---|
439 | }
|
---|
440 | }
|
---|
441 | }
|
---|
442 |
|
---|
443 | return offGal;
|
---|
444 | }
|
---|
445 |
|
---|
446 |
|
---|
447 | // Compute A Priori BDS Receiver Clock Offset
|
---|
448 | //////////////////////////////////////////////////////////////////////////////
|
---|
449 | double t_pppClient::cmpOffBds(vector<t_pppSatObs*>& obsVector) {
|
---|
450 |
|
---|
451 | t_lc::type tLC = t_lc::dummy;
|
---|
452 | double offBds = 0.0;
|
---|
453 |
|
---|
454 | if (_opt->useSystem('C')) {
|
---|
455 | while (obsVector.size() > 0) {
|
---|
456 | offBds = 0.0;
|
---|
457 | double maxRes = 0.0;
|
---|
458 | int maxResIndex = -1;
|
---|
459 | t_prn maxResPrn;
|
---|
460 | unsigned nObs = 0;
|
---|
461 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
462 | const t_pppSatObs* satObs = obsVector.at(ii);
|
---|
463 | if (satObs->prn().system() == 'C') {
|
---|
464 | if (tLC == t_lc::dummy) {
|
---|
465 | tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
|
---|
466 | }
|
---|
467 | if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
|
---|
468 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
469 | ++nObs;
|
---|
470 | offBds += ll;
|
---|
471 | if (fabs(ll) > fabs(maxRes)) {
|
---|
472 | maxRes = ll;
|
---|
473 | maxResIndex = ii;
|
---|
474 | maxResPrn = satObs->prn();
|
---|
475 | }
|
---|
476 | }
|
---|
477 | }
|
---|
478 | }
|
---|
479 |
|
---|
480 | if (nObs > 0) {
|
---|
481 | offBds = offBds / nObs;
|
---|
482 | }
|
---|
483 | else {
|
---|
484 | offBds = 0.0;
|
---|
485 | }
|
---|
486 |
|
---|
487 | if (fabs(maxRes) > 1000.0) {
|
---|
488 | LOG << "t_pppClient::cmpOffBds outlier " << maxResPrn.toString() << " " << maxRes << endl;
|
---|
489 | delete obsVector.at(maxResIndex);
|
---|
490 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
491 | }
|
---|
492 | else {
|
---|
493 | break;
|
---|
494 | }
|
---|
495 | }
|
---|
496 | }
|
---|
497 | return offBds;
|
---|
498 | }
|
---|
499 | //
|
---|
500 | //////////////////////////////////////////////////////////////////////////////
|
---|
501 | void t_pppClient::initOutput(t_output* output) {
|
---|
502 | _output = output;
|
---|
503 | _output->_numSat = 0;
|
---|
504 | _output->_hDop = 0.0;
|
---|
505 | _output->_error = false;
|
---|
506 | }
|
---|
507 |
|
---|
508 | //
|
---|
509 | //////////////////////////////////////////////////////////////////////////////
|
---|
510 | void t_pppClient::clearObs() {
|
---|
511 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
---|
512 | delete _obsRover.at(ii);
|
---|
513 | }
|
---|
514 | _obsRover.clear();
|
---|
515 | }
|
---|
516 |
|
---|
517 | //
|
---|
518 | //////////////////////////////////////////////////////////////////////////////
|
---|
519 | void t_pppClient::finish(t_irc irc, int ind) {
|
---|
520 | #ifdef BNC_DEBUG_PPP
|
---|
521 | LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
|
---|
522 | #endif
|
---|
523 |
|
---|
524 | clearObs();
|
---|
525 |
|
---|
526 | _output->_epoTime = _epoTimeRover;
|
---|
527 |
|
---|
528 | if (irc == success) {
|
---|
529 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
---|
530 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
---|
531 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
---|
532 |
|
---|
533 | xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
|
---|
534 |
|
---|
535 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
---|
536 |
|
---|
537 | _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
|
---|
538 | _output->_trp = _filter->trp();
|
---|
539 | _output->_trpStdev = _filter->trpStdev();
|
---|
540 |
|
---|
541 | _output->_numSat = _filter->numSat();
|
---|
542 | _output->_hDop = _filter->HDOP();
|
---|
543 | _output->_error = false;
|
---|
544 | }
|
---|
545 | else {
|
---|
546 | _output->_error = true;
|
---|
547 | }
|
---|
548 |
|
---|
549 | _output->_log = _log->str();
|
---|
550 | delete _log; _log = new ostringstream();
|
---|
551 |
|
---|
552 | return;
|
---|
553 | }
|
---|
554 |
|
---|
555 | //
|
---|
556 | //////////////////////////////////////////////////////////////////////////////
|
---|
557 | t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
|
---|
558 | vector<t_pppSatObs*>& obsVector) {
|
---|
559 | bncTime time;
|
---|
560 | time = _epoTimeRover;
|
---|
561 | station->setName(_opt->_roverName);
|
---|
562 | station->setAntName(_opt->_antNameRover);
|
---|
563 | station->setEpochTime(time);
|
---|
564 |
|
---|
565 | if (_opt->xyzAprRoverSet()) {
|
---|
566 | station->setXyzApr(_opt->_xyzAprRover);
|
---|
567 | }
|
---|
568 | else {
|
---|
569 | station->setXyzApr(xyzc.Rows(1,3));
|
---|
570 | }
|
---|
571 | station->setNeuEcc(_opt->_neuEccRover);
|
---|
572 |
|
---|
573 | // Receiver Clock
|
---|
574 | // --------------
|
---|
575 | station->setDClk(xyzc[3]);
|
---|
576 |
|
---|
577 | // Tides
|
---|
578 | // -----
|
---|
579 | station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
|
---|
580 | station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
|
---|
581 |
|
---|
582 | // Observation model
|
---|
583 | // -----------------
|
---|
584 | vector<t_pppSatObs*>::iterator it = obsVector.begin();
|
---|
585 | while (it != obsVector.end()) {
|
---|
586 | t_pppSatObs* satObs = *it;
|
---|
587 | t_irc modelSetup;
|
---|
588 | if (satObs->isValid()) {
|
---|
589 | modelSetup = satObs->cmpModel(station);
|
---|
590 | }
|
---|
591 | if (satObs->isValid() &&
|
---|
592 | satObs->eleSat() >= _opt->_minEle &&
|
---|
593 | modelSetup == success) {
|
---|
594 | ++it;
|
---|
595 | }
|
---|
596 | else {
|
---|
597 | delete satObs;
|
---|
598 | it = obsVector.erase(it);
|
---|
599 | }
|
---|
600 | }
|
---|
601 |
|
---|
602 | return success;
|
---|
603 | }
|
---|
604 |
|
---|
605 | //
|
---|
606 | //////////////////////////////////////////////////////////////////////////////
|
---|
607 | void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
|
---|
608 |
|
---|
609 | try {
|
---|
610 | initOutput(output);
|
---|
611 |
|
---|
612 | // Prepare Observations of the Rover
|
---|
613 | // ---------------------------------
|
---|
614 | if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
|
---|
615 | return finish(failure, 1);
|
---|
616 | }
|
---|
617 |
|
---|
618 | for (int iter = 1; iter <= 2; iter++) {
|
---|
619 | ColumnVector xyzc(4); xyzc = 0.0;
|
---|
620 | bool print = (iter == 2);
|
---|
621 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
---|
622 | return finish(failure, 2);
|
---|
623 | }
|
---|
624 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
---|
625 | return finish(failure, 3);
|
---|
626 | }
|
---|
627 | }
|
---|
628 | // use observations only if satellite code biases are available
|
---|
629 | /* ------------------------------------------------------------
|
---|
630 | if (!_opt->_corrMount.empty() {
|
---|
631 | useObsWithCodeBiasesOnly(_obsRover);
|
---|
632 | }*/
|
---|
633 |
|
---|
634 | if (int(_obsRover.size()) < _opt->_minObs) {
|
---|
635 | LOG << "t_pppClient::processEpoch not enough observations" << endl;
|
---|
636 | return finish(failure, 4);
|
---|
637 | }
|
---|
638 |
|
---|
639 | _offGlo = cmpOffGlo(_obsRover);
|
---|
640 | _offGal = cmpOffGal(_obsRover);
|
---|
641 | _offBds = cmpOffBds(_obsRover);
|
---|
642 |
|
---|
643 | // Prepare Pseudo Observations of the Rover
|
---|
644 | // ----------------------------------------
|
---|
645 | _pseudoObsIono = preparePseudoObs(_obsRover);
|
---|
646 |
|
---|
647 | // Store last epoch of data
|
---|
648 | // ------------------------
|
---|
649 | _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
|
---|
650 |
|
---|
651 | // Process Epoch in Filter
|
---|
652 | // -----------------------
|
---|
653 | if (_filter->processEpoch(_obsPool) != success) {
|
---|
654 | LOG << "filter->processEpoch() != success" << endl;
|
---|
655 | return finish(failure, 5);
|
---|
656 | }
|
---|
657 | }
|
---|
658 | catch (Exception& exc) {
|
---|
659 | LOG << exc.what() << endl;
|
---|
660 | return finish(failure, 6);
|
---|
661 | }
|
---|
662 | catch (t_except msg) {
|
---|
663 | LOG << msg.what() << endl;
|
---|
664 | return finish(failure, 7);
|
---|
665 | }
|
---|
666 | catch (const char* msg) {
|
---|
667 | LOG << msg << endl;
|
---|
668 | return finish(failure, 8);
|
---|
669 | }
|
---|
670 | catch (...) {
|
---|
671 | LOG << "unknown exception" << endl;
|
---|
672 | return finish(failure, 9);
|
---|
673 | }
|
---|
674 | return finish(success, 0);
|
---|
675 | }
|
---|
676 |
|
---|
677 | //
|
---|
678 | ////////////////////////////////////////////////////////////////////////////
|
---|
679 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
---|
680 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
---|
681 | }
|
---|
682 |
|
---|
683 | //
|
---|
684 | ////////////////////////////////////////////////////////////////////////////
|
---|
685 | t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
---|
686 |
|
---|
687 | if (pos.Nrows() != 4) {
|
---|
688 | pos.ReSize(4);
|
---|
689 | }
|
---|
690 | pos = 0.0;
|
---|
691 |
|
---|
692 | for (int iter = 1; iter <= 2; iter++) {
|
---|
693 | Matrix BB = BBpass;
|
---|
694 | int mm = BB.Nrows();
|
---|
695 | for (int ii = 1; ii <= mm; ii++) {
|
---|
696 | double xx = BB(ii,1);
|
---|
697 | double yy = BB(ii,2);
|
---|
698 | double traveltime = 0.072;
|
---|
699 | if (iter > 1) {
|
---|
700 | double zz = BB(ii,3);
|
---|
701 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
---|
702 | (yy-pos(2)) * (yy-pos(2)) +
|
---|
703 | (zz-pos(3)) * (zz-pos(3)) );
|
---|
704 | traveltime = rho / t_CST::c;
|
---|
705 | }
|
---|
706 | double angle = traveltime * t_CST::omega;
|
---|
707 | double cosa = cos(angle);
|
---|
708 | double sina = sin(angle);
|
---|
709 | BB(ii,1) = cosa * xx + sina * yy;
|
---|
710 | BB(ii,2) = -sina * xx + cosa * yy;
|
---|
711 | }
|
---|
712 |
|
---|
713 | Matrix BBB;
|
---|
714 | if (mm > 4) {
|
---|
715 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
---|
716 | BBB = hlp.i() * BB.t();
|
---|
717 | }
|
---|
718 | else {
|
---|
719 | BBB = BB.i();
|
---|
720 | }
|
---|
721 | ColumnVector ee(mm); ee = 1.0;
|
---|
722 | ColumnVector alpha(mm); alpha = 0.0;
|
---|
723 | for (int ii = 1; ii <= mm; ii++) {
|
---|
724 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
---|
725 | }
|
---|
726 | ColumnVector BBBe = BBB * ee;
|
---|
727 | ColumnVector BBBalpha = BBB * alpha;
|
---|
728 | double aa = lorentz(BBBe, BBBe);
|
---|
729 | double bb = lorentz(BBBe, BBBalpha)-1;
|
---|
730 | double cc = lorentz(BBBalpha, BBBalpha);
|
---|
731 | double root = sqrt(bb*bb-aa*cc);
|
---|
732 |
|
---|
733 | Matrix hlpPos(4,2);
|
---|
734 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
---|
735 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
---|
736 |
|
---|
737 | ColumnVector omc(2);
|
---|
738 | for (int pp = 1; pp <= 2; pp++) {
|
---|
739 | hlpPos(4,pp) = -hlpPos(4,pp);
|
---|
740 | omc(pp) = BB(1,4) -
|
---|
741 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
---|
742 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
---|
743 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
---|
744 | hlpPos(4,pp);
|
---|
745 | }
|
---|
746 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
---|
747 | pos = hlpPos.Column(2);
|
---|
748 | }
|
---|
749 | else {
|
---|
750 | pos = hlpPos.Column(1);
|
---|
751 | }
|
---|
752 | }
|
---|
753 | if (pos.size() != 4 ||
|
---|
754 | std::isnan(pos(1)) ||
|
---|
755 | std::isnan(pos(2)) ||
|
---|
756 | std::isnan(pos(3)) ||
|
---|
757 | std::isnan(pos(4))) {
|
---|
758 | return failure;
|
---|
759 | }
|
---|
760 |
|
---|
761 | return success;
|
---|
762 | }
|
---|
763 |
|
---|
764 | //
|
---|
765 | //////////////////////////////////////////////////////////////////////////////
|
---|
766 | void t_pppClient::reset() {cout << "t_pppClient::reset()" << endl;
|
---|
767 |
|
---|
768 | // to delete old orbit and clock corrections
|
---|
769 | delete _ephPool;
|
---|
770 | _ephPool = new t_pppEphPool();
|
---|
771 |
|
---|
772 | // to delete old code biases
|
---|
773 | delete _obsPool;
|
---|
774 | _obsPool = new t_pppObsPool();
|
---|
775 |
|
---|
776 | // to delete all parameters
|
---|
777 | delete _filter;
|
---|
778 | _filter = new t_pppFilter();
|
---|
779 |
|
---|
780 | }
|
---|