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

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