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

Last change on this file since 6032 was 6032, checked in by mervart, 10 years ago
File size: 15.9 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_pppSatObs
30 *
31 * Purpose: Satellite observations
32 *
33 * Author: L. Mervart
34 *
35 * Created: 29-Jul-2014
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41
42#include <iostream>
43#include <cmath>
44#include <newmatio.h>
45
46#include "pppSatObs.h"
47#include "bncconst.h"
48#include "pppEphPool.h"
49#include "pppStation.h"
50#include "bncutils.h"
51#include "bncantex.h"
52#include "pppObsPool.h"
53#include "pppClient.h"
54
55using namespace BNC_PPP;
56using namespace std;
57
58// Constructor
59////////////////////////////////////////////////////////////////////////////
60t_pppSatObs::t_pppSatObs(const t_satObs& pppSatObs) {
61 _prn = pppSatObs._prn;
62 _time = pppSatObs._time;
63 _outlier = false;
64 _valid = true;
65 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
66 _obs[ii] = 0;
67 }
68 prepareObs(pppSatObs);
69}
70
71// Destructor
72////////////////////////////////////////////////////////////////////////////
73t_pppSatObs::~t_pppSatObs() {
74 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
75 delete _obs[iFreq];
76 }
77}
78
79//
80////////////////////////////////////////////////////////////////////////////
81void t_pppSatObs::prepareObs(const t_satObs& pppSatObs) {
82
83 _model.reset();
84
85 // Select pseudoranges and phase observations
86 // ------------------------------------------
87 const string preferredAttrib = "CWP_";
88
89 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
90 string frqNum = t_frequency::toString(t_frequency::type(iFreq)).substr(1);
91 for (unsigned iPref = 0; iPref < preferredAttrib.length(); iPref++) {
92 string obsType = (preferredAttrib[iPref] == '_') ? frqNum : frqNum + preferredAttrib[iPref];
93 if (_obs[iFreq] == 0) {
94 for (unsigned ii = 0; ii < pppSatObs._obs.size(); ii++) {
95 const t_frqObs* obs = pppSatObs._obs[ii];
96 if (obs->_rnxType2ch == obsType && obs->_codeValid && obs->_phaseValid) {
97 _obs[iFreq] = new t_frqObs(*obs);
98 _obs[iFreq]->_freqType = t_frequency::type(iFreq);
99 }
100 }
101 }
102 }
103 }
104
105 // Used frequency types
106 // --------------------
107 _fType1 = t_lc::toFreq(_prn.system(),t_lc::l1);
108 _fType2 = t_lc::toFreq(_prn.system(),t_lc::l2);
109
110 // Check whether all required frequencies available
111 // ------------------------------------------------
112 for (unsigned ii = 0; ii < OPT->LCs(_prn.system()).size(); ii++) {
113 t_lc::type tLC = OPT->LCs(_prn.system())[ii];
114 if (!isValid(tLC)) {
115 _valid = false;
116 return;
117 }
118 }
119
120 // Find Glonass Channel Number
121 // ---------------------------
122 if (_prn.system() == 'R') {
123 _channel = PPP_CLIENT->ephPool()->getChannel(_prn);
124 }
125 else {
126 _channel = 0;
127 }
128
129 // Compute Satellite Coordinates at Time of Transmission
130 // -----------------------------------------------------
131 _xcSat.ReSize(4); _xcSat = 0.0;
132 _vvSat.ReSize(4); _vvSat = 0.0;
133 bool totOK = false;
134 ColumnVector satPosOld(4); satPosOld = 0.0;
135 t_lc::type tLC = isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
136 double prange = obsValue(tLC);
137 for (int ii = 1; ii <= 10; ii++) {
138 bncTime ToT = _time - prange / t_CST::c - _xcSat[3];
139 if (PPP_CLIENT->ephPool()->getCrd(_prn, ToT, _xcSat, _vvSat) != success) {
140 _valid = false;
141 return;
142 }
143 ColumnVector dx = _xcSat - satPosOld;
144 dx[3] *= t_CST::c;
145 if (dx.norm_Frobenius() < 1.e-4) {
146 totOK = true;
147 break;
148 }
149 satPosOld = _xcSat;
150 }
151 if (totOK) {
152 _model._satClkM = _xcSat[3] * t_CST::c;
153 }
154 else {
155 _valid = false;
156 }
157}
158
159//
160////////////////////////////////////////////////////////////////////////////
161void t_pppSatObs::lcCoeff(t_lc::type tLC,
162 map<t_frequency::type, double>& codeCoeff,
163 map<t_frequency::type, double>& phaseCoeff) const {
164
165 codeCoeff.clear();
166 phaseCoeff.clear();
167
168 double f1 = t_CST::freq(_fType1, _channel);
169 double f2 = t_CST::freq(_fType2, _channel);
170
171 switch (tLC) {
172 case t_lc::l1:
173 phaseCoeff[_fType1] = 1.0;
174 return;
175 case t_lc::l2:
176 phaseCoeff[_fType2] = 1.0;
177 return;
178 case t_lc::lIF:
179 phaseCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
180 phaseCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
181 return;
182 case t_lc::MW:
183 phaseCoeff[_fType1] = f1 / (f1 - f2);
184 phaseCoeff[_fType2] = -f2 / (f1 - f2);
185 codeCoeff[_fType1] = -f1 / (f1 + f2);
186 codeCoeff[_fType2] = -f2 / (f1 + f2);
187 return;
188 case t_lc::CL:
189 phaseCoeff[_fType1] = 0.5;
190 codeCoeff[_fType1] = 0.5;
191 return;
192 case t_lc::c1:
193 codeCoeff[_fType1] = 1.0;
194 return;
195 case t_lc::c2:
196 codeCoeff[_fType2] = 1.0;
197 return;
198 case t_lc::cIF:
199 codeCoeff[_fType1] = f1 * f1 / (f1 * f1 - f2 * f2);
200 codeCoeff[_fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
201 return;
202 case t_lc::dummy:
203 case t_lc::maxLc:
204 return;
205 }
206}
207
208//
209////////////////////////////////////////////////////////////////////////////
210bool t_pppSatObs::isValid(t_lc::type tLC) const {
211 bool valid = true;
212 obsValue(tLC, &valid);
213 return valid;
214}
215//
216////////////////////////////////////////////////////////////////////////////
217double t_pppSatObs::obsValue(t_lc::type tLC, bool* valid) const {
218
219 map<t_frequency::type, double> codeCoeff;
220 map<t_frequency::type, double> phaseCoeff;
221 lcCoeff(tLC, codeCoeff, phaseCoeff);
222
223 double retVal = 0.0;
224 if (valid) *valid = true;
225
226 map<t_frequency::type, double>::const_iterator it;
227 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
228 t_frequency::type tFreq = it->first;
229 if (_obs[tFreq] == 0) {
230 if (valid) *valid = false;
231 return 0.0;
232 }
233 else {
234 retVal += it->second * _obs[tFreq]->_code;
235 }
236 }
237 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
238 t_frequency::type tFreq = it->first;
239 if (_obs[tFreq] == 0) {
240 if (valid) *valid = false;
241 return 0.0;
242 }
243 else {
244 retVal += it->second * _obs[tFreq]->_phase * t_CST::lambda(tFreq, _channel);
245 }
246 }
247
248 return retVal;
249}
250
251//
252////////////////////////////////////////////////////////////////////////////
253double t_pppSatObs::lambda(t_lc::type tLC) const {
254
255 double f1 = t_CST::freq(_fType1, _channel);
256 double f2 = t_CST::freq(_fType2, _channel);
257
258 if (tLC == t_lc::l1) {
259 return t_CST::c / f1;
260 }
261 else if (tLC == t_lc::l2) {
262 return t_CST::c / f2;
263 }
264 else if (tLC == t_lc::lIF) {
265 return t_CST::c / (f1 + f2);
266 }
267 else if (tLC == t_lc::MW) {
268 return t_CST::c / (f1 - f2);
269 }
270 else if (tLC == t_lc::CL) {
271 return t_CST::c / f1 / 2.0;
272 }
273
274 return 0.0;
275}
276
277//
278////////////////////////////////////////////////////////////////////////////
279double t_pppSatObs::sigma(t_lc::type tLC) const {
280
281 map<t_frequency::type, double> codeCoeff;
282 map<t_frequency::type, double> phaseCoeff;
283 lcCoeff(tLC, codeCoeff, phaseCoeff);
284
285 double retVal = 0.0;
286
287 map<t_frequency::type, double>::const_iterator it;
288 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
289 retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
290 }
291 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
292 retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
293 }
294
295 retVal = sqrt(retVal);
296
297 // Elevation-Dependent Weighting
298 // -----------------------------
299 double cEle = 1.0;
300 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
301 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
302 double eleD = eleSat()*180.0/M_PI;
303 double hlp = fabs(90.0 - eleD);
304 cEle = (1.0 + hlp*hlp*hlp*0.000004);
305 }
306
307 return cEle * retVal;
308}
309
310//
311////////////////////////////////////////////////////////////////////////////
312double t_pppSatObs::maxRes(t_lc::type tLC) const {
313
314 map<t_frequency::type, double> codeCoeff;
315 map<t_frequency::type, double> phaseCoeff;
316 lcCoeff(tLC, codeCoeff, phaseCoeff);
317
318 double retVal = 0.0;
319
320 map<t_frequency::type, double>::const_iterator it;
321 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
322 retVal += it->second * OPT->_maxResC1;
323 }
324 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
325 retVal += it->second * OPT->_maxResL1;
326 }
327
328 return retVal;
329}
330
331
332//
333////////////////////////////////////////////////////////////////////////////
334t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
335
336 // Reset all model values
337 // ----------------------
338 _model.reset();
339
340 // Topocentric Satellite Position
341 // ------------------------------
342 ColumnVector rSat = _xcSat.Rows(1,3);
343 ColumnVector rhoV = rSat - station->xyzApr();
344 _model._rho = rhoV.norm_Frobenius();
345
346 ColumnVector neu(3);
347 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
348
349 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
350 if (neu[2] < 0) {
351 _model._eleSat *= -1.0;
352 }
353 _model._azSat = atan2(neu[1], neu[0]);
354
355 // Satellite Clocks
356 // ----------------
357 _model._satClkM = _xcSat[3] * t_CST::c;
358
359 // Receiver Clocks
360 // ---------------
361 _model._recClkM = station->dClk() * t_CST::c;
362
363 // Sagnac Effect (correction due to Earth rotation)
364 // ------------------------------------------------
365 ColumnVector Omega(3);
366 Omega[0] = 0.0;
367 Omega[1] = 0.0;
368 Omega[2] = t_CST::omega / t_CST::c;
369 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
370
371 // Antenna Eccentricity
372 // --------------------
373 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
374
375 // Antenna Phase Center Offsets and Variations
376 // -------------------------------------------
377 if (PPP_CLIENT->antex()) {
378 bool found;
379 double pco = PPP_CLIENT->antex()->rcvCorr(station->antName(), _model._eleSat, found);
380 for (unsigned ii = 0; ii < t_frequency::max; ii++) {
381 _model._antPCO[ii] = pco;
382 }
383 }
384
385 // Tropospheric Delay
386 // ------------------
387 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
388
389 // Phase Wind-Up
390 // -------------
391 _model._windUp = station->windUp(_time, _prn, rSat);
392
393 // Code and Phase Biases
394 // ---------------------
395 const t_satBias* satBias = PPP_CLIENT->obsPool()->satBias(_prn);
396 if (satBias) {
397 for (unsigned ii = 0; ii < satBias->_bias.size(); ii++) {
398 const t_frqBias& bias = satBias->_bias[ii];
399 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
400 const t_frqObs* obs = _obs[iFreq];
401 if (obs && obs->_rnxType2ch == bias._rnxType2ch) {
402 _model._codeBias[iFreq] = bias._code;
403 _model._phaseBias[iFreq] = bias._phase;
404 }
405 }
406 }
407 }
408
409 // Tidal Correction
410 // ----------------
411 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
412
413 // Ionospheric Delay
414 // -----------------
415 // TODO
416
417 // Ocean Loading
418 // -------------
419 // TODO
420
421 // Set Model Set Flag
422 // ------------------
423 _model._set = true;
424
425 return success;
426}
427
428//
429////////////////////////////////////////////////////////////////////////////
430void t_pppSatObs::printModel() const {
431 LOG.setf(ios::fixed);
432 LOG << "MODEL for Satellite " << _prn.toString() << endl
433 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
434 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
435 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
436 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
437 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
438 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
439 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
440 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
441 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
442 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
443 for (unsigned iFreq = 1; iFreq < t_frequency::max; iFreq++) {
444 if (_obs[iFreq]) {
445 LOG << "PCO: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._antPCO[iFreq] << endl
446 << "BIAS CODE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._codeBias[iFreq] << endl
447 << "BIAS PHASE: " << t_frequency::toString(t_frequency::type(iFreq)) << setw(12) << setprecision(3) << _model._phaseBias[iFreq] << endl;
448 }
449 }
450 LOG << "OBS-CMP P3: " << _prn.toString() << " "
451 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
452 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
453 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
454
455 LOG << "OBS-CMP L3: " << _prn.toString() << " "
456 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
457 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
458 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
459
460 LOG << "OBS-CMP MW: " << _prn.toString() << " "
461 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
462 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
463 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
464}
465
466//
467////////////////////////////////////////////////////////////////////////////
468double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
469 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
470}
471
472//
473////////////////////////////////////////////////////////////////////////////
474double t_pppSatObs::cmpValue(t_lc::type tLC) const {
475
476 if (!isValid(tLC)) {
477 return 0.0;
478 }
479
480 // Non-Dispersive Part
481 // -------------------
482 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
483 + _model._sagnac + _model._antEcc + _model._tropo
484 + _model._tide;
485
486 // Add Dispersive Part
487 // -------------------
488 map<t_frequency::type, double> codeCoeff;
489 map<t_frequency::type, double> phaseCoeff;
490 lcCoeff(tLC, codeCoeff, phaseCoeff);
491
492 double dispPart = 0.0;
493
494 map<t_frequency::type, double>::const_iterator it;
495 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
496 t_frequency::type tFreq = it->first;
497 dispPart += it->second * (_model._antPCO[tFreq] + _model._codeBias[tFreq]);
498 }
499 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
500 t_frequency::type tFreq = it->first;
501 dispPart += it->second * (_model._antPCO[tFreq] + _model._phaseBias[tFreq] +
502 _model._windUp * t_CST::lambda(tFreq, _channel));
503 }
504
505 return nonDisp + dispPart;
506}
507
508//
509////////////////////////////////////////////////////////////////////////////
510void t_pppSatObs::setRes(t_lc::type tLC, double res) {
511 _res[tLC] = res;
512}
513
514//
515////////////////////////////////////////////////////////////////////////////
516double t_pppSatObs::getRes(t_lc::type tLC) const {
517 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
518 if (it != _res.end()) {
519 return it->second;
520 }
521 else {
522 return 0.0;
523 }
524}
Note: See TracBrowser for help on using the repository browser.