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

Last change on this file since 7169 was 6998, checked in by stuerze, 9 years ago

some superfluous lines deleted

File size: 15.1 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 = "CWPX_";
64
65 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
66 string frqNum = t_frequency::toString(t_frequency::type(iFreq)).substr(1);
67 for (unsigned iPref = 0; iPref < preferredAttrib.length(); iPref++) {
68 string obsType = (preferredAttrib[iPref] == '_') ? frqNum : frqNum + preferredAttrib[iPref];
69 if (_obs[iFreq] == 0) {
70 for (unsigned ii = 0; ii < pppSatObs._obs.size(); ii++) {
71 const t_frqObs* obs = pppSatObs._obs[ii];
72 if (obs->_rnxType2ch == obsType && obs->_codeValid && obs->_phaseValid) {
73 _obs[iFreq] = new t_frqObs(*obs);
74 }
75 }
76 }
77 }
78 }
79
80 // Used frequency types
81 // --------------------
82 _fType1 = t_lc::toFreq(_prn.system(),t_lc::l1);
83 _fType2 = t_lc::toFreq(_prn.system(),t_lc::l2);
84
85 // Check whether all required frequencies available
86 // ------------------------------------------------
87 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
88 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
89 if (!isValid(tLC)) {
90 _valid = false;
91 return;
92 }
93 }
94
95 // Find Glonass Channel Number
96 // ---------------------------
97 if (_prn.system() == 'R') {
98 _channel = PPP_CLIENT->ephPool()->getChannel(_prn);
99 }
100 else {
101 _channel = 0;
102 }
103
104 // Compute Satellite Coordinates at Time of Transmission
105 // -----------------------------------------------------
106 _xcSat.ReSize(4); _xcSat = 0.0;
107 _vvSat.ReSize(4); _vvSat = 0.0;
108 bool totOK = false;
109 ColumnVector satPosOld(4); satPosOld = 0.0;
110 t_lc::type tLC = isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
111 double prange = obsValue(tLC);
112 for (int ii = 1; ii <= 10; ii++) {
113 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
114 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
115 _valid = false;
116 return;
117 }
118 ColumnVector dx = _xcSat - satPosOld;
119 dx[3] *= t_CST::c;
120 if (dx.norm_Frobenius() < 1.e-4) {
121 totOK = true;
122 break;
123 }
124 satPosOld = _xcSat;
125 }
126 if (totOK) {
127 _model._satClkM = _xcSat[3] * t_CST::c;
128 }
129 else {
130 _valid = false;
131 }
132}
133
134//
135////////////////////////////////////////////////////////////////////////////
136void t_pppSatObs::lcCoeff(t_lc::type tLC,
137 map<t_frequency::type, double>& codeCoeff,
138 map<t_frequency::type, double>& phaseCoeff) const {
139
140 codeCoeff.clear();
141 phaseCoeff.clear();
142
143 double f1 = t_CST::freq(_fType1, _channel);
144 double f2 = t_CST::freq(_fType2, _channel);
145
146 switch (tLC) {
147 case t_lc::l1:
148 phaseCoeff[_fType1] = 1.0;
149 return;
150 case t_lc::l2:
151 phaseCoeff[_fType2] = 1.0;
152 return;
153 case t_lc::lIF:
154 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
155 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
156 return;
157 case t_lc::MW:
158 phaseCoeff[_fType1] = f1 / (f1 - f2);
159 phaseCoeff[_fType2] = -f2 / (f1 - f2);
160 codeCoeff[_fType1] = -f1 / (f1 + f2);
161 codeCoeff[_fType2] = -f2 / (f1 + f2);
162 return;
163 case t_lc::CL:
164 phaseCoeff[_fType1] = 0.5;
165 codeCoeff[_fType1] = 0.5;
166 return;
167 case t_lc::c1:
168 codeCoeff[_fType1] = 1.0;
169 return;
170 case t_lc::c2:
171 codeCoeff[_fType2] = 1.0;
172 return;
173 case t_lc::cIF:
174 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
175 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
176 return;
177 case t_lc::dummy:
178 case t_lc::maxLc:
179 return;
180 }
181}
182
183//
184////////////////////////////////////////////////////////////////////////////
185bool t_pppSatObs::isValid(t_lc::type tLC) const {
186 bool valid = true;
187 obsValue(tLC, &valid);
188 return valid;
189}
190//
191////////////////////////////////////////////////////////////////////////////
192double t_pppSatObs::obsValue(t_lc::type tLC, bool* valid) const {
193
194 map<t_frequency::type, double> codeCoeff;
195 map<t_frequency::type, double> phaseCoeff;
196 lcCoeff(tLC, codeCoeff, phaseCoeff);
197
198 double retVal = 0.0;
199 if (valid) *valid = true;
200
201 map<t_frequency::type, double>::const_iterator it;
202 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
203 t_frequency::type tFreq = it->first;
204 if (_obs[tFreq] == 0) {
205 if (valid) *valid = false;
206 return 0.0;
207 }
208 else {
209 retVal += it->second * _obs[tFreq]->_code;
210 }
211 }
212 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
213 t_frequency::type tFreq = it->first;
214 if (_obs[tFreq] == 0) {
215 if (valid) *valid = false;
216 return 0.0;
217 }
218 else {
219 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
220 }
221 }
222
223 return retVal;
224}
225
226//
227////////////////////////////////////////////////////////////////////////////
228double t_pppSatObs::lambda(t_lc::type tLC) const {
229
230 double f1 = t_CST::freq(_fType1, _channel);
231 double f2 = t_CST::freq(_fType2, _channel);
232
233 if (tLC == t_lc::l1) {
234 return t_CST::c / f1;
235 }
236 else if (tLC == t_lc::l2) {
237 return t_CST::c / f2;
238 }
239 else if (tLC == t_lc::lIF) {
240 return t_CST::c / (f1 + f2);
241 }
242 else if (tLC == t_lc::MW) {
243 return t_CST::c / (f1 - f2);
244 }
245 else if (tLC == t_lc::CL) {
246 return t_CST::c / f1 / 2.0;
247 }
248
249 return 0.0;
250}
251
252//
253////////////////////////////////////////////////////////////////////////////
254double t_pppSatObs::sigma(t_lc::type tLC) const {
255
256 map<t_frequency::type, double> codeCoeff;
257 map<t_frequency::type, double> phaseCoeff;
258 lcCoeff(tLC, codeCoeff, phaseCoeff);
259
260 double retVal = 0.0;
261
262 map<t_frequency::type, double>::const_iterator it;
263 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
264 retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
265 }
266 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
267 retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
268 }
269
270 retVal = sqrt(retVal);
271
272 // De-Weight GLONASS
273 // -----------------
274 if (_prn.system() == 'R') {
275 retVal *= 5.0;
276 }
277
278 // Elevation-Dependent Weighting
279 // -----------------------------
280 double cEle = 1.0;
281 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
282 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
283 double eleD = eleSat()*180.0/M_PI;
284 double hlp = fabs(90.0 - eleD);
285 cEle = (1.0 + hlp*hlp*hlp*0.000004);
286 }
287
288 return cEle * retVal;
289}
290
291//
292////////////////////////////////////////////////////////////////////////////
293double t_pppSatObs::maxRes(t_lc::type tLC) const {
294
295 map<t_frequency::type, double> codeCoeff;
296 map<t_frequency::type, double> phaseCoeff;
297 lcCoeff(tLC, codeCoeff, phaseCoeff);
298
299 double retVal = 0.0;
300
301 map<t_frequency::type, double>::const_iterator it;
302 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
303 retVal += it->second * it->second * OPT->_maxResC1 * OPT->_maxResC1;
304 }
305 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
306 retVal += it->second * it->second * OPT->_maxResL1 * OPT->_maxResL1;
307 }
308
309 return sqrt(retVal);
310}
311
312
313//
314////////////////////////////////////////////////////////////////////////////
315t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
316
317 // Reset all model values
318 // ----------------------
319 _model.reset();
320
321 // Topocentric Satellite Position
322 // ------------------------------
323 ColumnVector rSat = _xcSat.Rows(1,3);
324 ColumnVector rhoV = rSat - station->xyzApr();
325 _model._rho = rhoV.norm_Frobenius();
326
327 ColumnVector neu(3);
328 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
329
330 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
331 if (neu[2] < 0) {
332 _model._eleSat *= -1.0;
333 }
334 _model._azSat = atan2(neu[1], neu[0]);
335
336 // Satellite Clocks
337 // ----------------
338 _model._satClkM = _xcSat[3] * t_CST::c;
339
340 // Receiver Clocks
341 // ---------------
342 _model._recClkM = station->dClk() * t_CST::c;
343
344 // Sagnac Effect (correction due to Earth rotation)
345 // ------------------------------------------------
346 ColumnVector Omega(3);
347 Omega[0] = 0.0;
348 Omega[1] = 0.0;
349 Omega[2] = t_CST::omega / t_CST::c;
350 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
351
352 // Antenna Eccentricity
353 // --------------------
354 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
355
356 // Antenna Phase Center Offsets and Variations
357 // -------------------------------------------
358 if (PPP_CLIENT->antex()) {
359 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
360 t_frequency::type frqType = static_cast<t_frequency::type>(ii);
361 bool found;
362 _model._antPCO[ii] = PPP_CLIENT->antex()->rcvCorr(station->antName(), frqType,
363 _model._eleSat, _model._azSat, found);
364 }
365 }
366
367 // Tropospheric Delay
368 // ------------------
369 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
370
371 // Phase Wind-Up
372 // -------------
373 _model._windUp = station->windUp(_time, _prn, rSat);
374
375 // Code Biases
376 // -----------
377 const t_satCodeBias* satCodeBias = PPP_CLIENT->obsPool()->satCodeBias(_prn);
378 if (satCodeBias) {
379 for (unsigned ii = 0; ii < satCodeBias->_bias.size(); ii++) {
380 const t_frqCodeBias& bias = satCodeBias->_bias[ii];
381 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
382 const t_frqObs* obs = _obs[iFreq];
383 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
384 _model._codeBias[iFreq] = bias._value;
385 }
386 }
387 }
388 }
389
390 // Tidal Correction
391 // ----------------
392 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
393
394 // Ionospheric Delay
395 // -----------------
396 // TODO
397
398 // Ocean Loading
399 // -------------
400 // TODO
401
402 // Set Model Set Flag
403 // ------------------
404 _model._set = true;
405
406 return success;
407}
408
409//
410////////////////////////////////////////////////////////////////////////////
411void t_pppSatObs::printModel() const {
412 LOG.setf(ios::fixed);
413 LOG << "MODEL for Satellite " << _prn.toString() << endl
414 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
415 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
416 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
417 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
418 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
419 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
420 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
421 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
422 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
423 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
424 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
425 if (_obs[iFreq]) {
426 LOG << "PCO: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
427 << "BIAS CODE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
428 << "BIAS PHASE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl;
429 }
430 }
431 LOG << "OBS-CMP P3: " << _prn.toString() << " "
432 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
433 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
434 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
435
436 LOG << "OBS-CMP L3: " << _prn.toString() << " "
437 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
438 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
439 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
440
441 LOG << "OBS-CMP MW: " << _prn.toString() << " "
442 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
443 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
444 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
445}
446
447//
448////////////////////////////////////////////////////////////////////////////
449double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
450 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
451}
452
453//
454////////////////////////////////////////////////////////////////////////////
455double t_pppSatObs::cmpValue(t_lc::type tLC) const {
456
457 if (!isValid(tLC)) {
458 return 0.0;
459 }
460
461 // Non-Dispersive Part
462 // -------------------
463 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
464 + _model._sagnac + _model._antEcc + _model._tropo
465 + _model._tide;
466
467 // Add Dispersive Part
468 // -------------------
469 map<t_frequency::type, double> codeCoeff;
470 map<t_frequency::type, double> phaseCoeff;
471 lcCoeff(tLC, codeCoeff, phaseCoeff);
472
473 double dispPart = 0.0;
474
475 map<t_frequency::type, double>::const_iterator it;
476 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
477 t_frequency::type tFreq = it->first;
478 dispPart += it->second * (_model._antPCO[tFreq] + _model._codeBias[tFreq]);
479 }
480 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
481 t_frequency::type tFreq = it->first;
482 dispPart += it->second * (_model._antPCO[tFreq] + _model._phaseBias[tFreq] +
483 _model._windUp * t_CST::lambda(tFreq, _channel));
484 }
485
486 return nonDisp + dispPart;
487}
488
489//
490////////////////////////////////////////////////////////////////////////////
491void t_pppSatObs::setRes(t_lc::type tLC, double res) {
492 _res[tLC] = res;
493}
494
495//
496////////////////////////////////////////////////////////////////////////////
497double t_pppSatObs::getRes(t_lc::type tLC) const {
498 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
499 if (it != _res.end()) {
500 return it->second;
501 }
502 else {
503 return 0.0;
504 }
505}
Note: See TracBrowser for help on using the repository browser.