source: ntrip/trunk/BNC/src/PPP/pppParlist.cpp@ 8956

Last change on this file since 8956 was 8956, checked in by stuerze, 4 years ago

update regarding PPP

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 15.1 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppParlist
6 *
7 * Purpose: List of estimated parameters
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <cmath>
18#include <iostream>
19#include <sstream>
20#include <iomanip>
21#include <algorithm>
22#include <newmatio.h>
23
24#include "pppParlist.h"
25#include "pppSatObs.h"
26#include "pppStation.h"
27#include "bncutils.h"
28#include "bncconst.h"
29#include "pppClient.h"
30
31using namespace BNC_PPP;
32using namespace std;
33
34// Constructor
35////////////////////////////////////////////////////////////////////////////
36t_pppParam::t_pppParam(e_type type, const t_prn& prn, t_lc::type tLC,
37 const vector<t_pppSatObs*>* obsVector) {
38
39 _type = type;
40 _prn = prn;
41 _tLC = tLC;
42 _x0 = 0.0;
43 _indexOld = -1;
44 _indexNew = -1;
45 _noise = 0.0;
46 _ambInfo = 0;
47
48 switch (_type) {
49 case crdX:
50 _epoSpec = false;
51 _sigma0 = OPT->_aprSigCrd[0];
52 _noise = OPT->_noiseCrd[0];
53 break;
54 case crdY:
55 _epoSpec = false;
56 _sigma0 = OPT->_aprSigCrd[1];
57 _noise = OPT->_noiseCrd[1];
58 break;
59 case crdZ:
60 _epoSpec = false;
61 _sigma0 = OPT->_aprSigCrd[2];
62 _noise = OPT->_noiseCrd[2];
63 break;
64 case clkR:
65 _epoSpec = true;
66 _sigma0 = OPT->_noiseClk;
67 break;
68 case amb:
69 _epoSpec = false;
70 _sigma0 = OPT->_aprSigAmb;
71 _ambInfo = new t_ambInfo();
72 if (obsVector) {
73 for (unsigned ii = 0; ii < obsVector->size(); ii++) {
74 const t_pppSatObs* obs = obsVector->at(ii);
75 if (obs->prn() == _prn) {
76 double offGG = 0;
77 if (_prn.system() == 'R' && tLC != t_lc::MW) {
78 offGG = PPP_CLIENT->offGG();
79 }
80 _x0 = floor((obs->obsValue(tLC) - offGG - obs->cmpValue(tLC)) / obs->lambda(tLC) + 0.5);
81 break;
82 }
83 }
84 }
85 break;
86 case offGG:
87 _epoSpec = true;
88 _sigma0 = 1000.0;
89 _x0 = PPP_CLIENT->offGG();
90 break;
91 case trp:
92 _epoSpec = false;
93 _sigma0 = OPT->_aprSigTrp;
94 _noise = OPT->_noiseTrp;
95 break;
96 case ion:
97 _epoSpec = false;
98 _sigma0 = OPT->_aprSigIon;
99 _noise = OPT->_noiseIon;
100 break;
101 case cBias1:
102 case cBias2:
103 _epoSpec = false;
104 _sigma0 = OPT->_aprSigCodeBias;
105 _noise = OPT->_noiseCodeBias;
106 break;
107 case pBias1:
108 case pBias2:
109 _epoSpec = false;
110 _sigma0 = OPT->_aprSigPhaseBias;
111 _noise = OPT->_noisePhaseBias;
112 break;
113 }
114}
115
116// Destructor
117////////////////////////////////////////////////////////////////////////////
118t_pppParam::~t_pppParam() {
119 delete _ambInfo;
120}
121
122//
123////////////////////////////////////////////////////////////////////////////
124double t_pppParam::partial(const bncTime& /* epoTime */, const t_pppSatObs* obs,
125 const t_lc::type& tLC, const t_prn refPrn) const {
126
127 // Special Case - Melbourne-Wuebbena
128 // ---------------------------------
129 if (tLC == t_lc::MW && _type != amb) {
130 return 0.0;
131 }
132
133 const t_pppStation* sta = PPP_CLIENT->staRover();
134 ColumnVector rhoV = sta->xyzApr() - obs->xc().Rows(1,3);
135
136 map<t_frequency::type, double> codeCoeff;
137 map<t_frequency::type, double> phaseCoeff;
138 map<t_frequency::type, double> ionoCoeff;
139 obs->lcCoeff(tLC, codeCoeff, phaseCoeff, ionoCoeff);
140
141 switch (_type) {
142 case crdX:
143 if (tLC == t_lc::GIM) {return 0.0;}
144 return (sta->xyzApr()[0] - obs->xc()[0]) / rhoV.NormFrobenius();
145 case crdY:
146 if (tLC == t_lc::GIM) {return 0.0;}
147 return (sta->xyzApr()[1] - obs->xc()[1]) / rhoV.NormFrobenius();
148 case crdZ:
149 if (tLC == t_lc::GIM) {return 0.0;}
150 return (sta->xyzApr()[2] - obs->xc()[2]) / rhoV.NormFrobenius();
151 case clkR:
152 if (tLC == t_lc::GIM) {return 0.0;}
153 return 1.0;
154 case offGG:
155 if (tLC == t_lc::GIM) {return 0.0;}
156 return (obs->prn().system() == 'R') ? 1.0 : 0.0;
157 case amb:
158 if (tLC == t_lc::GIM) {return 0.0;}
159 else if ((OPT->_obsModelType == OPT->IF) ||
160 (OPT->_obsModelType == OPT->PPPRTK) ||
161 (OPT->_obsModelType == OPT->UncombPPP) ||
162 (OPT->_obsModelType == OPT->DCMcodeBias && !obs->isReference()) ||
163 (OPT->_obsModelType == OPT->DCMphaseBias && !obs->isReference()) ) {
164 if (obs->prn() == _prn) {
165 if (tLC == _tLC) {
166 return (obs->lambda(tLC));
167 }
168 else if (tLC == t_lc::lIF && _tLC == t_lc::MW) {
169 return obs->lambda(t_lc::lIF) * obs->lambda(t_lc::MW) / obs->lambda(t_lc::l2);
170 }
171 else {
172 if (_tLC == t_lc::l1) {
173 return obs->lambda(t_lc::l1) * phaseCoeff[t_lc::toFreq(obs->prn().system(),t_lc::l1)];
174 }
175 else if (_tLC == t_lc::l2) {
176 return obs->lambda(t_lc::l2) * phaseCoeff[t_lc::toFreq(obs->prn().system(),t_lc::l2)];
177 }
178 }
179 }
180 }
181 break;
182 case trp:
183 if (tLC == t_lc::GIM) {return 0.0;}
184 return 1.0 / sin(obs->eleSat());
185 case ion:
186
187 if (obs->prn() == _prn) {
188 if (tLC == t_lc::c1) {
189 return ionoCoeff[t_lc::toFreq(obs->prn().system(),t_lc::c1)];
190 }
191 else if (tLC == t_lc::c2) {
192 return ionoCoeff[t_lc::toFreq(obs->prn().system(),t_lc::c2)];
193 }
194 else if (tLC == t_lc::l1) {
195 return ionoCoeff[t_lc::toFreq(obs->prn().system(),t_lc::l1)];
196 }
197 else if (tLC == t_lc::l2) {
198 return ionoCoeff[t_lc::toFreq(obs->prn().system(),t_lc::l2)];
199 }
200 else if (tLC == t_lc::GIM) {
201 return -1.0;
202 }
203 }
204 if (tLC == t_lc::GIM && _prn == refPrn) {
205 return 1.0;
206 }
207 break;
208 case cBias1:
209 if (tLC == t_lc::c1) {
210 return 1.0;
211 }
212 else {
213 return 0.0;
214 }
215 break;
216 case cBias2:
217 if (tLC == t_lc::c2) {
218 return 1.0;
219 }
220 else {
221 return 0.0;
222 }
223 break;
224 case pBias1:
225 if (tLC == t_lc::l1) {
226 return 1.0;
227 }
228 else {
229 return 0.0;
230 }
231 break;
232 case pBias2:
233 if (tLC == t_lc::l2) {
234 return 1.0;
235 }
236 else {
237 return 0.0;
238 }
239 }
240 return 0.0;
241}
242
243//
244////////////////////////////////////////////////////////////////////////////
245string t_pppParam::toString() const {
246 stringstream ss;
247 switch (_type) {
248 case crdX:
249 ss << "CRD_X";
250 break;
251 case crdY:
252 ss << "CRD_Y";
253 break;
254 case crdZ:
255 ss << "CRD_Z";
256 break;
257 case clkR:
258 ss << "REC_CLK ";
259 break;
260 case offGG:
261 ss << "OGG ";
262 break;
263 case trp:
264 ss << "TRP ";
265 break;
266 case amb:
267 ss << "AMB " << left << setw(3) << t_lc::toString(_tLC) << right << ' ' << _prn.toString();
268 break;
269 case ion:
270 ss << "ION " << left << setw(3) << t_lc::toString(_tLC) << right << ' ' << _prn.toString();
271 break;
272 case cBias1:
273 case cBias2:
274 case pBias1:
275 case pBias2:
276 ss << "BIAS " << left << setw(3) << t_lc::toString(_tLC) << right << ' ' << "REC";
277 break;
278 }
279 return ss.str();
280}
281
282// Constructor
283////////////////////////////////////////////////////////////////////////////
284t_pppParlist::t_pppParlist() {
285}
286
287// Destructor
288////////////////////////////////////////////////////////////////////////////
289t_pppParlist::~t_pppParlist() {
290 for (unsigned ii = 0; ii < _params.size(); ii++) {
291 delete _params[ii];
292 }
293}
294
295//
296////////////////////////////////////////////////////////////////////////////
297t_irc t_pppParlist::set(const bncTime& epoTime,
298 const std::vector<t_pppSatObs*>& obsVector,
299 const QMap<char, t_pppRefSat*>& refSatMap) {
300
301 // Remove some Parameters
302 // ----------------------
303 vector<t_pppParam*>::iterator it = _params.begin();
304 while (it != _params.end()) {
305 t_pppParam* par = *it;
306
307 bool remove = false;
308
309 if (par->epoSpec()) {
310 remove = true;
311 }
312
313 else if (par->type() == t_pppParam::crdX ||
314 par->type() == t_pppParam::crdY ||
315 par->type() == t_pppParam::crdZ) {
316 if (par->lastObsTime().valid() && (epoTime - par->lastObsTime() > 60.0)) {
317 remove = true;
318 }
319 }
320 else if (par->type() == t_pppParam::amb) {
321 char system = par->prn().system();
322 t_prn refPrn = t_prn();
323 if (OPT->_refSatRequired) {
324 refPrn = (refSatMap[system])->prn();
325 }
326 if ((par->lastObsTime().valid() && (epoTime - par->lastObsTime() > 60.0)) ||
327 ( refPrn == par->prn())) {
328 remove = true;
329 }
330 }
331
332 if (remove) {
333 delete par;
334 it = _params.erase(it);
335 }
336 else {
337 ++it;
338 }
339 }
340
341 // Check whether parameters have observations
342 // ------------------------------------------
343 for (unsigned ii = 0; ii < _params.size(); ii++) {
344 t_pppParam* par = _params[ii];
345 if (par->prn() == 0) {
346 par->setLastObsTime(epoTime);
347 if (par->firstObsTime().undef()) {
348 par->setFirstObsTime(epoTime);
349 }
350 }
351 else {
352 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
353 const t_pppSatObs* satObs = obsVector[jj];
354 if (satObs->prn() == par->prn()) {
355 par->setLastObsTime(epoTime);
356 if (par->firstObsTime().undef()) {
357 par->setFirstObsTime(epoTime);
358 }
359 break;
360 }
361 }
362 }
363 }
364
365 // Required Set of Parameters
366 // --------------------------
367 vector<t_pppParam*> required;
368
369 // Coordinates
370 // -----------
371 required.push_back(new t_pppParam(t_pppParam::crdX, t_prn(), t_lc::dummy));
372 required.push_back(new t_pppParam(t_pppParam::crdY, t_prn(), t_lc::dummy));
373 required.push_back(new t_pppParam(t_pppParam::crdZ, t_prn(), t_lc::dummy));
374
375 // Receiver Clock
376 // --------------
377 required.push_back(new t_pppParam(t_pppParam::clkR, t_prn(), t_lc::dummy));
378
379 // GPS-GLONASS Clock Offset
380 // ------------------------
381 if (OPT->useSystem('R')) {
382 required.push_back(new t_pppParam(t_pppParam::offGG, t_prn(), t_lc::dummy));
383 }
384
385 // Troposphere
386 // -----------
387 if (OPT->estTrp()) {
388 required.push_back(new t_pppParam(t_pppParam::trp, t_prn(), t_lc::dummy));
389 }
390
391 // Ionosphere
392 // ----------
393 if (OPT->_obsModelType == OPT->UncombPPP ||
394 OPT->_obsModelType == OPT->DCMcodeBias ||
395 OPT->_obsModelType == OPT->DCMphaseBias ) {
396 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
397 const t_pppSatObs* satObs = obsVector[jj];
398 required.push_back(new t_pppParam(t_pppParam::ion, satObs->prn(), t_lc::dummy));
399 }
400 }
401
402 // Ambiguities
403 // -----------
404 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
405 const t_pppSatObs* satObs = obsVector[jj];
406 if ((OPT->_obsModelType == OPT->IF) ||
407 (OPT->_obsModelType == OPT->PPPRTK) ||
408 (OPT->_obsModelType == OPT->UncombPPP) ||
409 (OPT->_obsModelType == OPT->DCMcodeBias && !satObs->isReference()) ||
410 (OPT->_obsModelType == OPT->DCMphaseBias && !satObs->isReference()) ) {
411 const vector<t_lc::type>& ambLCs = OPT->ambLCs(satObs->prn().system());
412 for (unsigned ii = 0; ii < ambLCs.size(); ii++) {
413 required.push_back(new t_pppParam(t_pppParam::amb, satObs->prn(), ambLCs[ii], &obsVector));
414 }
415 }
416 }
417
418 // Receiver Code Biases
419 // --------------------
420 if (OPT->_obsModelType == OPT->DCMcodeBias) {
421 required.push_back(new t_pppParam(t_pppParam::cBias1, t_prn(), t_lc::c1));
422 required.push_back(new t_pppParam(t_pppParam::cBias2, t_prn(), t_lc::c2));
423 }
424
425 // Receiver Phase Biases
426 // ---------------------
427 if ((OPT->_obsModelType == OPT->DCMphaseBias) ||
428 (OPT->_obsModelType == OPT->PPPRTK) ) {
429 required.push_back(new t_pppParam(t_pppParam::pBias1, t_prn(), t_lc::l1));
430 required.push_back(new t_pppParam(t_pppParam::pBias2, t_prn(), t_lc::l2));
431 }
432
433 // Check if all required parameters are present
434 // --------------------------------------------
435 for (unsigned ii = 0; ii < required.size(); ii++) {
436 t_pppParam* parReq = required[ii];
437
438 bool found = false;
439 for (unsigned jj = 0; jj < _params.size(); jj++) {
440 t_pppParam* parOld = _params[jj];
441 if (parOld->isEqual(parReq)) {
442 found = true;
443 break;
444 }
445 }
446 if (found) {
447 delete parReq;
448 }
449 else {
450 _params.push_back(parReq);
451 }
452 }
453
454 // Set Parameter Indices
455 // ---------------------
456 sort(_params.begin(), _params.end(), t_pppParam::sortFunction);
457
458 for (unsigned ii = 0; ii < _params.size(); ii++) {
459 t_pppParam* par = _params[ii];
460 par->setIndex(ii);
461 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
462 const t_pppSatObs* satObs = obsVector[jj];
463 if (satObs->prn() == par->prn()) {
464 par->setAmbEleSat(satObs->eleSat());
465 par->stepAmbNumEpo();
466 }
467 }
468 }
469
470 return success;
471}
472
473//
474////////////////////////////////////////////////////////////////////////////
475void t_pppParlist::printResult(const bncTime& epoTime, const SymmetricMatrix& QQ,
476 const ColumnVector& xx) const {
477
478 string epoTimeStr = string(epoTime);
479 const t_pppStation* sta = PPP_CLIENT->staRover();
480
481 LOG << endl;
482
483 t_pppParam* parX = 0;
484 t_pppParam* parY = 0;
485 t_pppParam* parZ = 0;
486 for (unsigned ii = 0; ii < _params.size(); ii++) {
487 t_pppParam* par = _params[ii];
488 if (par->type() == t_pppParam::crdX) {
489 parX = par;
490 }
491 else if (par->type() == t_pppParam::crdY) {
492 parY = par;
493 }
494 else if (par->type() == t_pppParam::crdZ) {
495 parZ = par;
496 }
497 else {
498 int ind = par->indexNew();
499 double apr = (par->type() == t_pppParam::trp) ?
500 t_tropo::delay_saast(sta->xyzApr(), M_PI/2.0) : par->x0();
501 LOG << epoTimeStr << ' ' << par->toString() << ' '
502 << setw(10) << setprecision(4) << apr << ' '
503 << showpos << setw(10) << setprecision(4) << xx[ind] << noshowpos << " +- "
504 << setw(8) << setprecision(4) << sqrt(QQ[ind][ind]);
505 if (par->type() == t_pppParam::amb) {
506 LOG << " el = " << setw(6) << setprecision(2) << par->ambEleSat() * 180.0 / M_PI
507 << " epo = " << setw(4) << par->ambNumEpo();
508 }
509 LOG << endl;
510 }
511 }
512
513 if (parX && parY && parZ) {
514
515 ColumnVector xyz(3);
516 xyz[0] = xx[parX->indexNew()];
517 xyz[1] = xx[parY->indexNew()];
518 xyz[2] = xx[parZ->indexNew()];
519
520 ColumnVector neu(3);
521 xyz2neu(sta->ellApr().data(), xyz.data(), neu.data());
522
523 SymmetricMatrix QQxyz = QQ.SymSubMatrix(1,3);
524
525 SymmetricMatrix QQneu(3);
526 covariXYZ_NEU(QQxyz, sta->ellApr().data(), QQneu);
527
528 LOG << epoTimeStr << ' ' << sta->name()
529 << " X = " << setprecision(4) << sta->xyzApr()[0] + xyz[0] << " +- "
530 << setprecision(4) << sqrt(QQxyz[0][0])
531
532 << " Y = " << setprecision(4) << sta->xyzApr()[1] + xyz[1] << " +- "
533 << setprecision(4) << sqrt(QQxyz[1][1])
534
535 << " Z = " << setprecision(4) << sta->xyzApr()[2] + xyz[2] << " +- "
536 << setprecision(4) << sqrt(QQxyz[2][2])
537
538 << " dN = " << setprecision(4) << neu[0] << " +- "
539 << setprecision(4) << sqrt(QQneu[0][0])
540
541 << " dE = " << setprecision(4) << neu[1] << " +- "
542 << setprecision(4) << sqrt(QQneu[1][1])
543
544 << " dU = " << setprecision(4) << neu[2] << " +- "
545 << setprecision(4) << sqrt(QQneu[2][2])
546
547 << endl;
548 }
549}
550
Note: See TracBrowser for help on using the repository browser.