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