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

Last change on this file since 6462 was 6406, 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
[6030]380 // Code and Phase Biases
381 // ---------------------
[5827]382 const t_satBias* satBias = PPP_CLIENT->obsPool()->satBias(_prn);
[5743]383 if (satBias) {
[5827]384 for (unsigned ii = 0; ii < satBias->_bias.size(); ii++) {
385 const t_frqBias& bias = satBias->_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) {
389 _model._codeBias[iFreq] = bias._code;
390 _model._phaseBias[iFreq] = bias._phase;
[5743]391 }
392 }
393 }
394 }
395
396 // Tidal Correction
397 // ----------------
398 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
399
400 // Ionospheric Delay
401 // -----------------
402 // TODO
403
404 // Ocean Loading
405 // -------------
406 // TODO
407
408 // Set Model Set Flag
409 // ------------------
410 _model._set = true;
411
[5750]412 return success;
[5743]413}
414
415//
416////////////////////////////////////////////////////////////////////////////
[5819]417void t_pppSatObs::printModel() const {
[5743]418 LOG.setf(ios::fixed);
419 LOG << "MODEL for Satellite " << _prn.toString() << endl
[6030]420 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
421 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
422 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
423 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
424 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
425 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
426 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
427 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
428 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
429 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
430 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
431 if (_obs[iFreq]) {
432 LOG << "PCO: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
433 << "BIAS CODE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
434 << "BIAS PHASE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl;
435 }
436 }
[5743]437 LOG << "OBS-CMP P3: " << _prn.toString() << " "
438 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
439 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
440 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
441
442 LOG << "OBS-CMP L3: " << _prn.toString() << " "
443 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
444 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
445 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
446
447 LOG << "OBS-CMP MW: " << _prn.toString() << " "
448 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
449 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
450 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
451}
452
453//
454////////////////////////////////////////////////////////////////////////////
[5819]455double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
[5743]456 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
457}
458
459//
460////////////////////////////////////////////////////////////////////////////
[5819]461double t_pppSatObs::cmpValue(t_lc::type tLC) const {
[5743]462
[6031]463 if (!isValid(tLC)) {
[5743]464 return 0.0;
465 }
466
467 // Non-Dispersive Part
468 // -------------------
469 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
470 + _model._sagnac + _model._antEcc + _model._tropo
471 + _model._tide;
472
473 // Add Dispersive Part
474 // -------------------
[6031]475 map<t_frequency::type, double> codeCoeff;
476 map<t_frequency::type, double> phaseCoeff;
477 lcCoeff(tLC, codeCoeff, phaseCoeff);
[5743]478
[6031]479 double dispPart = 0.0;
480
481 map<t_frequency::type, double>::const_iterator it;
482 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
483 t_frequency::type tFreq = it->first;
484 dispPart += it->second * (_model._antPCO[tFreq] + _model._codeBias[tFreq]);
485 }
486 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
487 t_frequency::type tFreq = it->first;
[6032]488 dispPart += it->second * (_model._antPCO[tFreq] + _model._phaseBias[tFreq] +
489 _model._windUp * t_CST::lambda(tFreq, _channel));
[6031]490 }
491
492 return nonDisp + dispPart;
[5743]493}
494
495//
496////////////////////////////////////////////////////////////////////////////
[5819]497void t_pppSatObs::setRes(t_lc::type tLC, double res) {
[5743]498 _res[tLC] = res;
499}
500
501//
502////////////////////////////////////////////////////////////////////////////
[5819]503double t_pppSatObs::getRes(t_lc::type tLC) const {
[5743]504 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
505 if (it != _res.end()) {
506 return it->second;
507 }
508 else {
509 return 0.0;
510 }
511}
Note: See TracBrowser for help on using the repository browser.