source: ntrip/trunk/BNC/RTCM3/ephemeris.cpp@ 3263

Last change on this file since 3263 was 3263, checked in by mervart, 13 years ago
File size: 20.3 KB
Line 
1#include <math.h>
2#include <sstream>
3#include <iostream>
4#include <iomanip>
5#include <cstring>
6
7#include <newmatio.h>
8
9#include "ephemeris.h"
10#include "bncutils.h"
11#include "timeutils.h"
12#include "bnctime.h"
13
14using namespace std;
15
16#define PI 3.1415926535898
17// Returns nearest integer value
18////////////////////////////////////////////////////////////////////////////
19static double NearestInt(double fl, double * remain)
20{
21 bool isneg = fl < 0.0;
22 double intval;
23 if(isneg) fl *= -1.0;
24 intval = (double)((unsigned long)(fl+0.5));
25 if(isneg) {fl *= -1.0; intval *= -1.0;}
26 if(remain)
27 *remain = fl-intval;
28 return intval;
29} /* NearestInt() */
30
31// Returns CRC24
32////////////////////////////////////////////////////////////////////////////
33static unsigned long CRC24(long size, const unsigned char *buf)
34{
35 unsigned long crc = 0;
36 int i;
37
38 while(size--)
39 {
40 crc ^= (*buf++) << (16);
41 for(i = 0; i < 8; i++)
42 {
43 crc <<= 1;
44 if(crc & 0x1000000)
45 crc ^= 0x01864cfb;
46 }
47 }
48 return crc;
49} /* CRC24 */
50
51//
52////////////////////////////////////////////////////////////////////////////
53bool t_eph::isNewerThan(const t_eph* eph) const {
54 if (_GPSweek > eph->_GPSweek ||
55 (_GPSweek == eph->_GPSweek && _GPSweeks > eph->_GPSweeks)) {
56 return true;
57 }
58 else {
59 return false;
60 }
61}
62
63// Set GPS Satellite Position
64////////////////////////////////////////////////////////////////////////////
65void t_ephGPS::set(const gpsephemeris* ee) {
66
67 _prn = QString("G%1").arg(ee->satellite, 2, 10, QChar('0'));
68
69 // TODO: check if following two lines are correct
70 _GPSweek = ee->GPSweek;
71 _GPSweeks = ee->TOE;
72
73 _TOW = ee->TOW;
74 _TOC = ee->TOC;
75 _TOE = ee->TOE;
76 _IODE = ee->IODE;
77 _IODC = ee->IODC;
78
79 _clock_bias = ee->clock_bias ;
80 _clock_drift = ee->clock_drift ;
81 _clock_driftrate = ee->clock_driftrate;
82
83 _Crs = ee->Crs;
84 _Delta_n = ee->Delta_n;
85 _M0 = ee->M0;
86 _Cuc = ee->Cuc;
87 _e = ee->e;
88 _Cus = ee->Cus;
89 _sqrt_A = ee->sqrt_A;
90 _Cic = ee->Cic;
91 _OMEGA0 = ee->OMEGA0;
92 _Cis = ee->Cis;
93 _i0 = ee->i0;
94 _Crc = ee->Crc;
95 _omega = ee->omega;
96 _OMEGADOT = ee->OMEGADOT;
97 _IDOT = ee->IDOT;
98
99 _TGD = ee->TGD;
100}
101
102// Compute GPS Satellite Position (virtual)
103////////////////////////////////////////////////////////////////////////////
104void t_ephGPS::position(int GPSweek, double GPSweeks,
105 double* xc,
106 double* vv) const {
107
108 static const double secPerWeek = 7 * 86400.0;
109 static const double omegaEarth = 7292115.1467e-11;
110 static const double gmWGS = 398.6005e12;
111
112 memset(xc, 0, 4*sizeof(double));
113 memset(vv, 0, 3*sizeof(double));
114
115 double a0 = _sqrt_A * _sqrt_A;
116 if (a0 == 0) {
117 return;
118 }
119
120 double n0 = sqrt(gmWGS/(a0*a0*a0));
121 double tk = GPSweeks - _TOE;
122 if (GPSweek != _GPSweek) {
123 tk += (GPSweek - _GPSweek) * secPerWeek;
124 }
125 double n = n0 + _Delta_n;
126 double M = _M0 + n*tk;
127 double E = M;
128 double E_last;
129 do {
130 E_last = E;
131 E = M + _e*sin(E);
132 } while ( fabs(E-E_last)*a0 > 0.001 );
133 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
134 double u0 = v + _omega;
135 double sin2u0 = sin(2*u0);
136 double cos2u0 = cos(2*u0);
137 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
138 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
139 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
140 double xp = r*cos(u);
141 double yp = r*sin(u);
142 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
143 omegaEarth*_TOE;
144
145 double sinom = sin(OM);
146 double cosom = cos(OM);
147 double sini = sin(i);
148 double cosi = cos(i);
149 xc[0] = xp*cosom - yp*cosi*sinom;
150 xc[1] = xp*sinom + yp*cosi*cosom;
151 xc[2] = yp*sini;
152
153 double tc = GPSweeks - _TOC;
154 if (GPSweek != _GPSweek) {
155 tc += (GPSweek - _GPSweek) * secPerWeek;
156 }
157 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
158
159 // Velocity
160 // --------
161 double tanv2 = tan(v/2);
162 double dEdM = 1 / (1 - _e*cos(E));
163 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
164 * dEdM * n;
165 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
166 double dotom = _OMEGADOT - omegaEarth;
167 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
168 double dotr = a0 * _e*sin(E) * dEdM * n
169 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
170 double dotx = dotr*cos(u) - r*sin(u)*dotu;
171 double doty = dotr*sin(u) + r*cos(u)*dotu;
172
173 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
174 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
175 + yp*sini*sinom*doti; // dX / di
176
177 vv[1] = sinom *dotx + cosi*cosom *doty
178 + xp*cosom*dotom - yp*cosi*sinom*dotom
179 - yp*sini*cosom*doti;
180
181 vv[2] = sini *doty + yp*cosi *doti;
182
183 // Relativistic Correction
184 // -----------------------
185 // xc(4) -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
186 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
187}
188
189// build up RTCM3 for GPS
190////////////////////////////////////////////////////////////////////////////
191#define GPSTOINT(type, value) static_cast<type>(NearestInt(value,0))
192
193#define GPSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
194 |(GPSTOINT(long long,b)&((1ULL<<a)-1)); \
195 numbits += (a); \
196 while(numbits >= 8) { \
197 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
198#define GPSADDBITSFLOAT(a,b,c) {long long i = GPSTOINT(long long,(b)/(c)); \
199 GPSADDBITS(a,i)};
200
201int t_ephGPS::RTCM3(unsigned char *buffer)
202{
203
204 unsigned char *startbuffer = buffer;
205 buffer= buffer+3;
206 int size = 0;
207 int numbits = 0;
208 unsigned long long bitbuffer = 0;
209 if (_ura <= 2.40){
210 _ura = 0;
211 }
212 else if (_ura <= 3.40){
213 _ura = 1;
214 }
215 else if (_ura <= 6.85){
216 _ura = 2;
217 }
218 else if (_ura <= 9.65){
219 _ura = 3;
220 }
221 else if (_ura <= 13.65){
222 _ura = 4;
223 }
224 else if (_ura <= 24.00){
225 _ura = 5;
226 }
227 else if (_ura <= 48.00){
228 _ura = 6;
229 }
230 else if (_ura <= 96.00){
231 _ura = 7;
232 }
233 else if (_ura <= 192.00){
234 _ura = 8;
235 }
236 else if (_ura <= 384.00){
237 _ura = 9;
238 }
239 else if (_ura <= 768.00){
240 _ura = 10;
241 }
242 else if (_ura <= 1536.00){
243 _ura = 11;
244 }
245 else if (_ura <= 1536.00){
246 _ura = 12;
247 }
248 else if (_ura <= 2072.00){
249 _ura = 13;
250 }
251 else if (_ura <= 6144.00){
252 _ura = 14;
253 }
254 else{
255 _ura = 15;
256 }
257
258 GPSADDBITS(12, 1019)
259 GPSADDBITS(6,_prn.right((_prn.length()-1)).toInt())
260 GPSADDBITS(10, _GPSweek)
261 GPSADDBITS(4, _ura)
262 GPSADDBITS(2,_L2Codes)
263 GPSADDBITSFLOAT(14, _IDOT, PI/static_cast<double>(1<<30)
264 /static_cast<double>(1<<13))
265 GPSADDBITS(8, _IODE)
266 GPSADDBITS(16, static_cast<int>(_TOC)>>4)
267 GPSADDBITSFLOAT(8, _clock_driftrate, 1.0/static_cast<double>(1<<30)
268 /static_cast<double>(1<<25))
269 GPSADDBITSFLOAT(16, _clock_drift, 1.0/static_cast<double>(1<<30)
270 /static_cast<double>(1<<13))
271 GPSADDBITSFLOAT(22, _clock_bias, 1.0/static_cast<double>(1<<30)
272 /static_cast<double>(1<<1))
273 GPSADDBITS(10, _IODC)
274 GPSADDBITSFLOAT(16, _Crs, 1.0/static_cast<double>(1<<5))
275 GPSADDBITSFLOAT(16, _Delta_n, PI/static_cast<double>(1<<30)
276 /static_cast<double>(1<<13))
277 GPSADDBITSFLOAT(32, _M0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
278 GPSADDBITSFLOAT(16, _Cuc, 1.0/static_cast<double>(1<<29))
279 GPSADDBITSFLOAT(32, _e, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<3))
280 GPSADDBITSFLOAT(16, _Cus, 1.0/static_cast<double>(1<<29))
281 GPSADDBITSFLOAT(32, _sqrt_A, 1.0/static_cast<double>(1<<19))
282 GPSADDBITS(16, static_cast<int>(_TOE)>>4)
283 GPSADDBITSFLOAT(16, _Cic, 1.0/static_cast<double>(1<<29))
284 GPSADDBITSFLOAT(32, _OMEGA0, PI/static_cast<double>(1<<30)
285 /static_cast<double>(1<<1))
286 GPSADDBITSFLOAT(16, _Cis, 1.0/static_cast<double>(1<<29))
287 GPSADDBITSFLOAT(32, _i0, PI/static_cast<double>(1<<30)/static_cast<double>(1<<1))
288 GPSADDBITSFLOAT(16, _Crc, 1.0/static_cast<double>(1<<5))
289 GPSADDBITSFLOAT(32, _omega, PI/static_cast<double>(1<<30)
290 /static_cast<double>(1<<1))
291 GPSADDBITSFLOAT(24, _OMEGADOT, PI/static_cast<double>(1<<30)
292 /static_cast<double>(1<<13))
293 GPSADDBITSFLOAT(8, _TGD, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
294 GPSADDBITS(6, _health)
295 GPSADDBITS(1, _L2PFlag)
296 GPSADDBITS(1, 0) /* GPS fit interval */
297
298 startbuffer[0]=0xD3;
299 startbuffer[1]=(size >> 8);
300 startbuffer[2]=size;
301 unsigned long i = CRC24(size+3, startbuffer);
302 buffer[size++] = i >> 16;
303 buffer[size++] = i >> 8;
304 buffer[size++] = i;
305 size += 3;
306 return size;
307}
308
309// Derivative of the state vector using a simple force model (static)
310////////////////////////////////////////////////////////////////////////////
311ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
312 double* acc) {
313
314 // State vector components
315 // -----------------------
316 ColumnVector rr = xv.rows(1,3);
317 ColumnVector vv = xv.rows(4,6);
318
319 // Acceleration
320 // ------------
321 static const double GM = 398.60044e12;
322 static const double AE = 6378136.0;
323 static const double OMEGA = 7292115.e-11;
324 static const double C20 = -1082.6257e-6;
325
326 double rho = rr.norm_Frobenius();
327 double t1 = -GM/(rho*rho*rho);
328 double t2 = 3.0/2.0 * C20 * (GM*AE*AE) / (rho*rho*rho*rho*rho);
329 double t3 = OMEGA * OMEGA;
330 double t4 = 2.0 * OMEGA;
331 double z2 = rr(3) * rr(3);
332
333 // Vector of derivatives
334 // ---------------------
335 ColumnVector va(6);
336 va(1) = vv(1);
337 va(2) = vv(2);
338 va(3) = vv(3);
339 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
340 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
341 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
342
343 return va;
344}
345
346// Compute Glonass Satellite Position (virtual)
347////////////////////////////////////////////////////////////////////////////
348void t_ephGlo::position(int GPSweek, double GPSweeks,
349 double* xc, double* vv) const {
350
351 static const double secPerWeek = 7 * 86400.0;
352 static const double nominalStep = 10.0;
353
354 memset(xc, 0, 4*sizeof(double));
355 memset(vv, 0, 3*sizeof(double));
356
357 double dtPos = GPSweeks - _tt;
358 if (GPSweek != _GPSweek) {
359 dtPos += (GPSweek - _GPSweek) * secPerWeek;
360 }
361
362 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
363 double step = dtPos / nSteps;
364
365 double acc[3];
366 acc[0] = _x_acceleration * 1.e3;
367 acc[1] = _y_acceleration * 1.e3;
368 acc[2] = _z_acceleration * 1.e3;
369 for (int ii = 1; ii <= nSteps; ii++) {
370 _xv = rungeKutta4(_tt, _xv, step, acc, glo_deriv);
371 _tt += step;
372 }
373
374 // Position and Velocity
375 // ---------------------
376 xc[0] = _xv(1);
377 xc[1] = _xv(2);
378 xc[2] = _xv(3);
379
380 vv[0] = _xv(4);
381 vv[1] = _xv(5);
382 vv[2] = _xv(6);
383
384 // Clock Correction
385 // ----------------
386 double dtClk = GPSweeks - _GPSweeks;
387 if (GPSweek != _GPSweek) {
388 dtClk += (GPSweek - _GPSweek) * secPerWeek;
389 }
390 xc[3] = -_tau + _gamma * dtClk;
391}
392
393// IOD of Glonass Ephemeris (virtual)
394////////////////////////////////////////////////////////////////////////////
395int t_ephGlo::IOD() const {
396
397 bool old = false;
398
399 if (old) { // 5 LSBs of iod are equal to 5 LSBs of tb
400 unsigned int tb = int(fmod(_GPSweeks,86400.0)); //sec of day
401 const int shift = sizeof(tb) * 8 - 5;
402 unsigned int iod = tb << shift;
403 return (iod >> shift);
404 }
405 else {
406 bncTime tGPS(_GPSweek, _GPSweeks);
407 int hlpWeek = _GPSweek;
408 int hlpSec = int(_GPSweeks);
409 int hlpMsec = int(_GPSweeks * 1000);
410 updatetime(&hlpWeek, &hlpSec, hlpMsec, 0);
411 bncTime tHlp(hlpWeek, hlpSec);
412 double diffSec = tGPS - tHlp;
413 bncTime tMoscow = tGPS + diffSec;
414 return int(tMoscow.daysec() / 900);
415 }
416}
417
418// Set Glonass Ephemeris
419////////////////////////////////////////////////////////////////////////////
420void t_ephGlo::set(const glonassephemeris* ee) {
421
422 _prn = QString("R%1").arg(ee->almanac_number, 2, 10, QChar('0'));
423
424 int ww = ee->GPSWeek;
425 int tow = ee->GPSTOW;
426 updatetime(&ww, &tow, ee->tb*1000, 0); // Moscow -> GPS
427
428 bncTime hlpTime(ww, (double) tow);
429 unsigned year, month, day;
430 hlpTime.civil_date(year, month, day);
431 _gps_utc = gnumleap(year, month, day);
432
433 _GPSweek = ww;
434 _GPSweeks = tow;
435 _E = ee->E;
436 _tau = ee->tau;
437 _gamma = ee->gamma;
438 _x_pos = ee->x_pos;
439 _x_velocity = ee->x_velocity;
440 _x_acceleration = ee->x_acceleration;
441 _y_pos = ee->y_pos;
442 _y_velocity = ee->y_velocity;
443 _y_acceleration = ee->y_acceleration;
444 _z_pos = ee->z_pos;
445 _z_velocity = ee->z_velocity;
446 _z_acceleration = ee->z_acceleration;
447 _health = 0;
448 _frequency_number = ee->frequency_number;
449 _tki = ee->tk-3*60*60; if (_tki < 0) _tki += 86400;
450
451 // Initialize status vector
452 // ------------------------
453 _tt = _GPSweeks;
454
455 _xv(1) = _x_pos * 1.e3;
456 _xv(2) = _y_pos * 1.e3;
457 _xv(3) = _z_pos * 1.e3;
458 _xv(4) = _x_velocity * 1.e3;
459 _xv(5) = _y_velocity * 1.e3;
460 _xv(6) = _z_velocity * 1.e3;
461}
462
463// build up RTCM3 for GLONASS
464////////////////////////////////////////////////////////////////////////////
465#define GLONASSTOINT(type, value) static_cast<type>(NearestInt(value,0))
466
467#define GLONASSADDBITS(a, b) {bitbuffer = (bitbuffer<<(a)) \
468 |(GLONASSTOINT(long long,b)&((1ULL<<(a))-1)); \
469 numbits += (a); \
470 while(numbits >= 8) { \
471 buffer[size++] = bitbuffer>>(numbits-8);numbits -= 8;}}
472#define GLONASSADDBITSFLOATM(a,b,c) {int s; long long i; \
473 if(b < 0.0) \
474 { \
475 s = 1; \
476 i = GLONASSTOINT(long long,(-b)/(c)); \
477 if(!i) s = 0; \
478 } \
479 else \
480 { \
481 s = 0; \
482 i = GLONASSTOINT(long long,(b)/(c)); \
483 } \
484 GLONASSADDBITS(1,s) \
485 GLONASSADDBITS(a-1,i)}
486
487int t_ephGlo::RTCM3(unsigned char *buffer)
488{
489
490 int size = 0;
491 int numbits = 0;
492 long long bitbuffer = 0;
493 unsigned char *startbuffer = buffer;
494 buffer= buffer+3;
495
496 GLONASSADDBITS(12, 1020)
497 GLONASSADDBITS(6, _prn.right((_prn.length()-1)).toInt())
498 GLONASSADDBITS(5, 7+_frequency_number)
499 GLONASSADDBITS(1, 0)
500 GLONASSADDBITS(1, 0)
501 GLONASSADDBITS(2, 0)
502 _tki=_tki+3*60*60;
503 GLONASSADDBITS(5, static_cast<int>(_tki)/(60*60))
504 GLONASSADDBITS(6, (static_cast<int>(_tki)/60)%60)
505 GLONASSADDBITS(1, (static_cast<int>(_tki)/30)%30)
506 GLONASSADDBITS(1, _health)
507 GLONASSADDBITS(1, 0)
508 unsigned long long timeofday = (static_cast<int>(_tt+3*60*60-_gps_utc)%86400);
509 GLONASSADDBITS(7, timeofday/60/15)
510 GLONASSADDBITSFLOATM(24, _x_velocity*1000, 1000.0/static_cast<double>(1<<20))
511 GLONASSADDBITSFLOATM(27, _x_pos*1000, 1000.0/static_cast<double>(1<<11))
512 GLONASSADDBITSFLOATM(5, _x_acceleration*1000, 1000.0/static_cast<double>(1<<30))
513 GLONASSADDBITSFLOATM(24, _y_velocity*1000, 1000.0/static_cast<double>(1<<20))
514 GLONASSADDBITSFLOATM(27, _y_pos*1000, 1000.0/static_cast<double>(1<<11))
515 GLONASSADDBITSFLOATM(5, _y_acceleration*1000, 1000.0/static_cast<double>(1<<30))
516 GLONASSADDBITSFLOATM(24, _z_velocity*1000, 1000.0/static_cast<double>(1<<20))
517 GLONASSADDBITSFLOATM(27,_z_pos*1000, 1000.0/static_cast<double>(1<<11))
518 GLONASSADDBITSFLOATM(5, _z_acceleration*1000, 1000.0/static_cast<double>(1<<30))
519 GLONASSADDBITS(1, 0)
520 GLONASSADDBITSFLOATM(11, _gamma, 1.0/static_cast<double>(1<<30)
521 /static_cast<double>(1<<10))
522 GLONASSADDBITS(2, 0) /* GLONASS-M P */
523 GLONASSADDBITS(1, 0) /* GLONASS-M ln(3) */
524 GLONASSADDBITSFLOATM(22, _tau, 1.0/static_cast<double>(1<<30))
525 GLONASSADDBITS(5, 0) /* GLONASS-M delta tau */
526 GLONASSADDBITS(5, _E)
527 GLONASSADDBITS(1, 0) /* GLONASS-M P4 */
528 GLONASSADDBITS(4, 0) /* GLONASS-M FT */
529 GLONASSADDBITS(11, 0) /* GLONASS-M NT */
530 GLONASSADDBITS(2, 0) /* GLONASS-M active? */
531 GLONASSADDBITS(1, 0) /* GLONASS additional data */
532 GLONASSADDBITS(11, 0) /* GLONASS NA */
533 GLONASSADDBITS(32, 0) /* GLONASS tau C */
534 GLONASSADDBITS(5, 0) /* GLONASS-M N4 */
535 GLONASSADDBITS(22, 0) /* GLONASS-M tau GPS */
536 GLONASSADDBITS(1, 0) /* GLONASS-M ln(5) */
537 GLONASSADDBITS(7, 0) /* Reserved */
538
539 startbuffer[0]=0xD3;
540 startbuffer[1]=(size >> 8);
541 startbuffer[2]=size;
542 unsigned long i = CRC24(size+3, startbuffer);
543 buffer[size++] = i >> 16;
544 buffer[size++] = i >> 8;
545 buffer[size++] = i;
546 size += 3;
547 return size;
548}
549
550// Set Galileo Satellite Position
551////////////////////////////////////////////////////////////////////////////
552void t_ephGal::set(const galileoephemeris* ee) {
553
554 _prn = QString("E%1").arg(ee->satellite, 2, 10, QChar('0'));
555
556 _GPSweek = ee->Week;
557 _GPSweeks = ee->TOE;
558
559 _TOC = ee->TOC;
560 _TOE = ee->TOE;
561 _IODnav = ee->IODnav;
562
563 _clock_bias = ee->clock_bias ;
564 _clock_drift = ee->clock_drift ;
565 _clock_driftrate = ee->clock_driftrate;
566
567 _Crs = ee->Crs;
568 _Delta_n = ee->Delta_n;
569 _M0 = ee->M0;
570 _Cuc = ee->Cuc;
571 _e = ee->e;
572 _Cus = ee->Cus;
573 _sqrt_A = ee->sqrt_A;
574 _Cic = ee->Cic;
575 _OMEGA0 = ee->OMEGA0;
576 _Cis = ee->Cis;
577 _i0 = ee->i0;
578 _Crc = ee->Crc;
579 _omega = ee->omega;
580 _OMEGADOT = ee->OMEGADOT;
581 _IDOT = ee->IDOT;
582}
583
584// Compute Galileo Satellite Position (virtual)
585////////////////////////////////////////////////////////////////////////////
586void t_ephGal::position(int GPSweek, double GPSweeks,
587 double* xc,
588 double* vv) const {
589
590 static const double secPerWeek = 7 * 86400.0;
591 static const double omegaEarth = 7292115.1467e-11;
592 static const double gmWGS = 398.6005e12;
593
594 memset(xc, 0, 4*sizeof(double));
595 memset(vv, 0, 3*sizeof(double));
596
597 double a0 = _sqrt_A * _sqrt_A;
598 if (a0 == 0) {
599 return;
600 }
601
602 double n0 = sqrt(gmWGS/(a0*a0*a0));
603 double tk = GPSweeks - _TOE;
604 if (GPSweek != _GPSweek) {
605 tk += (GPSweek - _GPSweek) * secPerWeek;
606 }
607 double n = n0 + _Delta_n;
608 double M = _M0 + n*tk;
609 double E = M;
610 double E_last;
611 do {
612 E_last = E;
613 E = M + _e*sin(E);
614 } while ( fabs(E-E_last)*a0 > 0.001 );
615 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
616 double u0 = v + _omega;
617 double sin2u0 = sin(2*u0);
618 double cos2u0 = cos(2*u0);
619 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
620 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
621 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
622 double xp = r*cos(u);
623 double yp = r*sin(u);
624 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
625 omegaEarth*_TOE;
626
627 double sinom = sin(OM);
628 double cosom = cos(OM);
629 double sini = sin(i);
630 double cosi = cos(i);
631 xc[0] = xp*cosom - yp*cosi*sinom;
632 xc[1] = xp*sinom + yp*cosi*cosom;
633 xc[2] = yp*sini;
634
635 double tc = GPSweeks - _TOC;
636 if (GPSweek != _GPSweek) {
637 tc += (GPSweek - _GPSweek) * secPerWeek;
638 }
639 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
640
641 // Velocity
642 // --------
643 double tanv2 = tan(v/2);
644 double dEdM = 1 / (1 - _e*cos(E));
645 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
646 * dEdM * n;
647 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
648 double dotom = _OMEGADOT - omegaEarth;
649 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
650 double dotr = a0 * _e*sin(E) * dEdM * n
651 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
652 double dotx = dotr*cos(u) - r*sin(u)*dotu;
653 double doty = dotr*sin(u) + r*cos(u)*dotu;
654
655 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
656 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
657 + yp*sini*sinom*doti; // dX / di
658
659 vv[1] = sinom *dotx + cosi*cosom *doty
660 + xp*cosom*dotom - yp*cosi*sinom*dotom
661 - yp*sini*cosom*doti;
662
663 vv[2] = sini *doty + yp*cosi *doti;
664
665 // Relativistic Correction
666 // -----------------------
667 // xc(4) -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
668 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
669}
670
671// build up RTCM3 for Galileo
672////////////////////////////////////////////////////////////////////////////
673int t_ephGal::RTCM3(unsigned char *buffer) {
674
675 return 0;
676}
Note: See TracBrowser for help on using the repository browser.