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

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