source: ntrip/branches/BNC_2.12/src/PPP/pppSatObs.cpp@ 8541

Last change on this file since 8541 was 8541, checked in by stuerze, 5 years ago

minor changes to consider a satellite clock drift that is introduced via RTNET format

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 16.6 KB
RevLine 
[7237]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppSatObs
6 *
7 * Purpose: Satellite observations
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
[7288]13 * Changes:
[7237]14 *
15 * -----------------------------------------------------------------------*/
16
17
18#include <iostream>
19#include <cmath>
20#include <newmatio.h>
21
22#include "pppSatObs.h"
23#include "bncconst.h"
24#include "pppEphPool.h"
25#include "pppStation.h"
26#include "bncutils.h"
27#include "bncantex.h"
28#include "pppObsPool.h"
29#include "pppClient.h"
30
31using namespace BNC_PPP;
32using namespace std;
33
34// Constructor
35////////////////////////////////////////////////////////////////////////////
36t_pppSatObs::t_pppSatObs(const t_satObs& pppSatObs) {
37 _prn = pppSatObs._prn;
38 _time = pppSatObs._time;
39 _outlier = false;
40 _valid = true;
41 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
42 _obs[ii] = 0;
43 }
44 prepareObs(pppSatObs);
45}
46
47// Destructor
48////////////////////////////////////////////////////////////////////////////
49t_pppSatObs::~t_pppSatObs() {
50 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
51 delete _obs[iFreq];
52 }
53}
54
[7288]55//
[7237]56////////////////////////////////////////////////////////////////////////////
57void t_pppSatObs::prepareObs(const t_satObs& pppSatObs) {
58
59 _model.reset();
60
61 // Select pseudoranges and phase observations
62 // ------------------------------------------
[7253]63 const string preferredAttrib = "CWPXI_";
[8541]64 //const string preferredAttrib = "G:12&PWCSLXYN G:5&IQX R:12&PC R:3&IQX E:16&BCX E:578&IQX J:1&SLXCZ J:26&SLX J:5&IQX C:IQX I:ABCX S:1&C S:5&IQX";
[7237]65
66 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
67 string frqNum = t_frequency::toString(t_frequency::type(iFreq)).substr(1);
68 for (unsigned iPref = 0; iPref < preferredAttrib.length(); iPref++) {
69 string obsType = (preferredAttrib[iPref] == '_') ? frqNum : frqNum + preferredAttrib[iPref];
70 if (_obs[iFreq] == 0) {
71 for (unsigned ii = 0; ii < pppSatObs._obs.size(); ii++) {
72 const t_frqObs* obs = pppSatObs._obs[ii];
[8027]73 if (obs->_rnxType2ch == obsType &&
74 obs->_codeValid && obs->_code &&
75 obs->_phaseValid && obs->_phase) {
[7237]76 _obs[iFreq] = new t_frqObs(*obs);
77 }
78 }
79 }
80 }
81 }
82
83 // Used frequency types
84 // --------------------
85 _fType1 = t_lc::toFreq(_prn.system(),t_lc::l1);
86 _fType2 = t_lc::toFreq(_prn.system(),t_lc::l2);
87
88 // Check whether all required frequencies available
89 // ------------------------------------------------
90 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
91 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
92 if (!isValid(tLC)) {
93 _valid = false;
94 return;
95 }
96 }
97
98 // Find Glonass Channel Number
99 // ---------------------------
100 if (_prn.system() == 'R') {
101 _channel = PPP_CLIENT->ephPool()->getChannel(_prn);
102 }
103 else {
104 _channel = 0;
105 }
106
107 // Compute Satellite Coordinates at Time of Transmission
108 // -----------------------------------------------------
[8541]109 _xcSat.ReSize(6); _xcSat = 0.0;
[8496]110 _vvSat.ReSize(3); _vvSat = 0.0;
[7237]111 bool totOK = false;
[8541]112 ColumnVector satPosOld(6); satPosOld = 0.0;
[7237]113 t_lc::type tLC = isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
114 double prange = obsValue(tLC);
115 for (int ii = 1; ii <= 10; ii++) {
116 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
117 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
118 _valid = false;
119 return;
120 }
121 ColumnVector dx = _xcSat - satPosOld;
122 dx[3] *= t_CST::c;
123 if (dx.norm_Frobenius() < 1.e-4) {
124 totOK = true;
125 break;
126 }
[7288]127 satPosOld = _xcSat;
[7237]128 }
129 if (totOK) {
[7250]130 _signalPropagationTime = prange / t_CST::c - _xcSat[3];
[7288]131 _model._satClkM = _xcSat[3] * t_CST::c;
[7237]132 }
133 else {
134 _valid = false;
135 }
136}
137
[7288]138//
[7237]139////////////////////////////////////////////////////////////////////////////
[7288]140void t_pppSatObs::lcCoeff(t_lc::type tLC,
[7237]141 map<t_frequency::type, double>& codeCoeff,
142 map<t_frequency::type, double>& phaseCoeff) const {
143
144 codeCoeff.clear();
145 phaseCoeff.clear();
146
147 double f1 = t_CST::freq(_fType1, _channel);
148 double f2 = t_CST::freq(_fType2, _channel);
149
150 switch (tLC) {
151 case t_lc::l1:
[7288]152 phaseCoeff[_fType1] = 1.0;
[7237]153 return;
[7288]154 case t_lc::l2:
155 phaseCoeff[_fType2] = 1.0;
[7237]156 return;
[7288]157 case t_lc::lIF:
[7237]158 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
159 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
160 return;
[7288]161 case t_lc::MW:
[7237]162 phaseCoeff[_fType1] = f1 / (f1 - f2);
163 phaseCoeff[_fType2] = -f2 / (f1 - f2);
164 codeCoeff[_fType1] = -f1 / (f1 + f2);
165 codeCoeff[_fType2] = -f2 / (f1 + f2);
166 return;
[7288]167 case t_lc::CL:
[7237]168 phaseCoeff[_fType1] = 0.5;
169 codeCoeff[_fType1] = 0.5;
170 return;
[7288]171 case t_lc::c1:
172 codeCoeff[_fType1] = 1.0;
[7237]173 return;
[7288]174 case t_lc::c2:
175 codeCoeff[_fType2] = 1.0;
[7237]176 return;
[7288]177 case t_lc::cIF:
[7237]178 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
179 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
180 return;
[7288]181 case t_lc::dummy:
182 case t_lc::maxLc:
[7237]183 return;
184 }
185}
186
[7288]187//
[7237]188////////////////////////////////////////////////////////////////////////////
189bool t_pppSatObs::isValid(t_lc::type tLC) const {
190 bool valid = true;
191 obsValue(tLC, &valid);
192 return valid;
193}
[7288]194//
[7237]195////////////////////////////////////////////////////////////////////////////
196double t_pppSatObs::obsValue(t_lc::type tLC, bool* valid) const {
197
198 map<t_frequency::type, double> codeCoeff;
199 map<t_frequency::type, double> phaseCoeff;
200 lcCoeff(tLC, codeCoeff, phaseCoeff);
201
202 double retVal = 0.0;
203 if (valid) *valid = true;
204
205 map<t_frequency::type, double>::const_iterator it;
206 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
207 t_frequency::type tFreq = it->first;
208 if (_obs[tFreq] == 0) {
209 if (valid) *valid = false;
210 return 0.0;
211 }
212 else {
213 retVal += it->second * _obs[tFreq]->_code;
214 }
215 }
216 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
217 t_frequency::type tFreq = it->first;
218 if (_obs[tFreq] == 0) {
219 if (valid) *valid = false;
220 return 0.0;
221 }
222 else {
223 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
224 }
225 }
226
227 return retVal;
228}
229
[7288]230//
[7237]231////////////////////////////////////////////////////////////////////////////
232double t_pppSatObs::lambda(t_lc::type tLC) const {
233
234 double f1 = t_CST::freq(_fType1, _channel);
235 double f2 = t_CST::freq(_fType2, _channel);
236
237 if (tLC == t_lc::l1) {
238 return t_CST::c / f1;
239 }
240 else if (tLC == t_lc::l2) {
241 return t_CST::c / f2;
242 }
243 else if (tLC == t_lc::lIF) {
244 return t_CST::c / (f1 + f2);
245 }
246 else if (tLC == t_lc::MW) {
247 return t_CST::c / (f1 - f2);
248 }
249 else if (tLC == t_lc::CL) {
250 return t_CST::c / f1 / 2.0;
251 }
252
253 return 0.0;
254}
255
[7288]256//
[7237]257////////////////////////////////////////////////////////////////////////////
258double t_pppSatObs::sigma(t_lc::type tLC) const {
259
260 map<t_frequency::type, double> codeCoeff;
261 map<t_frequency::type, double> phaseCoeff;
262 lcCoeff(tLC, codeCoeff, phaseCoeff);
263
264 double retVal = 0.0;
265
266 map<t_frequency::type, double>::const_iterator it;
267 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
268 retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
269 }
270 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
271 retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
272 }
273
[7288]274 retVal = sqrt(retVal);
275
[7237]276 // De-Weight GLONASS
277 // -----------------
278 if (_prn.system() == 'R') {
279 retVal *= 5.0;
280 }
281
282 // Elevation-Dependent Weighting
283 // -----------------------------
284 double cEle = 1.0;
285 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
286 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
287 double eleD = eleSat()*180.0/M_PI;
288 double hlp = fabs(90.0 - eleD);
289 cEle = (1.0 + hlp*hlp*hlp*0.000004);
290 }
291
292 return cEle * retVal;
293}
294
[7288]295//
[7237]296////////////////////////////////////////////////////////////////////////////
297double t_pppSatObs::maxRes(t_lc::type tLC) const {
298
299 map<t_frequency::type, double> codeCoeff;
300 map<t_frequency::type, double> phaseCoeff;
301 lcCoeff(tLC, codeCoeff, phaseCoeff);
302
303 double retVal = 0.0;
304
305 map<t_frequency::type, double>::const_iterator it;
306 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
307 retVal += it->second * it->second * OPT->_maxResC1 * OPT->_maxResC1;
308 }
309 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
310 retVal += it->second * it->second * OPT->_maxResL1 * OPT->_maxResL1;
311 }
312
313 return sqrt(retVal);
314}
315
316
[7288]317//
[7237]318////////////////////////////////////////////////////////////////////////////
319t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
320
321 // Reset all model values
322 // ----------------------
323 _model.reset();
324
325 // Topocentric Satellite Position
326 // ------------------------------
327 ColumnVector rSat = _xcSat.Rows(1,3);
[7288]328 ColumnVector rhoV = rSat - station->xyzApr();
[7237]329 _model._rho = rhoV.norm_Frobenius();
330
331 ColumnVector neu(3);
332 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
333
334 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
335 if (neu[2] < 0) {
336 _model._eleSat *= -1.0;
337 }
338 _model._azSat = atan2(neu[1], neu[0]);
339
340 // Satellite Clocks
341 // ----------------
342 _model._satClkM = _xcSat[3] * t_CST::c;
343
344 // Receiver Clocks
345 // ---------------
346 _model._recClkM = station->dClk() * t_CST::c;
347
348 // Sagnac Effect (correction due to Earth rotation)
349 // ------------------------------------------------
350 ColumnVector Omega(3);
351 Omega[0] = 0.0;
352 Omega[1] = 0.0;
353 Omega[2] = t_CST::omega / t_CST::c;
354 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
355
356 // Antenna Eccentricity
357 // --------------------
358 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
359
360 // Antenna Phase Center Offsets and Variations
361 // -------------------------------------------
362 if (PPP_CLIENT->antex()) {
363 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
364 t_frequency::type frqType = static_cast<t_frequency::type>(ii);
365 bool found;
[7288]366 _model._antPCO[ii] = PPP_CLIENT->antex()->rcvCorr(station->antName(), frqType,
[7237]367 _model._eleSat, _model._azSat, found);
368 }
369 }
370
371 // Tropospheric Delay
372 // ------------------
373 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
374
375 // Phase Wind-Up
376 // -------------
377 _model._windUp = station->windUp(_time, _prn, rSat);
378
379 // Code Biases
380 // -----------
381 const t_satCodeBias* satCodeBias = PPP_CLIENT->obsPool()->satCodeBias(_prn);
[7288]382 if (satCodeBias) {
[7237]383 for (unsigned ii = 0; ii < satCodeBias->_bias.size(); ii++) {
384 const t_frqCodeBias& bias = satCodeBias->_bias[ii];
385 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
386 const t_frqObs* obs = _obs[iFreq];
387 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
388 _model._codeBias[iFreq] = bias._value;
389 }
390 }
391 }
392 }
393
[7288]394 // Phase Biases
395 // -----------
396 // TODO: consideration of fix indicators, yaw angle and jump counter
397 const t_satPhaseBias* satPhaseBias = PPP_CLIENT->obsPool()->satPhaseBias(_prn);
398 if (satPhaseBias) {
399 for (unsigned ii = 0; ii < satPhaseBias->_bias.size(); ii++) {
400 const t_frqPhaseBias& bias = satPhaseBias->_bias[ii];
401 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
402 const t_frqObs* obs = _obs[iFreq];
403 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
404 _model._phaseBias[iFreq] = bias._value;
405 }
406 }
407 }
408 }
409
[7237]410 // Tidal Correction
411 // ----------------
412 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
413
414 // Ionospheric Delay
415 // -----------------
[7250]416 const t_vTec* vTec = PPP_CLIENT->obsPool()->vTec();
[7253]417 bool vTecUsage = true;
418 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
419 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
420 if (tLC == t_lc::cIF || tLC == t_lc::lIF) {
421 vTecUsage = false;
[7237]422 }
423 }
[7258]424 if (vTecUsage && vTec) {
425 double stec = station->stec(vTec, _signalPropagationTime, rSat);
426 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
427 t_frequency::type frqType = static_cast<t_frequency::type>(iFreq);
428 _model._ionoCodeDelay[iFreq] = 40.3E16 / pow(t_CST::freq(frqType, _channel), 2) * stec;
[7253]429 }
430 }
[7237]431
432 // Ocean Loading
433 // -------------
434 // TODO
435
436 // Set Model Set Flag
437 // ------------------
438 _model._set = true;
439
[7252]440 //printModel();
441
[7237]442 return success;
443}
444
[7288]445//
[7237]446////////////////////////////////////////////////////////////////////////////
447void t_pppSatObs::printModel() const {
[7253]448
[7237]449 LOG.setf(ios::fixed);
450 LOG << "MODEL for Satellite " << _prn.toString() << endl
451 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
452 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
453 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
454 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
455 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
456 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
457 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
458 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
459 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
460 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
461 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
462 if (_obs[iFreq]) {
[7288]463 string frqStr = t_frequency::toString(t_frequency::type(iFreq));
464 if (_prn.system() == frqStr[0]) {
465 LOG << "PCO : " << frqStr << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
466 << "BIAS CODE : " << frqStr << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
467 << "BIAS PHASE : " << frqStr << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl
468 << "IONO CODEDELAY: " << frqStr << setw(12) << setprecision(3) << _model._ionoCodeDelay[iFreq] << endl;
469 }
[7237]470 }
471 }
[7253]472 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
473 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
474 LOG << "OBS-CMP " << t_lc::toString(tLC) << ": " << _prn.toString() << " "
475 << setw(12) << setprecision(3) << obsValue(tLC) << " "
476 << setw(12) << setprecision(3) << cmpValue(tLC) << " "
477 << setw(12) << setprecision(3) << obsValue(tLC) - cmpValue(tLC) << endl;
[7237]478
[7253]479 }
[7288]480 LOG << "OBS-CMP MW: " << _prn.toString() << " "
[7237]481 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
482 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
483 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
484}
485
[7288]486//
[7237]487////////////////////////////////////////////////////////////////////////////
488double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
489 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
490}
491
[7288]492//
[7237]493////////////////////////////////////////////////////////////////////////////
494double t_pppSatObs::cmpValue(t_lc::type tLC) const {
495
496 if (!isValid(tLC)) {
497 return 0.0;
498 }
499
500 // Non-Dispersive Part
501 // -------------------
[7288]502 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
503 + _model._sagnac + _model._antEcc + _model._tropo
[7237]504 + _model._tide;
505
506 // Add Dispersive Part
507 // -------------------
508 map<t_frequency::type, double> codeCoeff;
509 map<t_frequency::type, double> phaseCoeff;
510 lcCoeff(tLC, codeCoeff, phaseCoeff);
511
512 double dispPart = 0.0;
513
514 map<t_frequency::type, double>::const_iterator it;
515 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
516 t_frequency::type tFreq = it->first;
[7262]517 dispPart += it->second * (_model._antPCO[tFreq] - _model._codeBias[tFreq] +
[7252]518 _model._ionoCodeDelay[tFreq]);
[7237]519 }
520 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
521 t_frequency::type tFreq = it->first;
[7262]522 dispPart += it->second * (_model._antPCO[tFreq] - _model._phaseBias[tFreq] +
[7252]523 _model._windUp * t_CST::lambda(tFreq, _channel) -
524 _model._ionoCodeDelay[tFreq]);
[7237]525 }
526
527 return nonDisp + dispPart;
528}
529
[7288]530//
[7237]531////////////////////////////////////////////////////////////////////////////
532void t_pppSatObs::setRes(t_lc::type tLC, double res) {
533 _res[tLC] = res;
534}
535
[7288]536//
[7237]537////////////////////////////////////////////////////////////////////////////
538double t_pppSatObs::getRes(t_lc::type tLC) const {
539 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
540 if (it != _res.end()) {
541 return it->second;
542 }
543 else {
544 return 0.0;
545 }
546}
Note: See TracBrowser for help on using the repository browser.