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

Last change on this file since 6026 was 6026, checked in by mervart, 10 years ago
File size: 15.4 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
212 map<t_frequency::type, double> codeCoeff;
213 map<t_frequency::type, double> phaseCoeff;
214 lcCoeff(tLC, codeCoeff, phaseCoeff);
215
216 map<t_frequency::type, double>::const_iterator it;
217 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
218 t_frequency::type tFreq = it->first;
219 if (_obs[tFreq] == 0) {
220 return false;
221 }
222 }
223 for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {
224 t_frequency::type tFreq = it->first;
225 if (_obs[tFreq] == 0) {
226 return false;
227 }
228 }
229
230 return true;
231}
232
233//
234////////////////////////////////////////////////////////////////////////////
235double t_pppSatObs::obsValue(t_lc::type tLC) const {
236
237 if (!_validObs2 && t_lc::need2ndFreq(tLC)) {
238 return 0.0;
239 }
240
241 return this->lc(tLC, _rawL1, _rawL2, _rawC1, _rawC2);
242}
243
244
245//
246////////////////////////////////////////////////////////////////////////////
247t_irc t_pppSatObs::cmpModel(const t_pppStation* station) {
248
249 // Reset all model values
250 // ----------------------
251 _model.reset();
252
253 // Topocentric Satellite Position
254 // ------------------------------
255 ColumnVector rSat = _xcSat.Rows(1,3);
256 ColumnVector rhoV = rSat - station->xyzApr();
257 _model._rho = rhoV.norm_Frobenius();
258
259 ColumnVector neu(3);
260 xyz2neu(station->ellApr().data(), rhoV.data(), neu.data());
261
262 _model._eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / _model._rho );
263 if (neu[2] < 0) {
264 _model._eleSat *= -1.0;
265 }
266 _model._azSat = atan2(neu[1], neu[0]);
267
268 // Satellite Clocks
269 // ----------------
270 _model._satClkM = _xcSat[3] * t_CST::c;
271
272 // Receiver Clocks
273 // ---------------
274 _model._recClkM = station->dClk() * t_CST::c;
275
276 // Sagnac Effect (correction due to Earth rotation)
277 // ------------------------------------------------
278 ColumnVector Omega(3);
279 Omega[0] = 0.0;
280 Omega[1] = 0.0;
281 Omega[2] = t_CST::omega / t_CST::c;
282 _model._sagnac = DotProduct(Omega, crossproduct(rSat, station->xyzApr()));
283
284 // Antenna Eccentricity
285 // --------------------
286 _model._antEcc = -DotProduct(station->xyzEcc(), rhoV) / _model._rho;
287
288 // Antenna Phase Center Offsets and Variations
289 // -------------------------------------------
290 if (PPP_CLIENT->antex()) {
291 bool found;
292 _model._antPco1 = PPP_CLIENT->antex()->rcvCorr(station->antName(), _model._eleSat, found);
293 _model._antPco2 = _model._antPco1;
294 }
295
296 // Tropospheric Delay
297 // ------------------
298 _model._tropo = t_tropo::delay_saast(station->xyzApr(), _model._eleSat);
299
300 // Phase Wind-Up
301 // -------------
302 _model._windUp = station->windUp(_time, _prn, rSat);
303
304 // Code (and Phase) Biases
305 // -----------------------
306 const t_satBias* satBias = PPP_CLIENT->obsPool()->satBias(_prn);
307 if (satBias) {
308 for (unsigned ii = 0; ii < satBias->_bias.size(); ii++) {
309 const t_frqBias& bias = satBias->_bias[ii];
310 if (_validObs1 && _validObs1->_rnxType2ch == bias._rnxType2ch) {
311 _validObs1->_biasJumpCounter = satBias->_jumpCount;
312 if (bias._codeValid) {
313 _model._biasC1 = bias._code;
314 }
315 if (bias._phaseValid) {
316 _model._biasL1 = bias._phase;
317 }
318 }
319 if (_validObs2 && _validObs2->_rnxType2ch == bias._rnxType2ch) {
320 _validObs2->_biasJumpCounter = satBias->_jumpCount;
321 if (bias._codeValid) {
322 _model._biasC2 = bias._code;
323 }
324 if (bias._phaseValid) {
325 _model._biasL2 = bias._phase;
326 }
327 }
328 }
329 }
330
331 // Tidal Correction
332 // ----------------
333 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
334
335 // Ionospheric Delay
336 // -----------------
337 // TODO
338
339 // Ocean Loading
340 // -------------
341 // TODO
342
343 // Set Model Set Flag
344 // ------------------
345 _model._set = true;
346
347 return success;
348}
349
350//
351////////////////////////////////////////////////////////////////////////////
352void t_pppSatObs::printModel() const {
353 LOG.setf(ios::fixed);
354 LOG << "MODEL for Satellite " << _prn.toString() << endl
355 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
356 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
357 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
358 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
359 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
360 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
361 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
362 << "PCO1: " << setw(12) << setprecision(3) << _model._antPco1 << endl
363 << "PCO2: " << setw(12) << setprecision(3) << _model._antPco2 << endl
364 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
365 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
366 << "BIASC1: " << setw(12) << setprecision(3) << _model._biasC1 << endl
367 << "BIASC2: " << setw(12) << setprecision(3) << _model._biasC2 << endl
368 << "BIASL1: " << setw(12) << setprecision(3) << _model._biasL1 << endl
369 << "BIASL2: " << setw(12) << setprecision(3) << _model._biasL2 << endl
370 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
371
372 //// beg test
373 LOG << "PCO L3: " << setw(12) << setprecision(3)
374 << lc(t_lc::lIF, _model._antPco1, _model._antPco2, 0.0, 0.0) << endl;
375
376 LOG << "WIND L3:" << setw(12) << setprecision(3)
377 << lc(t_lc::lIF, _model._windUp * t_CST::c / _f1,
378 _model._windUp * t_CST::c / _f2, 0.0, 0.0) << endl;
379
380 LOG << "OBS-CMP P3: " << _prn.toString() << " "
381 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
382 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
383 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
384
385 LOG << "OBS-CMP L3: " << _prn.toString() << " "
386 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
387 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
388 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
389
390 LOG << "OBS-CMP MW: " << _prn.toString() << " "
391 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
392 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
393 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
394 //// end test
395}
396
397//
398////////////////////////////////////////////////////////////////////////////
399double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
400 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
401}
402
403//
404////////////////////////////////////////////////////////////////////////////
405double t_pppSatObs::cmpValue(t_lc::type tLC) const {
406
407 if (!_validObs2 && t_lc::need2ndFreq(tLC)) {
408 return 0.0;
409 }
410
411 // Non-Dispersive Part
412 // -------------------
413 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
414 + _model._sagnac + _model._antEcc + _model._tropo
415 + _model._tide;
416
417 // Add Dispersive Part
418 // -------------------
419 double L1 = nonDisp + _model._antPco1 - _model._biasL1 + _model._windUp * t_CST::c / _f1;
420 double L2 = nonDisp + _model._antPco2 - _model._biasL2 + _model._windUp * t_CST::c / _f2;
421 double C1 = nonDisp + _model._antPco1 - _model._biasC1;
422 double C2 = nonDisp + _model._antPco2 - _model._biasC2;
423
424 return this->lc(tLC, L1, L2, C1, C2);
425}
426
427//
428////////////////////////////////////////////////////////////////////////////
429double t_pppSatObs::lambda(t_lc::type tLC) const {
430
431 if (tLC == t_lc::l1) {
432 return t_CST::c / _f1;
433 }
434 else if (tLC == t_lc::l2) {
435 return t_CST::c / _f2;
436 }
437 else if (tLC == t_lc::lIF) {
438 return t_CST::c / (_f1 + _f2);
439 }
440 else if (tLC == t_lc::MW) {
441 return t_CST::c / (_f1 - _f2);
442 }
443 else if (tLC == t_lc::CL) {
444 return t_CST::c / _f1 / 2.0;
445 }
446
447 return 0.0;
448}
449
450//
451////////////////////////////////////////////////////////////////////////////
452double t_pppSatObs::sigma(t_lc::type tLC) const {
453
454 ColumnVector sig(4);
455 sig(1) = OPT->_sigmaL1;
456 sig(2) = OPT->_sigmaL1;
457 sig(3) = OPT->_sigmaC1;
458 sig(4) = OPT->_sigmaC1;
459
460 ColumnVector coeff(4);
461 lc(tLC, sig(1), sig(2), sig(3), sig(4), &coeff);
462
463 ColumnVector sp = SP(sig, coeff); // Schur product
464
465 // Elevation-Dependent Weighting
466 // -----------------------------
467 double cEle = 1.0;
468 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
469 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
470 double eleD = eleSat()*180.0/M_PI;
471 double hlp = fabs(90.0 - eleD);
472 cEle = (1.0 + hlp*hlp*hlp*0.000004);
473 }
474
475 return cEle * sp.norm_Frobenius();
476}
477
478//
479////////////////////////////////////////////////////////////////////////////
480double t_pppSatObs::maxRes(t_lc::type tLC) const {
481
482 ColumnVector res(4);
483 res(1) = OPT->_maxResL1;
484 res(2) = OPT->_maxResL1;
485 res(3) = OPT->_maxResC1;
486 res(4) = OPT->_maxResC1;
487
488 ColumnVector coeff(4);
489 lc(tLC, res(1), res(2), res(3), res(4), &coeff);
490
491 ColumnVector sp = SP(res, coeff); // Schur product
492
493 return sp.norm_Frobenius();
494}
495
496//
497////////////////////////////////////////////////////////////////////////////
498void t_pppSatObs::setRes(t_lc::type tLC, double res) {
499 _res[tLC] = res;
500}
501
502//
503////////////////////////////////////////////////////////////////////////////
504double t_pppSatObs::getRes(t_lc::type tLC) const {
505 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
506 if (it != _res.end()) {
507 return it->second;
508 }
509 else {
510 return 0.0;
511 }
512}
Note: See TracBrowser for help on using the repository browser.