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

Last change on this file since 5918 was 5918, checked in by mervart, 10 years ago
File size: 15.5 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(_prn.system());
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 const t_satBias* satBias = PPP_CLIENT->obsPool()->satBias(_prn);
244 if (satBias) {
245 for (unsigned ii = 0; ii < satBias->_bias.size(); ii++) {
246 const t_frqBias& bias = satBias->_bias[ii];
247 if (_validObs1 && _validObs1->_rnxType2ch == bias._rnxType2ch) {
248 _validObs1->_biasJumpCounter = satBias->_jumpCount;
249 if (bias._codeValid) {
250 _model._biasC1 = bias._code;
251 }
252 if (bias._phaseValid) {
253 _model._biasL1 = bias._phase;
254 }
255 }
256 if (_validObs2 && _validObs2->_rnxType2ch == bias._rnxType2ch) {
257 _validObs2->_biasJumpCounter = satBias->_jumpCount;
258 if (bias._codeValid) {
259 _model._biasC2 = bias._code;
260 }
261 if (bias._phaseValid) {
262 _model._biasL2 = bias._phase;
263 }
264 }
265 }
266 }
267
268 // Tidal Correction
269 // ----------------
270 _model._tide = -DotProduct(station->tideDspl(), rhoV) / _model._rho;
271
272 // Ionospheric Delay
273 // -----------------
274 // TODO
275
276 // Ocean Loading
277 // -------------
278 // TODO
279
280 // Set Model Set Flag
281 // ------------------
282 _model._set = true;
283
284 return success;
285}
286
287//
288////////////////////////////////////////////////////////////////////////////
289void t_pppSatObs::printModel() const {
290 LOG.setf(ios::fixed);
291 LOG << "MODEL for Satellite " << _prn.toString() << endl
292 << "RHO: " << setw(12) << setprecision(3) << _model._rho << endl
293 << "ELE: " << setw(12) << setprecision(3) << _model._eleSat * 180.0 / M_PI << endl
294 << "AZI: " << setw(12) << setprecision(3) << _model._azSat * 180.0 / M_PI << endl
295 << "SATCLK: " << setw(12) << setprecision(3) << _model._satClkM << endl
296 << "RECCLK: " << setw(12) << setprecision(3) << _model._recClkM << endl
297 << "SAGNAC: " << setw(12) << setprecision(3) << _model._sagnac << endl
298 << "ANTECC: " << setw(12) << setprecision(3) << _model._antEcc << endl
299 << "PCO1: " << setw(12) << setprecision(3) << _model._antPco1 << endl
300 << "PCO2: " << setw(12) << setprecision(3) << _model._antPco2 << endl
301 << "TROPO: " << setw(12) << setprecision(3) << _model._tropo << endl
302 << "WINDUP: " << setw(12) << setprecision(3) << _model._windUp << endl
303 << "BIASC1: " << setw(12) << setprecision(3) << _model._biasC1 << endl
304 << "BIASC2: " << setw(12) << setprecision(3) << _model._biasC2 << endl
305 << "BIASL1: " << setw(12) << setprecision(3) << _model._biasL1 << endl
306 << "BIASL2: " << setw(12) << setprecision(3) << _model._biasL2 << endl
307 << "TIDES: " << setw(12) << setprecision(3) << _model._tide << endl;
308
309 //// beg test
310 LOG << "PCO L3: " << setw(12) << setprecision(3)
311 << lc(t_lc::lIF, _model._antPco1, _model._antPco2, 0.0, 0.0) << endl;
312
313 LOG << "WIND L3:" << setw(12) << setprecision(3)
314 << lc(t_lc::lIF, _model._windUp * t_CST::c / _f1,
315 _model._windUp * t_CST::c / _f2, 0.0, 0.0) << endl;
316
317 LOG << "OBS-CMP P3: " << _prn.toString() << " "
318 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) << " "
319 << setw(12) << setprecision(3) << cmpValue(t_lc::cIF) << " "
320 << setw(12) << setprecision(3) << obsValue(t_lc::cIF) - cmpValue(t_lc::cIF) << endl;
321
322 LOG << "OBS-CMP L3: " << _prn.toString() << " "
323 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) << " "
324 << setw(12) << setprecision(3) << cmpValue(t_lc::lIF) << " "
325 << setw(12) << setprecision(3) << obsValue(t_lc::lIF) - cmpValue(t_lc::lIF) << endl;
326
327 LOG << "OBS-CMP MW: " << _prn.toString() << " "
328 << setw(12) << setprecision(3) << obsValue(t_lc::MW) << " "
329 << setw(12) << setprecision(3) << cmpValue(t_lc::MW) << " "
330 << setw(12) << setprecision(3) << obsValue(t_lc::MW) - cmpValue(t_lc::MW) << endl;
331 //// end test
332}
333
334//
335////////////////////////////////////////////////////////////////////////////
336double t_pppSatObs::obsValue(t_lc::type tLC) const {
337
338 if (!_validObs2 && t_lc::need2ndFreq(tLC)) {
339 return 0.0;
340 }
341
342 return this->lc(tLC, _rawL1, _rawL2, _rawC1, _rawC2);
343}
344
345//
346////////////////////////////////////////////////////////////////////////////
347double t_pppSatObs::cmpValueForBanc(t_lc::type tLC) const {
348 return cmpValue(tLC) - _model._rho - _model._sagnac - _model._recClkM;
349}
350
351//
352////////////////////////////////////////////////////////////////////////////
353double t_pppSatObs::cmpValue(t_lc::type tLC) const {
354
355 if (!_validObs2 && t_lc::need2ndFreq(tLC)) {
356 return 0.0;
357 }
358
359 // Non-Dispersive Part
360 // -------------------
361 double nonDisp = _model._rho + _model._recClkM - _model._satClkM
362 + _model._sagnac + _model._antEcc + _model._tropo
363 + _model._tide;
364
365 // Add Dispersive Part
366 // -------------------
367 double L1 = nonDisp + _model._antPco1 - _model._biasL1 + _model._windUp * t_CST::c / _f1;
368 double L2 = nonDisp + _model._antPco2 - _model._biasL2 + _model._windUp * t_CST::c / _f2;
369 double C1 = nonDisp + _model._antPco1 - _model._biasC1;
370 double C2 = nonDisp + _model._antPco2 - _model._biasC2;
371
372 return this->lc(tLC, L1, L2, C1, C2);
373}
374
375//
376////////////////////////////////////////////////////////////////////////////
377double t_pppSatObs::lc(t_lc::type tLC,
378 double L1, double L2, double C1, double C2,
379 ColumnVector* coeff) const {
380
381 if (coeff) {
382 coeff->ReSize(4);
383 (*coeff) = 0.0;
384 }
385
386 if (tLC == t_lc::l1) {
387 if (coeff) (*coeff)(1) = 1.0;
388 return L1;
389 }
390 else if (tLC == t_lc::l2) {
391 if (coeff) (*coeff)(2) = 1.0;
392 return L2;
393 }
394 else if (tLC == t_lc::c1) {
395 if (coeff) (*coeff)(3) = 1.0;
396 return C1;
397 }
398 else if (tLC == t_lc::c2) {
399 if (coeff) (*coeff)(4) = 1.0;
400 return C2;
401 }
402 else if (tLC == t_lc::lIF || tLC == t_lc::cIF) {
403 double a1 = _f1 * _f1 / (_f1 * _f1 - _f2 * _f2);
404 double a2 = -_f2 * _f2 / (_f1 * _f1 - _f2 * _f2);
405 if (tLC == t_lc::lIF) {
406 if (coeff) {
407 (*coeff)(1) = a1;
408 (*coeff)(2) = a2;
409 }
410 return a1 * L1 + a2 * L2;
411 }
412 else {
413 if (coeff) {
414 (*coeff)(3) = a1;
415 (*coeff)(4) = a2;
416 }
417 return a1 * C1 + a2 * C2;
418 }
419 }
420 else if (tLC == t_lc::MW) {
421 double a1 = _f1 / (_f1 - _f2);
422 double a2 = -_f2 / (_f1 - _f2);
423 double a3 = -_f1 / (_f1 + _f2);
424 double a4 = -_f2 / (_f1 + _f2);
425 if (coeff) {
426 (*coeff)(1) = a1;
427 (*coeff)(2) = a2;
428 (*coeff)(3) = a3;
429 (*coeff)(4) = a4;
430 }
431 return a1 * L1 + a2 * L2 + a3 * C1 + a4 * C2;
432 }
433 else if (tLC == t_lc::CL) {
434 if (coeff) {
435 (*coeff)(1) = 0.5;
436 (*coeff)(3) = 0.5;
437 }
438 return (C1 + L1) / 2.0;
439 }
440
441 return 0.0;
442}
443
444//
445////////////////////////////////////////////////////////////////////////////
446double t_pppSatObs::lambda(t_lc::type tLC) const {
447
448 if (tLC == t_lc::l1) {
449 return t_CST::c / _f1;
450 }
451 else if (tLC == t_lc::l2) {
452 return t_CST::c / _f2;
453 }
454 else if (tLC == t_lc::lIF) {
455 return t_CST::c / (_f1 + _f2);
456 }
457 else if (tLC == t_lc::MW) {
458 return t_CST::c / (_f1 - _f2);
459 }
460 else if (tLC == t_lc::CL) {
461 return t_CST::c / _f1 / 2.0;
462 }
463
464 return 0.0;
465}
466
467//
468////////////////////////////////////////////////////////////////////////////
469double t_pppSatObs::sigma(t_lc::type tLC) const {
470
471 ColumnVector sig(4);
472 sig(1) = OPT->_sigmaL1;
473 sig(2) = OPT->_sigmaL1;
474 sig(3) = OPT->_sigmaC1;
475 sig(4) = OPT->_sigmaC1;
476
477 ColumnVector coeff(4);
478 lc(tLC, sig(1), sig(2), sig(3), sig(4), &coeff);
479
480 ColumnVector sp = SP(sig, coeff); // Schur product
481
482 // Elevation-Dependent Weighting
483 // -----------------------------
484 double cEle = 1.0;
485 if ( (OPT->_eleWgtCode && t_lc::includesCode(tLC)) ||
486 (OPT->_eleWgtPhase && t_lc::includesPhase(tLC)) ) {
487 double eleD = eleSat()*180.0/M_PI;
488 double hlp = fabs(90.0 - eleD);
489 cEle = (1.0 + hlp*hlp*hlp*0.000004);
490 }
491
492 return cEle * sp.norm_Frobenius();
493}
494
495//
496////////////////////////////////////////////////////////////////////////////
497double t_pppSatObs::maxRes(t_lc::type tLC) const {
498
499 ColumnVector res(4);
500 res(1) = OPT->_maxResL1;
501 res(2) = OPT->_maxResL1;
502 res(3) = OPT->_maxResC1;
503 res(4) = OPT->_maxResC1;
504
505 ColumnVector coeff(4);
506 lc(tLC, res(1), res(2), res(3), res(4), &coeff);
507
508 ColumnVector sp = SP(res, coeff); // Schur product
509
510 return sp.norm_Frobenius();
511}
512
513//
514////////////////////////////////////////////////////////////////////////////
515void t_pppSatObs::setRes(t_lc::type tLC, double res) {
516 _res[tLC] = res;
517}
518
519//
520////////////////////////////////////////////////////////////////////////////
521double t_pppSatObs::getRes(t_lc::type tLC) const {
522 map<t_lc::type, double>::const_iterator it = _res.find(tLC);
523 if (it != _res.end()) {
524 return it->second;
525 }
526 else {
527 return 0.0;
528 }
529}
Note: See TracBrowser for help on using the repository browser.