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

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