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

Last change on this file since 10946 was 10946, checked in by stuerze, 8 weeks ago

added GLONASS-M yaw-fixed attitude model for the APC/CoM offset applied when saving SP3 files, reducing along-track/cross-track errors near the orbit noon/midnight points

File size: 18.3 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: bncAntex
30 *
31 * Purpose: Antenna Phase Centers and Variations from ANTEX File
32 *
33 * Author: L. Mervart
34 *
35 * Created: 26-Jan-2011
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <cmath>
43#include <newmatio.h>
44
45#include "bncantex.h"
46#include "pppModel.h"
47
48using namespace std;
49
50// Constructor
51////////////////////////////////////////////////////////////////////////////
52bncAntex::bncAntex() {
53}
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
57bncAntex::bncAntex(const char* fileName) {
58 readFile(QString(fileName));//print();
59}
60
61// Destructor
62////////////////////////////////////////////////////////////////////////////
63bncAntex::~bncAntex() {
64 QMapIterator<QString, t_antMap*> it(_maps);
65 while (it.hasNext()) {
66 it.next();
67 delete it.value();
68 }
69 _maps.clear();
70}
71
72// Print
73////////////////////////////////////////////////////////////////////////////
74void bncAntex::print() const {
75 QMapIterator<QString, t_antMap*> itAnt(_maps);
76 while (itAnt.hasNext()) {
77 itAnt.next();
78 t_antMap* map = itAnt.value();
79 cout << map->antName.toLatin1().data() << endl;
80 cout << " " << map->zen1 << " " << map->zen2 << " " << map->dZen << endl;
81 QMapIterator<t_frequency::type, t_frqMap*> itFrq(map->frqMap);
82 while (itFrq.hasNext()) {
83 itFrq.next();
84 const t_frqMap* frqMap = itFrq.value();
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();
90 }
91 cout << endl;
92 }
93}
94
95// Print
96////////////////////////////////////////////////////////////////////////////
97QString bncAntex::pcoSinexString(const std::string& antName, t_frequency::type frqType) {
98
99 if (antName.find("NULLANTENNA") != string::npos) {
100 return QString(" ------ ------ ------");
101 }
102
103 QString antNameQ = antName.c_str();
104 if (_maps.find(antNameQ) == _maps.end()) {
105 return QString(" ------ ------ ------");
106 }
107
108 t_antMap* map = _maps[antNameQ];
109 if (map->frqMap.find(frqType) == map->frqMap.end()) {
110 return QString(" ------ ------ ------");
111 }
112
113 t_frqMap* frqMap = map->frqMap[frqType];
114
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);}
118
119 return QString(" %1 %2 %3").arg(u).arg(n).arg(e);
120}
121
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
139// Read ANTEX File
140////////////////////////////////////////////////////////////////////////////
141t_irc bncAntex::readFile(const QString& fileName) {
142
143 QFile inFile(fileName);
144 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
145
146 QTextStream in(&inFile);
147
148 t_antMap* newAntMap = 0;
149 t_frqMap* newFrqMap = 0;
150
151 while ( !in.atEnd() ) {
152 QString line = in.readLine();
153
154 // Start of Antenna
155 // ----------------
156 if (line.indexOf("START OF ANTENNA") == 60) {
157 if (newAntMap) {
158 delete newAntMap;
159 return failure;
160 }
161 else {
162 delete newAntMap;
163 newAntMap = new t_antMap();
164 }
165 }
166
167 // End of Antenna
168 // --------------
169 else if (line.indexOf("END OF ANTENNA") == 60) {
170 if (newAntMap) {
171 if (_maps.contains(newAntMap->antName)) {
172 delete _maps[newAntMap->antName];
173 }
174 _maps[newAntMap->antName] = newAntMap;
175 newAntMap = 0;
176 }
177 else {
178 delete newAntMap;
179 return failure;
180 }
181 }
182
183 // Antenna Reading in Progress
184 // ---------------------------
185 else if (newAntMap) {
186 if (line.indexOf("TYPE / SERIAL NO") == 60) {
187 if (line.indexOf("BLOCK I") == 0 ||
188 line.indexOf("GLONASS") == 0 ||
189 line.indexOf("QZSS") == 0 ||
190 line.indexOf("BEIDOU") == 0 ||
191 line.indexOf("GALILEO") == 0 ||
192 line.indexOf("NavIC") == 0 ){
193 newAntMap->antName = line.mid(20,3);
194 }
195 else {
196 newAntMap->antName = line.mid(0,20);
197 }
198 }
199 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
200 QTextStream inLine(&line, QIODevice::ReadOnly);
201 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
202 }
203 else if (line.indexOf("SINEX CODE") == 60) {
204 QTextStream inLine(&line, QIODevice::ReadOnly);
205 inLine >> newAntMap->snxCode;
206 }
207
208 // Start of Frequency
209 // ------------------
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
221 // End of Frequency
222 // ----------------
223 else if (line.indexOf("END OF FREQUENCY") == 60) {
224 if (newFrqMap) {
225 t_frequency::type frqType = t_frequency::dummy;
226 // GPS
227 if (line.indexOf("G01") == 3) {
228 frqType = t_frequency::G1;
229 }
230 else if (line.indexOf("G02") == 3) {
231 frqType = t_frequency::G2;
232 }
233 else if (line.indexOf("G05") == 3) {
234 frqType = t_frequency::G5;
235 }
236 // GLONASS
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 }
243 // Galileo
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 }
259 // QZSS
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 }
272 // BDS
273 else if (line.indexOf("C01") == 3) {
274 frqType = t_frequency::C1;
275 }
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 }
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 }
291 else {
292 delete newFrqMap;
293 }
294 newFrqMap = 0;
295 }
296 else {
297 delete newAntMap;
298 return failure;
299 }
300 }
301
302 // Frequency Reading in Progress
303 // -----------------------------
304 else if (newFrqMap) {
305 if (line.indexOf("NORTH / EAST / UP") == 60) {
306 QTextStream inLine(&line, QIODevice::ReadOnly);
307 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
308 newFrqMap->neu[0] *= 1e-3;
309 newFrqMap->neu[1] *= 1e-3;
310 newFrqMap->neu[2] *= 1e-3;
311 }
312 else if (line.indexOf("NOAZI") == 3) {
313 QTextStream inLine(&line, QIODevice::ReadOnly);
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 }
321 newFrqMap->pattern *= 1e-3;
322 }
323 }
324 }
325 }
326 inFile.close();
327 delete newFrqMap;
328 delete newAntMap;
329
330 return success;
331}
332
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////////////////////////////////////////////////////////////////////////////
351double bncAntex::glonassYawAngle(const QString& prn, const ColumnVector& xSat,
352 const ColumnVector& vSat,
353 const ColumnVector& xSun) {
354
355 const double MAX_YAW_RATE = 0.25 * M_PI / 180.0; // [rad/s], approximate
356
357 // Inertial-consistent velocity (xSat, vSat are Earth-fixed; remove the
358 // Earth-rotation contribution so that the orbit normal below is not
359 // contaminated by it)
360 // -------------------------------------------------------------------
361 ColumnVector Omega(3); Omega(1) = 0.0; Omega(2) = 0.0; Omega(3) = t_CST::omega;
362 ColumnVector vInert = vSat + crossproduct(Omega, xSat);
363
364 // Orbit normal and instantaneous orbital rate from r x v (exact, valid
365 // for any Keplerian orbit, not just circular ones)
366 // ---------------------------------------------------------------------
367 ColumnVector h = crossproduct(xSat, vInert);
368 double hNorm = sqrt(DotProduct(h, h));
369 ColumnVector orbNormal = h / hNorm;
370 double r = sqrt(DotProduct(xSat, xSat));
371 double nRate = hNorm / (r * r); // [rad/s]
372
373 // Beta angle (Sun elevation above the orbital plane)
374 // ----------------------------------------------------
375 double beta = asin(DotProduct(orbNormal, xSun));
376
377 // Orbit angle mu, measured from the orbit midnight point, increasing in
378 // the direction of satellite motion
379 // -----------------------------------------------------------------------
380 ColumnVector sunProj = xSun - DotProduct(xSun, orbNormal) * orbNormal;
381 sunProj /= sqrt(DotProduct(sunProj, sunProj));
382 ColumnVector eX = -1.0 * sunProj; // midnight direction, mu = 0
383 ColumnVector eY = crossproduct(orbNormal, eX);
384 ColumnVector rHat = xSat / r;
385 double mu = atan2(DotProduct(rHat, eY), DotProduct(rHat, eX));
386
387 // Nominal Sun-pointing yaw angle and its rate (Bar-Sever 1996)
388 // ----------------------------------------------------------------
389 double tanBeta = tan(beta);
390 double sinMu = sin(mu);
391 double psiNom = atan2(-tanBeta, sinMu);
392 double denom = tanBeta * tanBeta + sinMu * sinMu;
393 double psiRate = (denom > 1e-12)
394 ? nRate * fabs(tanBeta * cos(mu)) / denom
395 : 1e9;
396
397 t_glonassYaw& st = _glonassYaw[prn];
398 double psiEff;
399 if (psiRate > MAX_YAW_RATE) {
400 if (!st.valid) {
401 st.yaw = psiNom; // no prior history - best available estimate
402 }
403 psiEff = st.yaw; // hold the frozen yaw angle
404 }
405 else {
406 st.yaw = psiNom;
407 st.valid = true;
408 psiEff = psiNom;
409 }
410
411 return psiEff;
412}
413
414// Satellite Antenna Offset
415////////////////////////////////////////////////////////////////////////////
416t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
417 const ColumnVector& xSat,
418 const ColumnVector& vSat, ColumnVector& dx) {
419
420 t_frequency::type frqType = t_frequency::dummy;
421
422 if (prn[0] == 'G') {
423 frqType = t_frequency::G1;
424 }
425 else if (prn[0] == 'R') {
426 frqType = t_frequency::R1;
427 }
428 else if (prn[0] == 'E') {
429 frqType = t_frequency::E1;
430 }
431 else if (prn[0] == 'C') {
432 frqType = t_frequency::C2;
433 }
434 else if (prn[0] == 'S') {
435 frqType = t_frequency::S1;
436 }
437 else if (prn[0] == 'J') {
438 frqType = t_frequency::J1;
439 }
440 else if (prn[0] == 'I') {
441 frqType = t_frequency::I5;
442 }
443
444 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
445 if (it != _maps.end()) {
446 t_antMap* map = it.value();
447 if (map->frqMap.find(frqType) != map->frqMap.end()) {
448
449 double* neu = map->frqMap[frqType]->neu;
450
451 // Unit Vectors sz, sy, sx
452 // -----------------------
453 ColumnVector sz = -xSat;
454 sz /= sqrt(DotProduct(sz,sz));
455
456 ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
457 xSun /= sqrt(DotProduct(xSun,xSun));
458
459 ColumnVector sy, sx;
460
461 // GLONASS: override the nominal Sun-pointing attitude near the
462 // orbit noon/midnight points when the beta angle is small (see
463 // glonassYawAngle() above). Elsewhere GLONASS-M follows the same
464 // nominal law as the other constellations, so the result is
465 // identical to the direct Sun-pointing computation used below.
466 // -----------------------------------------------------------------
467 if (prn[0] == 'R' && vSat.size() == 3) {
468 double psi = glonassYawAngle(prn, xSat, vSat, xSun);
469
470 ColumnVector vInert = vSat;
471 ColumnVector Omega(3); Omega(1) = 0.0; Omega(2) = 0.0; Omega(3) = t_CST::omega;
472 vInert += crossproduct(Omega, xSat);
473
474 ColumnVector sy0 = crossproduct(sz, vInert);
475 sy0 /= sqrt(DotProduct(sy0,sy0));
476 ColumnVector sx0 = crossproduct(sy0, sz);
477
478 // Rodrigues rotation of (sx0, sy0) around sz by angle psi
479 double cosY = cos(psi);
480 double sinY = sin(psi);
481 sx = sx0 * cosY + crossproduct(sz, sx0) * sinY;
482 sy = sy0 * cosY + crossproduct(sz, sy0) * sinY;
483 }
484 else {
485 sy = crossproduct(sz, xSun);
486 sy /= sqrt(DotProduct(sy,sy));
487 sx = crossproduct(sy, sz);
488 }
489
490 dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
491 dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
492 dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
493
494 return success;
495 }
496 }
497
498 return failure;
499}
500
501//
502////////////////////////////////////////////////////////////////////////////
503double bncAntex::satCorr(const QString& prn, t_frequency::type frqType,
504 double elTx, double azTx, bool& found) const {
505
506 if (_maps.find(prn.mid(0,3)) == _maps.end()) {
507 found = false;
508 return 0.0;
509 };
510
511 t_antMap* map = _maps[prn.mid(0,3)];
512
513 if (map->frqMap.find(frqType) == map->frqMap.end()) {
514 found = false;
515 return 0.0;
516 };
517
518 t_frqMap* frqMap = map->frqMap[frqType];
519
520 double var = 0.0;
521 if (frqMap->pattern.ncols() > 0) {
522 double zenDiff = 999.999;
523 double zenTx = 90.0 - elTx * 180.0 / M_PI;
524 unsigned iZen = 0;
525 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
526 iZen += 1;
527 double newZenDiff = fabs(zen - zenTx);
528 if (newZenDiff < zenDiff) {
529 zenDiff = newZenDiff;
530 var = frqMap->pattern(iZen);
531 }
532 }
533 }
534
535 found = true;
536 return var - frqMap->neu[0] * cos(azTx)*cos(elTx)
537 - frqMap->neu[1] * sin(azTx)*cos(elTx)
538 - frqMap->neu[2] * sin(elTx);
539
540}
541
542//
543////////////////////////////////////////////////////////////////////////////
544double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
545 double eleSat, double azSat, bool& found) const {
546
547 if (antName.find("NULLANTENNA") != string::npos) {
548 found = true;
549 return 0.0;
550 }
551
552 QString antNameQ = antName.c_str();
553
554 if (_maps.find(antNameQ) == _maps.end()) {
555 found = false;
556 return 0.0;
557 }
558
559 t_antMap* map = _maps[antNameQ];
560 if (map->frqMap.find(frqType) == map->frqMap.end()) {
561 found = false;
562 return 0.0;
563 }
564
565 t_frqMap* frqMap = map->frqMap[frqType];
566
567 double var = 0.0;
568 if (frqMap->pattern.ncols() > 0) {
569 double zenDiff = 999.999;
570 double zenSat = 90.0 - eleSat * 180.0 / M_PI;
571 unsigned iZen = 0;
572 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
573 iZen += 1;
574 double newZenDiff = fabs(zen - zenSat);
575 if (newZenDiff < zenDiff) {
576 zenDiff = newZenDiff;
577 var = frqMap->pattern(iZen);
578 }
579 }
580 }
581
582 found = true;
583 return var - frqMap->neu[0] * cos(azSat)*cos(eleSat)
584 - frqMap->neu[1] * sin(azSat)*cos(eleSat)
585 - frqMap->neu[2] * sin(eleSat);
586
587}
Note: See TracBrowser for help on using the repository browser.