source: ntrip/trunk/BNC/bncmodel.cpp@ 2063

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

* empty log message *

File size: 6.7 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: bncParam, bncModel
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <cmath>
43#include <newmatio.h>
44
45#include "bncmodel.h"
46#include "bncpppclient.h"
47#include "bancroft.h"
48#include "bncutils.h"
49
50using namespace std;
51
52// Constructor
53////////////////////////////////////////////////////////////////////////////
54bncParam::bncParam(bncParam::parType typeIn) {
55 type = typeIn;
56}
57
58// Destructor
59////////////////////////////////////////////////////////////////////////////
60bncParam::~bncParam() {
61}
62
63// Partial
64////////////////////////////////////////////////////////////////////////////
65double bncParam::partialP3(t_satData* satData) {
66 if (type == CRD_X) {
67 return (x0 - satData->xx(1)) / satData->rho;
68 }
69 else if (type == CRD_Y) {
70 return (x0 - satData->xx(2)) / satData->rho;
71 }
72 else if (type == CRD_Z) {
73 return (x0 - satData->xx(3)) / satData->rho;
74 }
75 else if (type == RECCLK) {
76 return 1.0;
77 }
78 return 0.0;
79}
80
81// Constructor
82////////////////////////////////////////////////////////////////////////////
83bncModel::bncModel() {
84 _xcBanc.ReSize(4); _xcBanc = 0.0;
85 _params.push_back(new bncParam(bncParam::CRD_X));
86 _params.push_back(new bncParam(bncParam::CRD_Y));
87 _params.push_back(new bncParam(bncParam::CRD_Z));
88 _params.push_back(new bncParam(bncParam::RECCLK));
89}
90
91// Destructor
92////////////////////////////////////////////////////////////////////////////
93bncModel::~bncModel() {
94}
95
96// Bancroft Solution
97////////////////////////////////////////////////////////////////////////////
98t_irc bncModel::cmpBancroft(t_epoData* epoData) {
99
100 const unsigned MINOBS = 4;
101
102 if (epoData->size() < MINOBS) {
103 return failure;
104 }
105
106 Matrix BB(epoData->size(), 4);
107
108 QMapIterator<QString, t_satData*> it(epoData->satData);
109 int iObs = 0;
110 while (it.hasNext()) {
111 ++iObs;
112 it.next();
113 QString prn = it.key();
114 t_satData* satData = it.value();
115 BB(iObs, 1) = satData->xx(1);
116 BB(iObs, 2) = satData->xx(2);
117 BB(iObs, 3) = satData->xx(3);
118 BB(iObs, 4) = satData->P3 + satData->clk;
119 }
120
121 bancroft(BB, _xcBanc);
122
123 // Set Parameter A Priori Values
124 // -----------------------------
125 QListIterator<bncParam*> itPar(_params);
126 while (itPar.hasNext()) {
127 bncParam* par = itPar.next();
128 if (par->type == bncParam::CRD_X) {
129 par->x0 = _xcBanc(1);
130 }
131 else if (par->type == bncParam::CRD_Y) {
132 par->x0 = _xcBanc(2);
133 }
134 else if (par->type == bncParam::CRD_Z) {
135 par->x0 = _xcBanc(3);
136 }
137 else if (par->type == bncParam::RECCLK) {
138 par->x0 = _xcBanc(4);
139 }
140 }
141
142 // Set Station Height
143 // ------------------
144 ColumnVector ell(3);
145 xyz2ell(_xcBanc.data(), ell.data());
146 _height = ell(3);
147
148 cout << "height = " << _height << endl;
149
150 return success;
151}
152
153// Computed Value
154////////////////////////////////////////////////////////////////////////////
155double bncModel::cmpValueP3(t_satData* satData) {
156
157 double rho0 = (satData->xx - _xcBanc.Rows(1,3)).norm_Frobenius();
158
159 ColumnVector xRec(3);
160 double dPhi = t_CST::omega * rho0 / t_CST::c;
161 xRec(1) = _xcBanc(1) * cos(dPhi) - _xcBanc(2) * sin(dPhi);
162 xRec(2) = _xcBanc(2) * cos(dPhi) + _xcBanc(1) * sin(dPhi);
163 xRec(3) = _xcBanc(3);
164
165 satData->rho = (satData->xx - xRec).norm_Frobenius();
166
167 double tropDelay = delay_saast();
168
169 cout << "tropDelay " << tropDelay << endl;
170
171 return satData->rho + _xcBanc(4) - satData->clk + tropDelay;
172}
173
174// Tropospheric Model (Saastamoinen)
175////////////////////////////////////////////////////////////////////////////
176double bncModel::delay_saast() {
177
178 double Ele = M_PI/2.0;
179
180 double pp = 1013.25 * pow(1.0 - 2.26e-5 * _height, 5.225);
181 double TT = 18.0 - _height * 0.0065 + 273.15;
182 double hh = 50.0 * exp(-6.396e-4 * _height);
183 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
184
185 double h_km = _height / 1000.0;
186
187 if (h_km < 0.0) h_km = 0.0;
188 if (h_km > 5.0) h_km = 5.0;
189 int ii = int(h_km + 1);
190 double href = ii - 1;
191
192 double bCor[6];
193 bCor[0] = 1.156;
194 bCor[1] = 1.006;
195 bCor[2] = 0.874;
196 bCor[3] = 0.757;
197 bCor[4] = 0.654;
198 bCor[5] = 0.563;
199
200 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
201
202 double zen = M_PI/2.0 - Ele;
203
204 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
205}
206
207// Update Step of the Filter (currently just a single-epoch solution)
208////////////////////////////////////////////////////////////////////////////
209t_irc bncModel::update(t_epoData* epoData) {
210
211 unsigned nPar = _params.size();
212 unsigned nObs = epoData->size();
213
214 _AA.ReSize(nObs, nPar); // variance-covariance matrix
215 _ll.ReSize(nObs); // tems observed-computed
216
217 unsigned iObs = 0;
218 QMapIterator<QString, t_satData*> itObs(epoData->satData);
219 while (itObs.hasNext()) {
220 ++iObs;
221 itObs.next();
222 QString prn = itObs.key();
223 t_satData* satData = itObs.value();
224 _ll(iObs) = satData->P3 - cmpValueP3(satData);
225
226 unsigned iPar = 0;
227 QListIterator<bncParam*> itPar(_params);
228 while (itPar.hasNext()) {
229 ++iPar;
230 bncParam* par = itPar.next();
231 _AA(iObs, iPar) = par->partialP3(satData);
232 }
233 }
234
235 _QQ.ReSize(nPar);
236 _QQ << _AA.t() * _AA;
237 _QQ = _QQ.i();
238 _dx = _QQ * _AA.t() * _ll;
239
240 _xx.ReSize(nPar);
241
242 unsigned iPar = 0;
243 QListIterator<bncParam*> itPar(_params);
244 while (itPar.hasNext()) {
245 ++iPar;
246 bncParam* par = itPar.next();
247 _xx(iPar) = par->x0 + _dx(iPar);
248 }
249
250 return success;
251}
Note: See TracBrowser for help on using the repository browser.