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

Last change on this file since 6623 was 6463, checked in by mervart, 10 years ago
File size: 15.2 KB
RevLine 
[5743]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
[5819]5 * Class: t_pppSatObs
[5743]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>
[5822]21
22#include "pppSatObs.h"
[5750]23#include "bncconst.h"
[5810]24#include "pppEphPool.h"
25#include "pppStation.h"
[5750]26#include "bncutils.h"
27#include "bncantex.h"
[5810]28#include "pppObsPool.h"
[5750]29#include "pppClient.h"
[5743]30
[5814]31using namespace BNC_PPP;
[5743]32using namespace std;
33
34// Constructor
35////////////////////////////////////////////////////////////////////////////
[5819]36t_pppSatObs::t_pppSatObs(const t_satObs& pppSatObs) {
[6017]37 _prn = pppSatObs._prn;
38 _time = pppSatObs._time;
39 _outlier = false;
[6023]40 _valid = true;
[6017]41 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
42 _obs[ii] = 0;
[5743]43 }
[6017]44 prepareObs(pppSatObs);
[5743]45}
46
47// Destructor
48////////////////////////////////////////////////////////////////////////////
[5819]49t_pppSatObs::~t_pppSatObs() {
[6017]50 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
51 delete _obs[iFreq];
[5743]52 }
53}
54
55//
56////////////////////////////////////////////////////////////////////////////
[6017]57void t_pppSatObs::prepareObs(const t_satObs& pppSatObs) {
58
[5743]59 _model.reset();
60
[6017]61 // Select pseudoranges and phase observations
62 // ------------------------------------------
[6035]63 const string preferredAttrib = "CWPX_";
[5743]64
[6017]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);
[5830]74 }
[5743]75 }
76 }
77 }
78 }
79
[6026]80 // Used frequency types
81 // --------------------
82 _fType1 = t_lc::toFreq(_prn.system(),t_lc::l1);
[6035]83 if (_prn.system() == 'E') {
84 _fType2 = t_frequency::E5;
85 }
86 else {
87 _fType2 = t_lc::toFreq(_prn.system(),t_lc::l2);
88 }
[6026]89
[6024]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
[5743]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;
[6023]115 t_lc::type tLC = isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
[5743]116 double prange = obsValue(tLC);
117 for (int ii = 1; ii <= 10; ii++) {
[5750]118 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
119 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
[5743]120 _valid = false;
121 return;
122 }
123 ColumnVector dx = _xcSat - satPosOld;
[5750]124 dx[3] *= t_CST::c;
[5743]125 if (dx.norm_Frobenius() < 1.e-4) {
126 totOK = true;
127 break;
128 }
129 satPosOld = _xcSat;
130 }
131 if (totOK) {
[5750]132 _model._satClkM = _xcSat[3] * t_CST::c;
[5743]133 }
134 else {
135 _valid = false;
136 }
137}
138
139//
140////////////////////////////////////////////////////////////////////////////
[6025]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
[6026]148 double f1 = t_CST::freq(_fType1, _channel);
149 double f2 = t_CST::freq(_fType2, _channel);
[6025]150
151 switch (tLC) {
152 case t_lc::l1:
[6026]153 phaseCoeff[_fType1] = 1.0;
[6025]154 return;
155 case t_lc::l2:
[6026]156 phaseCoeff[_fType2] = 1.0;
[6025]157 return;
158 case t_lc::lIF:
[6026]159 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
160 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
[6025]161 return;
162 case t_lc::MW:
[6026]163 phaseCoeff[_fType1] = f1 / (f1 - f2);
164 phaseCoeff[_fType2] = -f2 / (f1 - f2);
165 codeCoeff[_fType1] = -f1 / (f1 + f2);
166 codeCoeff[_fType2] = -f2 / (f1 + f2);
[6025]167 return;
168 case t_lc::CL:
[6026]169 phaseCoeff[_fType1] = 0.5;
170 codeCoeff[_fType1] = 0.5;
[6025]171 return;
172 case t_lc::c1:
[6026]173 codeCoeff[_fType1] = 1.0;
[6025]174 return;
175 case t_lc::c2:
[6026]176 codeCoeff[_fType2] = 1.0;
[6025]177 return;
178 case t_lc::cIF:
[6026]179 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
180 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
[6025]181 return;
182 case t_lc::dummy:
183 case t_lc::maxLc:
184 return;
185 }
186}
187
[6026]188//
189////////////////////////////////////////////////////////////////////////////
190bool t_pppSatObs::isValid(t_lc::type tLC) const {
[6027]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 {
[6025]198
[6026]199 map<t_frequency::type, double> codeCoeff;
200 map<t_frequency::type, double> phaseCoeff;
201 lcCoeff(tLC, codeCoeff, phaseCoeff);
202
[6027]203 double retVal = 0.0;
204 if (valid) *valid = true;
205
[6026]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) {
[6027]210 if (valid) *valid = false;
211 return 0.0;
[6026]212 }
[6027]213 else {
[6028]214 retVal += it->second * _obs[tFreq]->_code;
[6027]215 }
[6026]216 }
217 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
218 t_frequency::type tFreq = it->first;
219 if (_obs[tFreq] == 0) {
[6027]220 if (valid) *valid = false;
221 return 0.0;
[6026]222 }
[6027]223 else {
[6028]224 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
[6027]225 }
[6026]226 }
227
[6027]228 return retVal;
[6026]229}
230
[6029]231//
232////////////////////////////////////////////////////////////////////////////
233double t_pppSatObs::lambda(t_lc::type tLC) const {
[6026]234
[6029]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
[6026]257//
258////////////////////////////////////////////////////////////////////////////
[6029]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
[6116]277 // De-Weight GLONASS
278 // -----------------
279 if (_prn.system() == 'R') {
280 retVal *= 5.0;
281 }
282
[6029]283 // Elevation-Dependent Weighting
284 // -----------------------------
285 double cEle = 1.0;
286 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
287 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
288 double eleD = eleSat()*180.0/M_PI;
289 double hlp = fabs(90.0 - eleD);
290 cEle = (1.0 + hlp*hlp*hlp*0.000004);
291 }
292
293 return cEle * retVal;
294}
295
296//
297////////////////////////////////////////////////////////////////////////////
298double t_pppSatObs::maxRes(t_lc::type tLC) const {
299
300 map<t_frequency::type, double> codeCoeff;
301 map<t_frequency::type, double> phaseCoeff;
302 lcCoeff(tLC, codeCoeff, phaseCoeff);
303
304 double retVal = 0.0;
305
306 map<t_frequency::type, double>::const_iterator it;
307 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
[6034]308 retVal += it->second * it->second * OPT->_maxResC1 * OPT->_maxResC1;
[6029]309 }
310 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
[6034]311 retVal += it->second * it->second * OPT->_maxResL1 * OPT->_maxResL1;
[6029]312 }
313
[6034]314 return sqrt(retVal);
[6029]315}
316
317
318//
319////////////////////////////////////////////////////////////////////////////
[5819]320t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
[5743]321
322 // Reset all model values
323 // ----------------------
324 _model.reset();
325
326 // Topocentric Satellite Position
327 // ------------------------------
328 ColumnVector rSat = _xcSat.Rows(1,3);
329 ColumnVector rhoV = rSat - station->xyzApr();
330 _model._rho = rhoV.norm_Frobenius();
331
332 ColumnVector neu(3);
333 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
334
335 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
336 if (neu[2] < 0) {
337 _model._eleSat *= -1.0;
338 }
339 _model._azSat = atan2(neu[1], neu[0]);
340
341 // Satellite Clocks
342 // ----------------
[5750]343 _model._satClkM = _xcSat[3] * t_CST::c;
[5743]344
345 // Receiver Clocks
346 // ---------------
[5750]347 _model._recClkM = station->dClk() * t_CST::c;
[5743]348
349 // Sagnac Effect (correction due to Earth rotation)
350 // ------------------------------------------------
351 ColumnVector Omega(3);
352 Omega[0] = 0.0;
353 Omega[1] = 0.0;
[5750]354 Omega[2] = t_CST::omega / t_CST::c;
[5743]355 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
356
357 // Antenna Eccentricity
358 // --------------------
359 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
360
361 // Antenna Phase Center Offsets and Variations
362 // -------------------------------------------
363 if (PPP_CLIENT->antex()) {
[6030]364 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
[6406]365 t_frequency::type frqType = static_cast<t_frequency::type>(ii);
366 bool found;
367 _model._antPCO[ii] = PPP_CLIENT->antex()->rcvCorr(station->antName(), frqType,
368 _model._eleSat, _model._azSat, found);
[6030]369 }
[5743]370 }
371
372 // Tropospheric Delay
373 // ------------------
[5829]374 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
[5743]375
376 // Phase Wind-Up
377 // -------------
378 _model._windUp = station->windUp(_time, _prn, rSat);
379
[6463]380 // Code Biases
381 // -----------
382 const t_satCodeBias* satCodeBias = PPP_CLIENT->obsPool()->satCodeBias(_prn);
383 if (satCodeBias) {
384 for (unsigned ii = 0; ii < satCodeBias->_bias.size(); ii++) {
385 const t_frqCodeBias& bias = satCodeBias->_bias[ii];
[6030]386 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
387 const t_frqObs* obs = _obs[iFreq];
388 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
[6463]389 _model._codeBias[iFreq] = bias._value;
[5743]390 }
391 }
392 }
393 }
394
395 // Tidal Correction
396 // ----------------
397 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
398
399 // Ionospheric Delay
400 // -----------------
401 // TODO
402
403 // Ocean Loading
404 // -------------
405 // TODO
406
407 // Set Model Set Flag
408 // ------------------
409 _model._set = true;
410
[5750]411 return success;
[5743]412}
413
414//
415////////////////////////////////////////////////////////////////////////////
[5819]416void t_pppSatObs::printModel() const {
[5743]417 LOG.setf(ios::fixed);
418 LOG << "MODEL for Satellite " << _prn.toString() << endl
[6030]419 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
420 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
421 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
422 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
423 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
424 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
425 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
426 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
427 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
428 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
429 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
430 if (_obs[iFreq]) {
431 LOG << "PCO: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
432 << "BIAS CODE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
433 << "BIAS PHASE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl;
434 }
435 }
[5743]436 LOG << "OBS-CMP P3: " << _prn.toString() << " "
437 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
438 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
439 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
440
441 LOG << "OBS-CMP L3: " << _prn.toString() << " "
442 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
443 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
444 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
445
446 LOG << "OBS-CMP MW: " << _prn.toString() << " "
447 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
448 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
449 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
450}
451
452//
453////////////////////////////////////////////////////////////////////////////
[5819]454double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
[5743]455 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
456}
457
458//
459////////////////////////////////////////////////////////////////////////////
[5819]460double t_pppSatObs::cmpValue(t_lc::type tLC) const {
[5743]461
[6031]462 if (!isValid(tLC)) {
[5743]463 return 0.0;
464 }
465
466 // Non-Dispersive Part
467 // -------------------
468 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
469 + _model._sagnac + _model._antEcc + _model._tropo
470 + _model._tide;
471
472 // Add Dispersive Part
473 // -------------------
[6031]474 map<t_frequency::type, double> codeCoeff;
475 map<t_frequency::type, double> phaseCoeff;
476 lcCoeff(tLC, codeCoeff, phaseCoeff);
[5743]477
[6031]478 double dispPart = 0.0;
479
480 map<t_frequency::type, double>::const_iterator it;
481 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
482 t_frequency::type tFreq = it->first;
483 dispPart += it->second * (_model._antPCO[tFreq] + _model._codeBias[tFreq]);
484 }
485 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
486 t_frequency::type tFreq = it->first;
[6032]487 dispPart += it->second * (_model._antPCO[tFreq] + _model._phaseBias[tFreq] +
488 _model._windUp * t_CST::lambda(tFreq, _channel));
[6031]489 }
490
491 return nonDisp + dispPart;
[5743]492}
493
494//
495////////////////////////////////////////////////////////////////////////////
[5819]496void t_pppSatObs::setRes(t_lc::type tLC, double res) {
[5743]497 _res[tLC] = res;
498}
499
500//
501////////////////////////////////////////////////////////////////////////////
[5819]502double t_pppSatObs::getRes(t_lc::type tLC) const {
[5743]503 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
504 if (it != _res.end()) {
505 return it->second;
506 }
507 else {
508 return 0.0;
509 }
510}
Note: See TracBrowser for help on using the repository browser.