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

Last change on this file since 2222 was 2222, checked in by mervart, 14 years ago

* empty log message *

File size: 6.8 KB
Line 
1#include <math.h>
2#include <sstream>
3#include <iomanip>
4#include <cstring>
5
6#include "ephemeris.h"
7#include "bncutils.h"
8#include "timeutils.h"
9
10using namespace std;
11
12//
13////////////////////////////////////////////////////////////////////////////
14bool t_eph::isNewerThan(const t_eph* eph) const {
15 if (_GPSweek > eph->_GPSweek ||
16 (_GPSweek == eph->_GPSweek && _GPSweeks > eph->_GPSweeks)) {
17 return true;
18 }
19 else {
20 return false;
21 }
22}
23
24// Set GPS Satellite Position
25////////////////////////////////////////////////////////////////////////////
26void t_ephGPS::set(const gpsephemeris* ee) {
27 ostringstream prn;
28 prn << 'G' << setfill('0') << setw(2) << ee->satellite;
29
30 _prn = prn.str();
31
32 // TODO: check if following two lines are correct
33 _GPSweek = ee->GPSweek;
34 _GPSweeks = ee->TOE;
35
36 _TOW = ee->TOW;
37 _TOC = ee->TOC;
38 _TOE = ee->TOE;
39 _IODE = ee->IODE;
40 _IODC = ee->IODC;
41
42 _clock_bias = ee->clock_bias ;
43 _clock_drift = ee->clock_drift ;
44 _clock_driftrate = ee->clock_driftrate;
45
46 _Crs = ee->Crs;
47 _Delta_n = ee->Delta_n;
48 _M0 = ee->M0;
49 _Cuc = ee->Cuc;
50 _e = ee->e;
51 _Cus = ee->Cus;
52 _sqrt_A = ee->sqrt_A;
53 _Cic = ee->Cic;
54 _OMEGA0 = ee->OMEGA0;
55 _Cis = ee->Cis;
56 _i0 = ee->i0;
57 _Crc = ee->Crc;
58 _omega = ee->omega;
59 _OMEGADOT = ee->OMEGADOT;
60 _IDOT = ee->IDOT;
61
62 _TGD = ee->TGD;
63}
64
65// Compute GPS Satellite Position (virtual)
66////////////////////////////////////////////////////////////////////////////
67void t_ephGPS::position(int GPSweek, double GPSweeks,
68 double* xc,
69 double* vv) const {
70
71 static const double secPerWeek = 7 * 86400.0;
72 static const double omegaEarth = 7292115.1467e-11;
73 static const double gmWGS = 398.6005e12;
74
75 memset(xc, 0, 4*sizeof(double));
76 memset(vv, 0, 3*sizeof(double));
77
78 double a0 = _sqrt_A * _sqrt_A;
79 if (a0 == 0) {
80 return;
81 }
82
83 double n0 = sqrt(gmWGS/(a0*a0*a0));
84 double tk = GPSweeks - _TOE;
85 if (GPSweek != _GPSweek) {
86 tk += (GPSweek - _GPSweek) * secPerWeek;
87 }
88 double n = n0 + _Delta_n;
89 double M = _M0 + n*tk;
90 double E = M;
91 double E_last;
92 do {
93 E_last = E;
94 E = M + _e*sin(E);
95 } while ( fabs(E-E_last)*a0 > 0.001 );
96 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
97 double u0 = v + _omega;
98 double sin2u0 = sin(2*u0);
99 double cos2u0 = cos(2*u0);
100 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
101 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
102 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
103 double xp = r*cos(u);
104 double yp = r*sin(u);
105 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
106 omegaEarth*_TOE;
107
108 double sinom = sin(OM);
109 double cosom = cos(OM);
110 double sini = sin(i);
111 double cosi = cos(i);
112 xc[0] = xp*cosom - yp*cosi*sinom;
113 xc[1] = xp*sinom + yp*cosi*cosom;
114 xc[2] = yp*sini;
115
116 double tc = GPSweeks - _TOC;
117 if (GPSweek != _GPSweek) {
118 tc += (GPSweek - _GPSweek) * secPerWeek;
119 }
120 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc
121 - 4.442807633e-10 * _e * sqrt(a0) *sin(E);
122
123 // Velocity
124 // --------
125 double tanv2 = tan(v/2);
126 double dEdM = 1 / (1 - _e*cos(E));
127 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
128 * dEdM * n;
129 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
130 double dotom = _OMEGADOT - omegaEarth;
131 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
132 double dotr = a0 * _e*sin(E) * dEdM * n
133 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
134 double dotx = dotr*cos(u) - r*sin(u)*dotu;
135 double doty = dotr*sin(u) + r*cos(u)*dotu;
136
137 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
138 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
139 + yp*sini*sinom*doti; // dX / di
140
141 vv[1] = sinom *dotx + cosi*cosom *doty
142 + xp*cosom*dotom - yp*cosi*sinom*dotom
143 - yp*sini*cosom*doti;
144
145 vv[2] = sini *doty + yp*cosi *doti;
146}
147
148
149// Derivative of the state vector using a simple force model (static)
150////////////////////////////////////////////////////////////////////////////
151ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv) {
152
153 // State vector components
154 // -----------------------
155 ColumnVector rr = xv.rows(1,3);
156 ColumnVector vv = xv.rows(4,6);
157
158 // Acceleration
159 // ------------
160 static const double GM = 398.60044e12;
161 static const double AE = 6378136.0;
162 static const double OMEGA = 7292115.e-11;
163 static const double C20 = -1082.63e-6;
164
165 double rho = rr.norm_Frobenius();
166 double t1 = -GM/(rho*rho*rho);
167 double t2 = 3.0/2.0 * C20 * (GM*AE*AE) / (rho*rho*rho*rho*rho);
168 double t3 = OMEGA * OMEGA;
169 double t4 = 2.0 * OMEGA;
170 double z2 = rr(3) * rr(3);
171
172 // Vector of derivatives
173 // ---------------------
174 ColumnVector va(6);
175 va(1) = vv(1);
176 va(2) = vv(2);
177 va(3) = vv(3);
178 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2);
179 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1);
180 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3);
181
182 return va;
183}
184
185// Compute Glonass Satellite Position (virtual)
186////////////////////////////////////////////////////////////////////////////
187void t_ephGlo::position(int GPSweek, double GPSweeks,
188 double* xc, double* vv) const {
189
190 static const double secPerWeek = 7 * 86400.0;
191 static const double nominalStep = 10.0;
192
193 memset(xc, 0, 4*sizeof(double));
194 memset(vv, 0, 3*sizeof(double));
195
196 double dtPos = GPSweeks - _tt;
197 if (GPSweek != _GPSweek) {
198 dtPos += (GPSweek - _GPSweek) * secPerWeek;
199 }
200
201 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
202 double step = dtPos / nSteps;
203
204 for (int ii = 1; ii <= nSteps; ii++) {
205 _xv = rungeKutta4(_tt, _xv, step, glo_deriv);
206 _tt += step;
207 }
208
209 // Position and Velocity
210 // ---------------------
211 xc[0] = _xv(1);
212 xc[1] = _xv(2);
213 xc[2] = _xv(3);
214
215 vv[0] = _xv(4);
216 vv[1] = _xv(5);
217 vv[2] = _xv(6);
218
219 // Clock Correction
220 // ----------------
221 double dtClk = GPSweeks - _GPSweeks;
222 if (GPSweek != _GPSweek) {
223 dtClk += (GPSweek - _GPSweek) * secPerWeek;
224 }
225 xc[3] = -_tau + _gamma * dtClk;
226}
227
228// IOD of Glonass Ephemeris (virtual)
229////////////////////////////////////////////////////////////////////////////
230int t_ephGlo::IOD() const {
231
232 bool old = false;
233
234 if (old) { // 5 LSBs of iod are equal to 5 LSBs of tb
235 unsigned int tb = int(fmod(_GPSweeks,86400.0)); //sec of day
236 const int shift = sizeof(tb) * 8 - 5;
237 unsigned int iod = tb << shift;
238 return (iod >> shift);
239 }
240 else {
241 return int(fmod(_tki, 3600)) / 30;
242 }
243}
244
245// Set Glonass Ephemeris
246////////////////////////////////////////////////////////////////////////////
247void t_ephGlo::set(const glonassephemeris* ee) {
248
249}
Note: See TracBrowser for help on using the repository browser.