source: ntrip/trunk/BNC/src/bncantex.cpp@ 10947

Last change on this file since 10947 was 10947, checked in by stuerze, 2 months ago

minor changes

File size: 19.0 KB
RevLine 
[2880]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: bncAntex
30 *
31 * Purpose: Antenna Phase Centers and Variations from ANTEX File
32 *
33 * Author: L. Mervart
34 *
35 * Created: 26-Jan-2011
36 *
[7521]37 * Changes:
[2880]38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
[10946]42#include <cmath>
[2890]43#include <newmatio.h>
[2880]44
45#include "bncantex.h"
[6041]46#include "pppModel.h"
[2880]47
48using namespace std;
49
50// Constructor
51////////////////////////////////////////////////////////////////////////////
52bncAntex::bncAntex() {
53}
54
[5754]55// Constructor
56////////////////////////////////////////////////////////////////////////////
57bncAntex::bncAntex(const char* fileName) {
[9598]58 readFile(QString(fileName));//print();
[5754]59}
60
[2880]61// Destructor
62////////////////////////////////////////////////////////////////////////////
63bncAntex::~bncAntex() {
[2882]64 QMapIterator<QString, t_antMap*> it(_maps);
65 while (it.hasNext()) {
66 it.next();
67 delete it.value();
68 }
[10234]69 _maps.clear();
[2880]70}
71
[7521]72// Print
[2880]73////////////////////////////////////////////////////////////////////////////
[2887]74void bncAntex::print() const {
[6405]75 QMapIterator<QString, t_antMap*> itAnt(_maps);
76 while (itAnt.hasNext()) {
77 itAnt.next();
78 t_antMap* map = itAnt.value();
[8204]79 cout << map->antName.toLatin1().data() << endl;
[2890]80 cout << " " << map->zen1 << " " << map->zen2 << " " << map->dZen << endl;
[6405]81 QMapIterator<t_frequency::type, t_frqMap*> itFrq(map->frqMap);
82 while (itFrq.hasNext()) {
83 itFrq.next();
84 const t_frqMap* frqMap = itFrq.value();
[9598]85 cout << t_frequency::toString(itFrq.key()) << ":\n"
86 << frqMap->neu[0] << " "
87 << frqMap->neu[1] << " "
88 << frqMap->neu[2] << endl;
89 cout << frqMap->pattern.t();
[2890]90 }
91 cout << endl;
[2887]92 }
93}
94
[7521]95// Print
96////////////////////////////////////////////////////////////////////////////
97QString bncAntex::pcoSinexString(const std::string& antName, t_frequency::type frqType) {
98
99 if (antName.find("NULLANTENNA") != string::npos) {
[7848]100 return QString(" ------ ------ ------");
[7521]101 }
102
103 QString antNameQ = antName.c_str();
104 if (_maps.find(antNameQ) == _maps.end()) {
[7848]105 return QString(" ------ ------ ------");
[7521]106 }
107
108 t_antMap* map = _maps[antNameQ];
109 if (map->frqMap.find(frqType) == map->frqMap.end()) {
[7848]110 return QString(" ------ ------ ------");
[7521]111 }
112
113 t_frqMap* frqMap = map->frqMap[frqType];
114
[9675]115 QString u = QString().asprintf("%+6.4f" ,frqMap->neu[2]); if (u.mid(1,1) == "0") {u.remove(1,1);}
116 QString n = QString().asprintf("%+6.4f" ,frqMap->neu[0]); if (n.mid(1,1) == "0") {n.remove(1,1);}
117 QString e = QString().asprintf("%+6.4f" ,frqMap->neu[1]); if (e.mid(1,1) == "0") {e.remove(1,1);}
[7848]118
119 return QString(" %1 %2 %3").arg(u).arg(n).arg(e);
[7521]120}
121
[10130]122// Print
123////////////////////////////////////////////////////////////////////////////
124QString bncAntex::snxCodeSinexString(const std::string& antName) {
125
126 if (antName.find("NULLANTENNA") != string::npos) {
127 return QString(" ----------");
128 }
129
130 QString antNameQ = antName.c_str();
131 if (_maps.find(antNameQ) == _maps.end()) {
132 return QString(" ----------");
133 }
134 else {
135 return QString(" %1").arg(_maps[antNameQ]->snxCode, 10, QLatin1Char(' '));
136 }
137}
138
[2894]139// Read ANTEX File
[2887]140////////////////////////////////////////////////////////////////////////////
[2882]141t_irc bncAntex::readFile(const QString& fileName) {
[2880]142
[2881]143 QFile inFile(fileName);
144 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
145
146 QTextStream in(&inFile);
147
[8078]148 t_antMap* newAntMap = 0;
149 t_frqMap* newFrqMap = 0;
[2888]150
[2881]151 while ( !in.atEnd() ) {
152 QString line = in.readLine();
[7521]153
[2883]154 // Start of Antenna
155 // ----------------
[2882]156 if (line.indexOf("START OF ANTENNA") == 60) {
[2883]157 if (newAntMap) {
158 delete newAntMap;
[2882]159 return failure;
160 }
161 else {
[3295]162 delete newAntMap;
[2883]163 newAntMap = new t_antMap();
[2882]164 }
[7521]165 }
[2881]166
[2883]167 // End of Antenna
168 // --------------
[2882]169 else if (line.indexOf("END OF ANTENNA") == 60) {
[2883]170 if (newAntMap) {
[3542]171 if (_maps.contains(newAntMap->antName)) {
172 delete _maps[newAntMap->antName];
173 }
[2883]174 _maps[newAntMap->antName] = newAntMap;
175 newAntMap = 0;
[2882]176 }
177 else {
[3295]178 delete newAntMap;
[2882]179 return failure;
180 }
181 }
[2883]182
183 // Antenna Reading in Progress
184 // ---------------------------
185 else if (newAntMap) {
186 if (line.indexOf("TYPE / SERIAL NO") == 60) {
[2889]187 if (line.indexOf("BLOCK I") == 0 ||
[7141]188 line.indexOf("GLONASS") == 0 ||
189 line.indexOf("QZSS") == 0 ||
190 line.indexOf("BEIDOU") == 0 ||
191 line.indexOf("GALILEO") == 0 ||
[10619]192 line.indexOf("NavIC") == 0 ){
[2884]193 newAntMap->antName = line.mid(20,3);
194 }
195 else {
196 newAntMap->antName = line.mid(0,20);
197 }
[2883]198 }
199 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
[2884]200 QTextStream inLine(&line, QIODevice::ReadOnly);
[7521]201 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
[2883]202 }
[10130]203 else if (line.indexOf("SINEX CODE") == 60) {
204 QTextStream inLine(&line, QIODevice::ReadOnly);
205 inLine >> newAntMap->snxCode;
206 }
[2883]207
[2885]208 // Start of Frequency
209 // ------------------
[2883]210 else if (line.indexOf("START OF FREQUENCY") == 60) {
211 if (newFrqMap) {
212 delete newFrqMap;
213 delete newAntMap;
214 return failure;
215 }
216 else {
217 newFrqMap = new t_frqMap();
218 }
219 }
220
[2885]221 // End of Frequency
222 // ----------------
[2888]223 else if (line.indexOf("END OF FREQUENCY") == 60) {
[2883]224 if (newFrqMap) {
[6405]225 t_frequency::type frqType = t_frequency::dummy;
[8630]226 // GPS
[6405]227 if (line.indexOf("G01") == 3) {
228 frqType = t_frequency::G1;
[2883]229 }
[6405]230 else if (line.indexOf("G02") == 3) {
231 frqType = t_frequency::G2;
[2883]232 }
[8630]233 else if (line.indexOf("G05") == 3) {
234 frqType = t_frequency::G5;
235 }
236 // GLONASS
[6405]237 else if (line.indexOf("R01") == 3) {
238 frqType = t_frequency::R1;
239 }
240 else if (line.indexOf("R02") == 3) {
241 frqType = t_frequency::R2;
242 }
[8630]243 // Galileo
[7144]244 else if (line.indexOf("E01") == 3) {
245 frqType = t_frequency::E1;
246 }
247 else if (line.indexOf("E05") == 3) {
248 frqType = t_frequency::E5;
249 }
250 else if (line.indexOf("E06") == 3) {
251 frqType = t_frequency::E6;
252 }
253 else if (line.indexOf("E07") == 3) {
254 frqType = t_frequency::E7;
255 }
256 else if (line.indexOf("E08") == 3) {
257 frqType = t_frequency::E8;
258 }
[8630]259 // QZSS
[7145]260 else if (line.indexOf("J01") == 3) {
261 frqType = t_frequency::J1;
262 }
263 else if (line.indexOf("J02") == 3) {
264 frqType = t_frequency::J2;
265 }
266 else if (line.indexOf("J05") == 3) {
267 frqType = t_frequency::J5;
268 }
269 else if (line.indexOf("J06") == 3) {
270 frqType = t_frequency::J6;
271 }
[8630]272 // BDS
273 else if (line.indexOf("C01") == 3) {
274 frqType = t_frequency::C1;
275 }
[7144]276 else if (line.indexOf("C02") == 3) {
277 frqType = t_frequency::C2;
278 }
279 else if (line.indexOf("C06") == 3) {
280 frqType = t_frequency::C6;
281 }
282 else if (line.indexOf("C07") == 3) {
283 frqType = t_frequency::C7;
284 }
[6405]285 if (frqType != t_frequency::dummy) {
286 if (newAntMap->frqMap.find(frqType) != newAntMap->frqMap.end()) {
287 delete newAntMap->frqMap[frqType];
288 }
289 newAntMap->frqMap[frqType] = newFrqMap;
290 }
[2883]291 else {
292 delete newFrqMap;
293 }
294 newFrqMap = 0;
295 }
296 else {
297 delete newAntMap;
298 return failure;
299 }
300 }
301
[2885]302 // Frequency Reading in Progress
303 // -----------------------------
[2883]304 else if (newFrqMap) {
[2891]305 if (line.indexOf("NORTH / EAST / UP") == 60) {
[2885]306 QTextStream inLine(&line, QIODevice::ReadOnly);
307 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
[2894]308 newFrqMap->neu[0] *= 1e-3;
309 newFrqMap->neu[1] *= 1e-3;
310 newFrqMap->neu[2] *= 1e-3;
[2883]311 }
[2884]312 else if (line.indexOf("NOAZI") == 3) {
[2885]313 QTextStream inLine(&line, QIODevice::ReadOnly);
[2886]314 int nPat = int((newAntMap->zen2-newAntMap->zen1)/newAntMap->dZen) + 1;
315 newFrqMap->pattern.ReSize(nPat);
316 QString dummy;
317 inLine >> dummy;
318 for (int ii = 0; ii < nPat; ii++) {
319 inLine >> newFrqMap->pattern[ii];
320 }
[2894]321 newFrqMap->pattern *= 1e-3;
[2884]322 }
[2883]323 }
324 }
[2881]325 }
[7865]326 inFile.close();
[3034]327 delete newFrqMap;
328 delete newAntMap;
329
[2882]330 return success;
[2880]331}
[2894]332
[10946]333// GLONASS Yaw Angle (Sun-pointing law overridden near noon/midnight when
334// the satellite cannot mechanically keep up, following the GLONASS-M
335// "yaw-fixed" behaviour described in Dilssner, Springer, Flohrer, Dow
336// (2011), "The GLONASS-M satellite yaw-attitude model", Advances in Space
337// Research 47(1), 160-171.
338//
339// Unlike GPS/Galileo/BeiDou, which are commonly approximated by the
340// nominal Sun-pointing yaw-steering law of Bar-Sever (1996) at all times,
341// GLONASS-M has been found to stop tracking that law and hold a constant
342// (frozen) yaw angle whenever the required yaw rate would exceed the
343// satellite's slew capability - which happens close to the orbit
344// noon/midnight points whenever the Sun's elevation above the orbital
345// plane (the "beta" angle) is small. The maximum yaw rate used below
346// (0.25 deg/s) and the general approach follow that paper; satellite
347// telemetry was not available to validate the exact rate against this
348// installation's GLONASS satellites, so it should be checked against
349// independently-known attitude/orbit residuals if high accuracy matters.
350////////////////////////////////////////////////////////////////////////////
[10947]351double bncAntex::glonassYawAngle(const QString& prn, double Mjd,
352 const ColumnVector& xSat,
[10946]353 const ColumnVector& vSat,
354 const ColumnVector& xSun) {
355
356 const double MAX_YAW_RATE = 0.25 * M_PI / 180.0; // [rad/s], approximate
357
[10947]358 // A genuine yaw-fixed window (gapless data) only ever lasts a few
359 // minutes around the orbit noon/midnight point - see the width
360 // estimate in the comment above. If the stored frozen value is much
361 // older than that, it is more likely stale (e.g. a stream outage, a
362 // maneuver-flagged-unhealthy period, or a brief eclipse passage spanned
363 // the gap) than a still-valid freeze, so fall back to the current
364 // nominal value instead of trusting it indefinitely.
365 const double MAX_FREEZE_AGE = 1800.0 / 86400.0; // 30 minutes, in days
366
[10946]367 // Inertial-consistent velocity (xSat, vSat are Earth-fixed; remove the
368 // Earth-rotation contribution so that the orbit normal below is not
369 // contaminated by it)
370 // -------------------------------------------------------------------
371 ColumnVector Omega(3); Omega(1) = 0.0; Omega(2) = 0.0; Omega(3) = t_CST::omega;
372 ColumnVector vInert = vSat + crossproduct(Omega, xSat);
373
374 // Orbit normal and instantaneous orbital rate from r x v (exact, valid
375 // for any Keplerian orbit, not just circular ones)
376 // ---------------------------------------------------------------------
377 ColumnVector h = crossproduct(xSat, vInert);
378 double hNorm = sqrt(DotProduct(h, h));
379 ColumnVector orbNormal = h / hNorm;
380 double r = sqrt(DotProduct(xSat, xSat));
381 double nRate = hNorm / (r * r); // [rad/s]
382
383 // Beta angle (Sun elevation above the orbital plane)
384 // ----------------------------------------------------
385 double beta = asin(DotProduct(orbNormal, xSun));
386
387 // Orbit angle mu, measured from the orbit midnight point, increasing in
388 // the direction of satellite motion
389 // -----------------------------------------------------------------------
390 ColumnVector sunProj = xSun - DotProduct(xSun, orbNormal) * orbNormal;
391 sunProj /= sqrt(DotProduct(sunProj, sunProj));
392 ColumnVector eX = -1.0 * sunProj; // midnight direction, mu = 0
393 ColumnVector eY = crossproduct(orbNormal, eX);
394 ColumnVector rHat = xSat / r;
395 double mu = atan2(DotProduct(rHat, eY), DotProduct(rHat, eX));
396
397 // Nominal Sun-pointing yaw angle and its rate (Bar-Sever 1996)
398 // ----------------------------------------------------------------
399 double tanBeta = tan(beta);
400 double sinMu = sin(mu);
401 double psiNom = atan2(-tanBeta, sinMu);
402 double denom = tanBeta * tanBeta + sinMu * sinMu;
403 double psiRate = (denom > 1e-12)
404 ? nRate * fabs(tanBeta * cos(mu)) / denom
405 : 1e9;
406
407 t_glonassYaw& st = _glonassYaw[prn];
408 double psiEff;
409 if (psiRate > MAX_YAW_RATE) {
[10947]410 if (!st.valid || (Mjd - st.lastMjd) > MAX_FREEZE_AGE) {
411 st.yaw = psiNom; // no prior history, or it is too old to trust
412 st.lastMjd = Mjd;
413 st.valid = true;
[10946]414 }
415 psiEff = st.yaw; // hold the frozen yaw angle
416 }
417 else {
[10947]418 st.yaw = psiNom;
419 st.lastMjd = Mjd;
420 st.valid = true;
421 psiEff = psiNom;
[10946]422 }
423
424 return psiEff;
425}
426
[3052]427// Satellite Antenna Offset
428////////////////////////////////////////////////////////////////////////////
[7521]429t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
[10946]430 const ColumnVector& xSat,
431 const ColumnVector& vSat, ColumnVector& dx) {
[3055]432
[6405]433 t_frequency::type frqType = t_frequency::dummy;
[7145]434
[6405]435 if (prn[0] == 'G') {
436 frqType = t_frequency::G1;
437 }
438 else if (prn[0] == 'R') {
439 frqType = t_frequency::R1;
440 }
[9481]441 else if (prn[0] == 'E') {
442 frqType = t_frequency::E1;
443 }
444 else if (prn[0] == 'C') {
445 frqType = t_frequency::C2;
446 }
447 else if (prn[0] == 'S') {
448 frqType = t_frequency::S1;
449 }
450 else if (prn[0] == 'J') {
451 frqType = t_frequency::J1;
452 }
453 else if (prn[0] == 'I') {
454 frqType = t_frequency::I5;
455 }
[6405]456
[6971]457 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
[3052]458 if (it != _maps.end()) {
459 t_antMap* map = it.value();
[6405]460 if (map->frqMap.find(frqType) != map->frqMap.end()) {
[3055]461
[6405]462 double* neu = map->frqMap[frqType]->neu;
[3055]463
[6405]464 // Unit Vectors sz, sy, sx
465 // -----------------------
466 ColumnVector sz = -xSat;
467 sz /= sqrt(DotProduct(sz,sz));
468
469 ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
470 xSun /= sqrt(DotProduct(xSun,xSun));
[7521]471
[10946]472 ColumnVector sy, sx;
[7521]473
[10946]474 // GLONASS: override the nominal Sun-pointing attitude near the
475 // orbit noon/midnight points when the beta angle is small (see
476 // glonassYawAngle() above). Elsewhere GLONASS-M follows the same
477 // nominal law as the other constellations, so the result is
478 // identical to the direct Sun-pointing computation used below.
479 // -----------------------------------------------------------------
480 if (prn[0] == 'R' && vSat.size() == 3) {
[10947]481 double psi = glonassYawAngle(prn, Mjd, xSat, vSat, xSun);
[3055]482
[10946]483 ColumnVector vInert = vSat;
484 ColumnVector Omega(3); Omega(1) = 0.0; Omega(2) = 0.0; Omega(3) = t_CST::omega;
485 vInert += crossproduct(Omega, xSat);
486
487 ColumnVector sy0 = crossproduct(sz, vInert);
488 sy0 /= sqrt(DotProduct(sy0,sy0));
489 ColumnVector sx0 = crossproduct(sy0, sz);
490
491 // Rodrigues rotation of (sx0, sy0) around sz by angle psi
492 double cosY = cos(psi);
493 double sinY = sin(psi);
494 sx = sx0 * cosY + crossproduct(sz, sx0) * sinY;
495 sy = sy0 * cosY + crossproduct(sz, sy0) * sinY;
496 }
497 else {
498 sy = crossproduct(sz, xSun);
499 sy /= sqrt(DotProduct(sy,sy));
500 sx = crossproduct(sy, sz);
501 }
502
[6405]503 dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
504 dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
505 dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
[3055]506
[6405]507 return success;
508 }
[3052]509 }
[6405]510
511 return failure;
[3052]512}
513
[7521]514//
[2894]515////////////////////////////////////////////////////////////////////////////
[9481]516double bncAntex::satCorr(const QString& prn, t_frequency::type frqType,
517 double elTx, double azTx, bool& found) const {
518
519 if (_maps.find(prn.mid(0,3)) == _maps.end()) {
520 found = false;
521 return 0.0;
522 };
523
524 t_antMap* map = _maps[prn.mid(0,3)];
525
526 if (map->frqMap.find(frqType) == map->frqMap.end()) {
527 found = false;
528 return 0.0;
529 };
530
531 t_frqMap* frqMap = map->frqMap[frqType];
532
533 double var = 0.0;
534 if (frqMap->pattern.ncols() > 0) {
535 double zenDiff = 999.999;
536 double zenTx = 90.0 - elTx * 180.0 / M_PI;
537 unsigned iZen = 0;
538 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
539 iZen += 1;
540 double newZenDiff = fabs(zen - zenTx);
541 if (newZenDiff < zenDiff) {
542 zenDiff = newZenDiff;
543 var = frqMap->pattern(iZen);
544 }
545 }
546 }
547
548 found = true;
549 return var - frqMap->neu[0] * cos(azTx)*cos(elTx)
550 - frqMap->neu[1] * sin(azTx)*cos(elTx)
551 - frqMap->neu[2] * sin(elTx);
552
553}
554
555//
556////////////////////////////////////////////////////////////////////////////
[6405]557double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
[6694]558 double eleSat, double azSat, bool& found) const {
[2894]559
[6405]560 if (antName.find("NULLANTENNA") != string::npos) {
[2938]561 found = true;
[6405]562 return 0.0;
[2894]563 }
[6405]564
565 QString antNameQ = antName.c_str();
566
567 if (_maps.find(antNameQ) == _maps.end()) {
[2938]568 found = false;
[6405]569 return 0.0;
[2938]570 }
[2894]571
[6405]572 t_antMap* map = _maps[antNameQ];
573 if (map->frqMap.find(frqType) == map->frqMap.end()) {
574 found = false;
575 return 0.0;
576 }
577
578 t_frqMap* frqMap = map->frqMap[frqType];
579
580 double var = 0.0;
581 if (frqMap->pattern.ncols() > 0) {
582 double zenDiff = 999.999;
583 double zenSat = 90.0 - eleSat * 180.0 / M_PI;
584 unsigned iZen = 0;
585 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
586 iZen += 1;
587 double newZenDiff = fabs(zen - zenSat);
588 if (newZenDiff < zenDiff) {
589 zenDiff = newZenDiff;
590 var = frqMap->pattern(iZen);
591 }
592 }
593 }
594
595 found = true;
[6694]596 return var - frqMap->neu[0] * cos(azSat)*cos(eleSat)
597 - frqMap->neu[1] * sin(azSat)*cos(eleSat)
598 - frqMap->neu[2] * sin(eleSat);
599
[5755]600}
Note: See TracBrowser for help on using the repository browser.