forked from XiaoGongWei/MG_APP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQGlobalDef.h
359 lines (326 loc) · 15.4 KB
/
QGlobalDef.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*************************************************************************
**
** MG-APP----Multi-GNSS-Automatic Precise Positioning Software
** Copyright (C) 2016-2020 XiaoGongWei
** This file is part of MG-APP.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** MPL License Usage
** This Source Code Form is subject to the terms of the Mozilla Public
** License, v. 2.0. If a copy of the MPL was not distributed with this
** file, You can obtain one at http://mozilla.org/MPL/2.0/.
**
** GPLv3.0 License Usage
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see http://www.gnu.org/licenses/.
**
** BSD 2-clause
** Copyright(c) 2007‐2013, T.Takasu, All rights reserved
** Redistribution and use in source and binary forms, with or without modification,
** permitted provided that the following conditions are met:
** 1. Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**************************************************************************
** Author: XiaoGongWei
** Website: github.com/xiaogongwei/MG_APP
** Download link (The GPS Toolbox): https://www.ngs.noaa.gov/gps-toolbox/
** Date: 06.02.2020
****************************************************************************/
#ifndef _QGLOBALDEF
#define _QGLOBALDEF
//Necessary header file
#include <QVector>
#include <QString>
#include <QDir>
#include <QDebug>
#include <QFile>
#include <QRegExp>
#include <qmath.h>
#include <QTime>
#include <QFileInfo>
#include <QMessageBox>
#include <iostream>
using namespace std;
//Eigen libraries (some classes are independent without Eigen)
#include <Eigen/Dense>
using namespace Eigen;
// C standard library function
#include <time.h>
#include <math.h>
#include <stdio.h>
// Custom base class
#include "QBaseObject.h"
// Mathematical Character Definition
#define MM_PI 3.1415926535897932385// Radius of circumference
#define M_C 299792458.0 // The speed of light M
#define M_GM 3.986005e14 // Earth's gravitational constant (m)(old value:3.986005e14)
#define M_GMK 398600.4415 // The Earth's Gravitational Constant (km)
#define M_We 0.000072921151467 // Earth rotation angular velocity
#define M_Re 6378137 // Reference ellipse length radius (m)
#define M_ReK 6378.137 // Reference ellipse length radius (km)
#define M_C20 -0.001082657 // The Second Harmonic Coefficient of Gravity Potential
#define M_nan 1e-15
#define M_Zgama_P_square (3*3) // Deionospheric Composite P Code Variance
#define M_IR 0.1 // ionospheric residual M
// GPS system parameters
#define M_F1 (1.57542e9)//F1
#define M_F2 (1.2276e9)//F2
#define M_F5 (1.17645e9)//F2
#define M_Lamta1 (0.190293672798365)//L1 wavelength
#define M_Lamta2 (0.244210213424568)//L2 wavelength
#define M_Lamta5 (0.254828048790854)//L5 wavelength
static double g_GPSFrq[6] = {0, 1.57542e9, 1.2276e9, 0, 0, 1.17645e9};//debug:2017.07.08
//GLONASS system parameters
static int g_GlonassK[24] = {1,-4,5,6,1,-4,5,6,-2,-7,0,-1,-2,-7,0,-1,4,-3,3,2,4,-3,3,2};//Frequency Number Corresponding to Glonass PRN
#define M_GLONASSF1(k) (1602 + k*0.5625)*1e6
#define M_GLONASSF2(k) (1246 + k*0.4375)*1e6
#define M_GLOSSLamta1k(k) (M_C/((1602 + k*0.5625)*1e6))// GLONASS L1 Wavelength Corresponding to Frequency Number
#define M_GLOSSLamta2k(k) (M_C/((1246 + k*0.4375)*1e6))// GLONASS L1 Wavelength Corresponding to Frequency Number
//BDS system parameters
static double g_BDSFrq[8] = {0, 1.561098e9, 1.561098e9, 0, 0, 0, 1.26852e9, 1.20714e9};//Storage Beidou Frequency
#define M_BDSLamtak(k) (M_C/g_BDSFrq[k])//Beidou wavelength
//Galieo system parameters
static double g_GalieoFrq[9] = {0, 1.57542e9, 0, 0, 0, 1.17645e9, 1.27875e9, 1.20714e9, 1.191795};//Galieo Band 1 5 6 7 8 Frequency
#define M_GalieoLamtak(k) (M_C/g_GalieoFrq[k])//Galieo wavelength
//PPP eliminates ionospheric combination wavelengths
//GPS wavelength
#define M_alpha1 (M_F1*M_F1/(M_F1*M_F1 - M_F2*M_F2))
#define M_alpha2 (M_F2*M_F2/(M_F1*M_F1 - M_F2*M_F2))
#define M_GPSLamta3 (M_alpha1*M_Lamta1 - M_alpha2*M_Lamta2)//0.106953378142147
//Calculate LL3
#define M_GetLamta3(F1,F2) ( (F1*M_C)/(F1*F1 - F2*F2) - (F2*M_C)/(F1*F1 - F2*F2) )
//RTKLIB structure
#ifndef RTKLIB_H
//Define the RTKlib variable
#define D2R (MM_PI/180.0) /* deg to rad */
#define AU 149597870691.0 /* 1 AU (m) */
#define AS2R (D2R/3600.0) /* arc sec to radian */
#define RE_WGS84 6378137.0 /* earth semimajor axis (WGS84) (m) */
#define FE_WGS84 (1.0/298.257223563) /* earth flattening (WGS84) */
// valid integer and decimal times from 1970-1-1 to 2038-1-18
typedef struct { /* time struct */
time_t time; /* time (s) expressed by standard time_t */
double sec; /* fraction of second under 1 s */
} gtime_t;
typedef struct { /* earth rotation parameter data type */
double mjd; /* mjd (days) */
double xp,yp; /* pole offset (rad) */
double xpr,ypr; /* pole offset rate (rad/day) */
double ut1_utc; /* ut1-utc (s) */
double lod; /* length of day (s/day) */
} erpd_t;
typedef struct { /* earth rotation parameter type */
int n,nmax; /* number and max number of data */
erpd_t *data; /* earth rotation parameter data */
} erp_t;
#endif
// customize the structure
typedef struct _StationInfo
{
QString AntType;
double AntCorr[3];// Antenna Correction: according deltype(Usually you can't accept HENs that need to look at O files.)
double satpos[3];
int deltype;/* Antenna delta type (0:HEN,1:XYZ) */
}StationInfo;
typedef struct _GPSPosTime
{
int Year;//year
int Month;//moth
int Day;//day
int Hours;//hour
int Minutes;//minutes
double Seconds;//seconds
double TropZHD;//Current epoch ZHD
int epochNum;//The number of epochs to which it belongs
}GPSPosTime;
typedef struct _RecivePos
{//Receiver Approximate Coordinate Correction by Single Point Positioning
double dX;//X or E
double dY;//Y or N
double dZ;//Z or U
double spp_pos[3];
int totolEpochStalitNum;//Number of satellites in an epoch
int Year;//year
int Month;//moth
int Day;//day
int Hours;//hour
int Minutes;//minutes
double Seconds;//seconds
}RecivePos;
typedef struct _MWLLP
{//Parameters used to detect cycle slips
double MW;
double dL;
double LP;
}CyclySlipNum;
//Broadcast ephemeris data format for each ephemeris
typedef struct _brdeph
{
char SatType;//Satellite type
int PRN;//Satellite Number
GPSPosTime UTCTime;//UTC time
double TimeDiv;//Clock deviation
double TimeMove;//Clock drift
double TimeMoveSpeed;//Clock drift acceleration
QVector< double > epochNData;//Store a data segment (GPS, BDS and Galieo are 28 7 rows GLONASS is 12 3 rows)
}BrdData;
// PPP saves the calculated data
// Preservation of satellite data and various corrections
typedef struct _SatlitData
{
int PRN;// Satellite PRN
char SatType;// Satellite type
GPSPosTime UTCTime;// Time stored in minutes and seconds, month, day, year, not necessarily UTC time
int EpochFlag;// Each epoch state (generally not 0:OK 1: power error of the first and second epoch. >1: unknown error)
int LL1_LOCK;// (rarely or hardly used: satellite signal out of lock or cycle-skip signal 0: OK or unknow. > : maybe ambiguity/Slip)
int SigInten;// Satellite status signal (generally not used; -1:unknow, Signal intensity range:1-9. If EpochFlag>0 and EpochFlag < 3 can't use)
double L1;// (cycle)
double L2;// (cycle)
double L3;// (cycle)
double C1;// Store P1 or C1(m)
double C2;// Store P2 or C2(m)
double C3;// Store P3 or C3(m)
double LL3;// Eliminate ionospheric carrier (m)!!!!
double PP3;// Elimination of ionospheric pseudo-distance (m)
double VLL3;// Filtering residue of LL3 (m)
double VPP3;// Filtering residue of PP3 (m)
double PP3_Smooth;// Phase smoothing pseudo-distance (m)
double PP3_Smooth_NUM;// Phase smoothing pseudo-distance number
double PP3_Smooth_Q; // The covariance of PP3_Smooth
QVector< QString > wantObserType;// Store the observed value type corresponding to the read dual-frequency (store order as C1, L1, C2, L2)
QVector< double > obserValue;// Observation data corresponding to obserType
QVector< QString > obserType;// Observation types (Rinex_2: C1, L1, D1, S1, C2, L2, etc. Rinex_3: C1C, L1C, S1C, C2W, L2W, etc.)
QVector<QString> badMsg;// Storage Elimination Satellites message
double Frq[3];// Record the frequencies of L1, L2, and L3
double X;// Wgs-84 satellite coordinates need to be converted from file (m)
double Y;//(m)
double Z;//(m)
double EA[2];// Satellite altitude Angle and azimuth (degrees)
//Model correction
double Relativty;// Relativistic correction (m)
double Sagnac;// Correction of earth autobiography (m)
double StaClock;// Satellite clock difference (m)
double SatTrop;// Signal direction tropospheric dry delay correction(ZPD) (m)
double StaTropMap;// The wet projection function of the troposphere(mf)
double AntHeight;// Correction of Antenna Height (m)
double L1Offset;// L1 receiver antenna number correction (cycle)
double L2Offset;// L2 receiver antenna number correction (cycle)
double SatL1Offset;// L1 satellite antenna weeks correction (weeks)
double SatL2Offset;// L2 satellite antenna weeks change by xiaogongwei 2019.04.12
double TideEffect;// Tidal correction (m)
double AntWindup;// Phase windup correction (cycle)
double SatWight;// SatWight = sin(e)^2 / M_Zgama_P_square
} SatlitData;
// define ambiguity
typedef struct _Ambiguity
{
int PRN;// Satellite PRN
char SatType;// Satellite type
double Amb;// Ambiguity (stored in Amb for both integer and floating point Numbers)
bool isIntAmb;// Is integer ambiguity
GPSPosTime UTCTime;// Time stored in minutes and seconds, month, day, year, not necessarily UTC time
}Ambiguity;
// define storage clock difference and zenith wet delay
typedef struct _Clock
{
double clockData[6];// X system receiver clock error,Xi system relative to X system receiver clock deviation
double ZTD_W;// Zenith wet delay
GPSPosTime UTCTime;// UTC year, month, day, hour, minute and second
}ClockData;
// print error message
//qDebug()<<erroInfo<<endl;
#define ErroTrace(erroInfo) {QMessageBox::critical(NULL, "Error", erroInfo, QMessageBox::Yes);}
#define ErrorMsg(myerromsg) \
{char buff[256]; sprintf(buff, "%s, line:%d, fuction:%s", __FILE__, __LINE__, __func__); myerromsg = "----"+QString(buff)+"----";}
// defines system newline characters
#if defined(_WIN32)
// Windows system
static QString ENDLINE = "\r\n";
static QString PATHSEG = "/";
static bool SYSTEMTYPE = 0;
#else
// Linux or MAC
static QString ENDLINE = "\n";
static QString PATHSEG = "/";
static bool SYSTEMTYPE = 1;
#endif
// struct for GUI
typedef struct _PlotGUI
{
QVector< double > X, Y, Z;// Store PPP coordinates
QVector< double > spp_X, spp_Y, spp_Z;// Store SPP coordinates
QVector< double > clockData;// Receiver difference
QVector< double > clockData_bias_1;// Receiver clock difference system deviation 1
QVector< double > clockData_bias_2;// Receiver clock difference system deviation 2
QVector< double > clockData_bias_3;// Receiver clock error system deviation 3
QVector< double > ZTD_W;// Zenith wet delay
QString save_file_path;// Save path for drawing results
}PlotGUIData;
#endif // _QGLOBALDEF
// Annotated example
/*
* Purpose: use SRIF Factorization Matrix Update Time
* ------------------------------------------------------------
* Example:
* | Rwk_1 0 0 | QR -> | Rwk Rwx Zw |
* | -Rp*Phi_Inv*G Rp*Phi_Inv Zp| | 0 Rp Zp |
* [Rd Zd; 0 ed] stored in AL. AL as input,meanwhile as output
*-------------------------------------------------------------
* Input:
* Rp: a priori square root information (SRI) matrix (an n * n upper triangular matrix)
* Zp: a priori SRIF state vector, of length n*1 (state is X, Zp = Rp*X).
* Phi: transition matrix, an n * n matrix.
* G : The n by ns matrix associated with process noise.
* The process noise covariance is G*Q*transpose(G) where inverse(Q)
* is transpose(Rw)*Rw. G is destroyed on output.
* Rwk_1: a priori square root information matrix for the process noise, an ns by ns upper triangular matrix
* Zw : a priori 'state' associated with the process noise, a vector with ns elements. Usually set to zero by
* the calling routine (for unbiased process noise).
* Rw: An ns by n matrix which is set to zero by this routine, but is used for output.
* -------------------------------------------------------------
* output:
* Rp: updated matrix (upper triangular, dimension N*N)
* Zp: updated vector (length N)
* Rwk_1: a posteriori square root information matrix for the process noise, an ns by ns upper triangular matrix
* Rwx:
* Zw :
* [Rwk_1 Rwx Zw] use to SRIF smoothing data
* where Rp*x = Zp
* -------------------------------------------------------------
* Authors: XiaoGongWei; Email: [email protected];
* Date: 2018-10-17; github: https://github.com/xiaogongwei
* -------------------------------------------------------------
* reference: Bierman, G.J. "Factorization Methods for Discrete Sequential
* Estimation," Academic Press, 1977.
*/