source: ntrip/trunk/BNC/src/PPP/pppSatObs.cpp@ 8718

Last change on this file since 8718 was 8619, checked in by stuerze, 6 years ago

special ssr wind up computation is added

  • 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.8 KB
Line 
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 *
13 * Changes:
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
55//
56////////////////////////////////////////////////////////////////////////////
57void t_pppSatObs::prepareObs(const t_satObs& pppSatObs) {
58
59 _model.reset();
60
61 // Select pseudoranges and phase observations
62 // ------------------------------------------
63 const string preferredAttrib = "CWPXI_";
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";
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];
73 if (obs->_rnxType2ch == obsType &&
74 obs->_codeValid && obs->_code &&
75 obs->_phaseValid && obs->_phase) {
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 // -----------------------------------------------------
109 _xcSat.ReSize(6); _xcSat = 0.0;
110 _vvSat.ReSize(3); _vvSat = 0.0;
111 bool totOK = false;
112 ColumnVector satPosOld(6); satPosOld = 0.0;
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 }
127 satPosOld = _xcSat;
128 }
129 if (totOK) {
130 _signalPropagationTime = prange / t_CST::c - _xcSat[3];
131 _model._satClkM = _xcSat[3] * t_CST::c;
132 }
133 else {
134 _valid = false;
135 }
136}
137
138//
139////////////////////////////////////////////////////////////////////////////
140void t_pppSatObs::lcCoeff(t_lc::type tLC,
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:
152 phaseCoeff[_fType1] = 1.0;
153 return;
154 case t_lc::l2:
155 phaseCoeff[_fType2] = 1.0;
156 return;
157 case t_lc::lIF:
158 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
159 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
160 return;
161 case t_lc::MW:
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;
167 case t_lc::CL:
168 phaseCoeff[_fType1] = 0.5;
169 codeCoeff[_fType1] = 0.5;
170 return;
171 case t_lc::c1:
172 codeCoeff[_fType1] = 1.0;
173 return;
174 case t_lc::c2:
175 codeCoeff[_fType2] = 1.0;
176 return;
177 case t_lc::cIF:
178 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
179 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
180 return;
181 case t_lc::dummy:
182 case t_lc::maxLc:
183 return;
184 }
185}
186
187//
188////////////////////////////////////////////////////////////////////////////
189bool t_pppSatObs::isValid(t_lc::type tLC) const {
190 bool valid = true;
191 obsValue(tLC, &valid);
192 return valid;
193}
194//
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
230//
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
256//
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
274 retVal = sqrt(retVal);
275
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
295//
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
317//
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);
328 ColumnVector rhoV = rSat - station->xyzApr();
329 _model._rho = rhoV.norm_Frobenius();
330
331 ColumnVector vSat = _vvSat;
332
333 ColumnVector neu(3);
334 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
335
336 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
337 if (neu[2] < 0) {
338 _model._eleSat *= -1.0;
339 }
340 _model._azSat = atan2(neu[1], neu[0]);
341
342 // Satellite Clocks
343 // ----------------
344 _model._satClkM = _xcSat[3] * t_CST::c;
345
346 // Receiver Clocks
347 // ---------------
348 _model._recClkM = station->dClk() * t_CST::c;
349
350 // Sagnac Effect (correction due to Earth rotation)
351 // ------------------------------------------------
352 ColumnVector Omega(3);
353 Omega[0] = 0.0;
354 Omega[1] = 0.0;
355 Omega[2] = t_CST::omega / t_CST::c;
356 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
357
358 // Antenna Eccentricity
359 // --------------------
360 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
361
362 // Antenna Phase Center Offsets and Variations
363 // -------------------------------------------
364 if (PPP_CLIENT->antex()) {
365 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
366 t_frequency::type frqType = static_cast<t_frequency::type>(ii);
367 bool found;
368 _model._antPCO[ii] = PPP_CLIENT->antex()->rcvCorr(station->antName(), frqType,
369 _model._eleSat, _model._azSat, found);
370 }
371 }
372
373 // Tropospheric Delay
374 // ------------------
375 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
376
377 // Code Biases
378 // -----------
379 const t_satCodeBias* satCodeBias = PPP_CLIENT->obsPool()->satCodeBias(_prn);
380 if (satCodeBias) {
381 for (unsigned ii = 0; ii < satCodeBias->_bias.size(); ii++) {
382 const t_frqCodeBias& bias = satCodeBias->_bias[ii];
383 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
384 const t_frqObs* obs = _obs[iFreq];
385 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
386 _model._codeBias[iFreq] = bias._value;
387 }
388 }
389 }
390 }
391
392 // Phase Biases
393 // -----------
394 // TODO: consideration of fix indicators and jump counter
395 const t_satPhaseBias* satPhaseBias = PPP_CLIENT->obsPool()->satPhaseBias(_prn);
396 double yaw = 0.0;
397 bool ssr = false;
398 if (satPhaseBias) {
399 yaw = satPhaseBias->_yaw;
400 ssr = true;
401 for (unsigned ii = 0; ii < satPhaseBias->_bias.size(); ii++) {
402 const t_frqPhaseBias& bias = satPhaseBias->_bias[ii];
403 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
404 const t_frqObs* obs = _obs[iFreq];
405 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
406 _model._phaseBias[iFreq] = bias._value;
407 }
408 }
409 }
410 }
411
412 // Phase Wind-Up
413 // -------------
414 _model._windUp = station->windUp(_time, _prn, rSat, ssr, yaw, vSat) ;
415
416
417 // Tidal Correction
418 // ----------------
419 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
420
421 // Ionospheric Delay
422 // -----------------
423 const t_vTec* vTec = PPP_CLIENT->obsPool()->vTec();
424 bool vTecUsage = true;
425 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
426 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
427 if (tLC == t_lc::cIF || tLC == t_lc::lIF) {
428 vTecUsage = false;
429 }
430 }
431 if (vTecUsage && vTec) {
432 double stec = station->stec(vTec, _signalPropagationTime, rSat);
433 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
434 t_frequency::type frqType = static_cast<t_frequency::type>(iFreq);
435 _model._ionoCodeDelay[iFreq] = 40.3E16 / pow(t_CST::freq(frqType, _channel), 2) * stec;
436 }
437 }
438
439 // Relativistic effect due to earth gravity
440 // ----------------------------------------
441 // TODO
442
443 // Ocean Loading
444 // -------------
445 // TODO
446
447 // Set Model Set Flag
448 // ------------------
449 _model._set = true;
450
451 //printModel();
452
453 return success;
454}
455
456//
457////////////////////////////////////////////////////////////////////////////
458void t_pppSatObs::printModel() const {
459
460 LOG.setf(ios::fixed);
461 LOG << "MODEL for Satellite " << _prn.toString() << endl
462 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
463 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
464 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
465 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
466 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
467 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
468 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
469 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
470 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
471 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
472 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
473 if (_obs[iFreq]) {
474 string frqStr = t_frequency::toString(t_frequency::type(iFreq));
475 if (_prn.system() == frqStr[0]) {
476 LOG << "PCO : " << frqStr << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
477 << "BIAS CODE : " << frqStr << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
478 << "BIAS PHASE : " << frqStr << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl
479 << "IONO CODEDELAY: " << frqStr << setw(12) << setprecision(3) << _model._ionoCodeDelay[iFreq] << endl;
480 }
481 }
482 }
483 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
484 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
485 LOG << "OBS-CMP " << t_lc::toString(tLC) << ": " << _prn.toString() << " "
486 << setw(12) << setprecision(3) << obsValue(tLC) << " "
487 << setw(12) << setprecision(3) << cmpValue(tLC) << " "
488 << setw(12) << setprecision(3) << obsValue(tLC) - cmpValue(tLC) << endl;
489
490 }
491 LOG << "OBS-CMP MW: " << _prn.toString() << " "
492 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
493 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
494 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
495}
496
497//
498////////////////////////////////////////////////////////////////////////////
499double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
500 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
501}
502
503//
504////////////////////////////////////////////////////////////////////////////
505double t_pppSatObs::cmpValue(t_lc::type tLC) const {
506
507 if (!isValid(tLC)) {
508 return 0.0;
509 }
510
511 // Non-Dispersive Part
512 // -------------------
513 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
514 + _model._sagnac + _model._antEcc + _model._tropo
515 + _model._tide;
516
517 // Add Dispersive Part
518 // -------------------
519 map<t_frequency::type, double> codeCoeff;
520 map<t_frequency::type, double> phaseCoeff;
521 lcCoeff(tLC, codeCoeff, phaseCoeff);
522
523 double dispPart = 0.0;
524
525 map<t_frequency::type, double>::const_iterator it;
526 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
527 t_frequency::type tFreq = it->first;
528 dispPart += it->second * (_model._antPCO[tFreq] - _model._codeBias[tFreq] +
529 _model._ionoCodeDelay[tFreq]);
530 }
531 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
532 t_frequency::type tFreq = it->first;
533 dispPart += it->second * (_model._antPCO[tFreq] - _model._phaseBias[tFreq] +
534 _model._windUp * t_CST::lambda(tFreq, _channel) -
535 _model._ionoCodeDelay[tFreq]);
536 }
537
538 return nonDisp + dispPart;
539}
540
541//
542////////////////////////////////////////////////////////////////////////////
543void t_pppSatObs::setRes(t_lc::type tLC, double res) {
544 _res[tLC] = res;
545}
546
547//
548////////////////////////////////////////////////////////////////////////////
549double t_pppSatObs::getRes(t_lc::type tLC) const {
550 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
551 if (it != _res.end()) {
552 return it->second;
553 }
554 else {
555 return 0.0;
556 }
557}
Note: See TracBrowser for help on using the repository browser.