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

Last change on this file since 8905 was 8905, checked in by stuerze, 2 years ago

some developments regarding PPP, not completed!

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 14.8 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 {//qDebug() << "t_pppParam::partial: " << tLC;
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// qDebug() << "refPrn: " << _refPrn.toString().c_str();
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
300 // Remove some Parameters
301 // ----------------------
302 vector<t_pppParam*>::iterator it = _params.begin();
303 while (it != _params.end()) {
304 t_pppParam* par = *it;
305
306 bool remove = false;
307
308 if (par->epoSpec()) {
309 remove = true;
310 }
311
312 else if (par->type() == t_pppParam::amb ||
313 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
321 if (remove) {
322 delete par;
323 it = _params.erase(it);
324 }
325 else {
326 ++it;
327 }
328 }
329
330 // Check whether parameters have observations
331 // ------------------------------------------
332 for (unsigned ii = 0; ii < _params.size(); ii++) {
333 t_pppParam* par = _params[ii];
334 if (par->prn() == 0) {
335 par->setLastObsTime(epoTime);
336 if (par->firstObsTime().undef()) {
337 par->setFirstObsTime(epoTime);
338 }
339 }
340 else {
341 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
342 const t_pppSatObs* satObs = obsVector[jj];
343 if (satObs->prn() == par->prn()) {
344 par->setLastObsTime(epoTime);
345 if (par->firstObsTime().undef()) {
346 par->setFirstObsTime(epoTime);
347 }
348 break;
349 }
350 }
351 }
352 }
353
354 // Required Set of Parameters
355 // --------------------------
356 vector<t_pppParam*> required;
357
358 // Coordinates
359 // -----------
360 required.push_back(new t_pppParam(t_pppParam::crdX, t_prn(), t_lc::dummy));
361 required.push_back(new t_pppParam(t_pppParam::crdY, t_prn(), t_lc::dummy));
362 required.push_back(new t_pppParam(t_pppParam::crdZ, t_prn(), t_lc::dummy));
363
364 // Receiver Clock
365 // --------------
366 required.push_back(new t_pppParam(t_pppParam::clkR, t_prn(), t_lc::dummy));
367
368 // GPS-GLONASS Clock Offset
369 // ------------------------
370 if (OPT->useSystem('R')) {
371 required.push_back(new t_pppParam(t_pppParam::offGG, t_prn(), t_lc::dummy));
372 }
373
374 // Troposphere
375 // -----------
376 if (OPT->estTrp()) {
377 required.push_back(new t_pppParam(t_pppParam::trp, t_prn(), t_lc::dummy));
378 }
379
380 // Ionosphere
381 // ----------
382 if (OPT->_obsModelType == OPT->UncombPPP ||
383 OPT->_obsModelType == OPT->DCMcodeBias ||
384 OPT->_obsModelType == OPT->DCMphaseBias ) {
385 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
386 const t_pppSatObs* satObs = obsVector[jj];
387 required.push_back(new t_pppParam(t_pppParam::ion, satObs->prn(), t_lc::dummy));
388 }
389 }
390
391 // Ambiguities
392 // -----------
393 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
394 const t_pppSatObs* satObs = obsVector[jj];
395 if ((OPT->_obsModelType == OPT->IF) ||
396 (OPT->_obsModelType == OPT->PPPRTK) ||
397 (OPT->_obsModelType == OPT->UncombPPP) ||
398 (OPT->_obsModelType == OPT->DCMcodeBias && !satObs->isReference()) ||
399 (OPT->_obsModelType == OPT->DCMphaseBias && !satObs->isReference()) ) {
400 const vector<t_lc::type>& ambLCs = OPT->ambLCs(satObs->prn().system());
401 for (unsigned ii = 0; ii < ambLCs.size(); ii++) {
402 required.push_back(new t_pppParam(t_pppParam::amb, satObs->prn(), ambLCs[ii], &obsVector));
403 }
404 }
405 }
406
407 // Receiver Code Biases
408 // --------------------
409 if (OPT->_obsModelType == OPT->DCMcodeBias) {
410 required.push_back(new t_pppParam(t_pppParam::cBias1, t_prn(), t_lc::c1));
411 required.push_back(new t_pppParam(t_pppParam::cBias2, t_prn(), t_lc::c2));
412 }
413
414 // Receiver Phase Biases
415 // ---------------------
416 if ((OPT->_obsModelType == OPT->DCMphaseBias) ||
417 (OPT->_obsModelType == OPT->PPPRTK) ) {
418 required.push_back(new t_pppParam(t_pppParam::pBias1, t_prn(), t_lc::l1));
419 required.push_back(new t_pppParam(t_pppParam::pBias2, t_prn(), t_lc::l2));
420 }
421
422 // Check if all required parameters are present
423 // --------------------------------------------
424 for (unsigned ii = 0; ii < required.size(); ii++) {
425 t_pppParam* parReq = required[ii];
426
427 bool found = false;
428 for (unsigned jj = 0; jj < _params.size(); jj++) {
429 t_pppParam* parOld = _params[jj];
430 if (parOld->isEqual(parReq)) {
431 found = true;
432 break;
433 }
434 }
435 if (found) {
436 delete parReq;
437 }
438 else {
439 _params.push_back(parReq);
440 }
441 }
442
443 // Set Parameter Indices
444 // ---------------------
445 sort(_params.begin(), _params.end(), t_pppParam::sortFunction);
446
447 for (unsigned ii = 0; ii < _params.size(); ii++) {
448 t_pppParam* par = _params[ii];
449 par->setIndex(ii);
450 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
451 const t_pppSatObs* satObs = obsVector[jj];
452 if (satObs->prn() == par->prn()) {
453 par->setAmbEleSat(satObs->eleSat());
454 par->stepAmbNumEpo();
455 }
456 }
457 }
458
459 return success;
460}
461
462//
463////////////////////////////////////////////////////////////////////////////
464void t_pppParlist::printResult(const bncTime& epoTime, const SymmetricMatrix& QQ,
465 const ColumnVector& xx) const {
466
467 string epoTimeStr = string(epoTime);
468 const t_pppStation* sta = PPP_CLIENT->staRover();
469
470 LOG << endl;
471
472 t_pppParam* parX = 0;
473 t_pppParam* parY = 0;
474 t_pppParam* parZ = 0;
475 for (unsigned ii = 0; ii < _params.size(); ii++) {
476 t_pppParam* par = _params[ii];
477 if (par->type() == t_pppParam::crdX) {
478 parX = par;
479 }
480 else if (par->type() == t_pppParam::crdY) {
481 parY = par;
482 }
483 else if (par->type() == t_pppParam::crdZ) {
484 parZ = par;
485 }
486 else {
487 int ind = par->indexNew();
488 double apr = (par->type() == t_pppParam::trp) ?
489 t_tropo::delay_saast(sta->xyzApr(), M_PI/2.0) : par->x0();
490 LOG << epoTimeStr << ' ' << par->toString() << ' '
491 << setw(10) << setprecision(4) << apr << ' '
492 << showpos << setw(10) << setprecision(4) << xx[ind] << noshowpos << " +- "
493 << setw(8) << setprecision(4) << sqrt(QQ[ind][ind]);
494 if (par->type() == t_pppParam::amb) {
495 LOG << " el = " << setw(6) << setprecision(2) << par->ambEleSat() * 180.0 / M_PI
496 << " epo = " << setw(4) << par->ambNumEpo();
497 }
498 LOG << endl;
499 }
500 }
501
502 if (parX && parY && parZ) {
503
504 ColumnVector xyz(3);
505 xyz[0] = xx[parX->indexNew()];
506 xyz[1] = xx[parY->indexNew()];
507 xyz[2] = xx[parZ->indexNew()];
508
509 ColumnVector neu(3);
510 xyz2neu(sta->ellApr().data(), xyz.data(), neu.data());
511
512 SymmetricMatrix QQxyz = QQ.SymSubMatrix(1,3);
513
514 SymmetricMatrix QQneu(3);
515 covariXYZ_NEU(QQxyz, sta->ellApr().data(), QQneu);
516
517 LOG << epoTimeStr << ' ' << sta->name()
518 << " X = " << setprecision(4) << sta->xyzApr()[0] + xyz[0] << " +- "
519 << setprecision(4) << sqrt(QQxyz[0][0])
520
521 << " Y = " << setprecision(4) << sta->xyzApr()[1] + xyz[1] << " +- "
522 << setprecision(4) << sqrt(QQxyz[1][1])
523
524 << " Z = " << setprecision(4) << sta->xyzApr()[2] + xyz[2] << " +- "
525 << setprecision(4) << sqrt(QQxyz[2][2])
526
527 << " dN = " << setprecision(4) << neu[0] << " +- "
528 << setprecision(4) << sqrt(QQneu[0][0])
529
530 << " dE = " << setprecision(4) << neu[1] << " +- "
531 << setprecision(4) << sqrt(QQneu[1][1])
532
533 << " dU = " << setprecision(4) << neu[2] << " +- "
534 << setprecision(4) << sqrt(QQneu[2][2])
535
536 << endl;
537 }
538}
539
Note: See TracBrowser for help on using the repository browser.