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

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