1111from cssrlib .ephemeris import satposs
1212from cssrlib .cssrlib import sSigGPS , sSigGAL , sSigQZS , sCType
1313from cssrlib .ppp import tidedisp , shapiro , windupcorr
14- from cssrlib .rtk import IB , ddres , resamb_lambda , valpos , holdamb , initx , kfupdate
14+ from cssrlib .rtk import IB , ddres , resamb_lambda , valpos , holdamb , initx
1515
1616MAXITR = 10
1717ELMIN = 10
@@ -34,14 +34,26 @@ def logmon(nav, t, sat, cs, iu=None):
3434 for i in range (n [0 ]):
3535 if cpc [i , 0 ] == 0 and cpc [i , 1 ] == 0 :
3636 continue
37- nav .fout .write ("%6d\t %3d\t %8.3f\t %8.3f\t %8.3f\t %8.3f\t %2d\t "
38- % (tow , sat [i ], cpc [i , 0 ], cpc [i , 1 ],
39- prc [i , 0 ], prc [i , 1 ], cs .iodssr ))
37+ sys , prn = gn .sat2prn (sat [i ])
38+ pb = osr [i , 0 :2 ]
39+ cb = osr [i , 2 :4 ]
40+ antr = osr [i , 4 :6 ]
41+ phw = osr [i , 6 :8 ]
42+ trop = osr [i , 8 ]
43+ iono = osr [i , 9 ]
44+ relatv = osr [i , 10 ]
45+ dorb = osr [i , 11 ]
46+ dclk = osr [i ,12 ]
47+ # tow sys prn trop iono antr1 antr2 antr5 relatv
48+ # wup2 wup5 CPC1 CPC2 CPC5 PRC1 PRC2 PRC5 orb clk
49+ nav .fout .write ("%6d\t %2d\t %3d\t %8.3f\t %8.3f\t %8.3f\t %8.3f\t "
50+ % (tow , sys , prn , pb [0 ], pb [1 ], cb [0 ], cb [1 ]))
51+ nav .fout .write ("%8.3f\t %8.3f\t %8.3f\t %8.3f\t "
52+ % (trop , iono , antr [0 ], antr [1 ]))
4053 nav .fout .write ("%8.3f\t %8.3f\t %8.3f\t %8.3f\t %8.3f\t "
41- % (osr [i , 0 ], osr [i , 1 ], osr [i , 2 ],
42- osr [i , 3 ], osr [i , 4 ]))
54+ % (relatv , phw [0 ], phw [1 ], cpc [i , 0 ], cpc [i , 1 ]))
4355 nav .fout .write ("%8.3f\t %8.3f\t %8.3f\t %8.3f\n "
44- % (osr [i , 5 ], osr [i , 6 ], osr [ i , 7 ], osr [ i , 8 ] ))
56+ % (prc [i , 0 ], prc [i , 1 ], dorb , dclk ))
4557 return 0
4658
4759
@@ -51,7 +63,7 @@ def rtkinit(nav, pos0=np.zeros(3)):
5163 nav .pmode = 1 # 0:static, 1:kinematic
5264
5365 nav .na = 3 if nav .pmode == 0 else 6
54- nav .nq = 3
66+ nav .nq = 3 if nav . pmode == 0 else 6
5567 nav .ratio = 0
5668 nav .thresar = [2 ]
5769 nav .nx = nav .na + gn .uGNSS .MAXSAT * nav .nf
@@ -63,8 +75,8 @@ def rtkinit(nav, pos0=np.zeros(3)):
6375 nav .phw = np .zeros (gn .uGNSS .MAXSAT )
6476
6577 # parameter for PPP-RTK
66- nav .eratio = [50 , 50 ]
67- nav .err = [100 , 0.00707 , 0.00354 ]
78+ nav .eratio = [100 , 100 ]
79+ nav .err = [0 , 0.003 , 0.003 ]
6880 nav .sig_p0 = 30.0
6981 nav .sig_v0 = 10.0
7082 nav .sig_n0 = 30.0
@@ -73,18 +85,20 @@ def rtkinit(nav, pos0=np.zeros(3)):
7385 nav .tidecorr = True
7486 nav .armode = 1 # 1:contunous,2:instantaneous,3:fix-and-hold
7587 nav .gnss_t = [uGNSS .GPS , uGNSS .GAL , uGNSS .QZS ]
76- nav .gnss_t = [uGNSS .GPS ] # GPS only
88+ # nav.gnss_t = [uGNSS.GPS] # GPS only
7789
7890 #
7991 nav .x [0 :3 ] = pos0
92+ nav .x [3 :6 ] = 0.0
8093
8194 dP = np .diag (nav .P )
8295 dP .flags ['WRITEABLE' ]= True
8396 dP [0 :3 ] = nav .sig_p0 ** 2
8497 nav .q = np .zeros (nav .nq )
85- if nav .pmode >= 1 :
98+ if nav .pmode >= 1 : # kinematic
8699 dP [3 :6 ] = nav .sig_v0 ** 2
87- nav .q [0 :3 ] = nav .sig_qv ** 2
100+ nav .q [0 :3 ] = nav .sig_qp ** 2
101+ nav .q [3 :6 ] = nav .sig_qv ** 2
88102 else :
89103 nav .q [0 :3 ] = nav .sig_qp ** 2
90104 # obs index
@@ -119,20 +133,13 @@ def udstate(nav, obs, cs):
119133
120134 # pos,vel
121135 na = nav .na
122- Px = nav .P [0 :na , 0 :na ]
123- if nav .pmode >= 1 :
124- F = np .eye (na )
125- F [0 :3 , 3 :6 ] = np .eye (3 )* tt
126- nav .x [0 :3 ] += tt * nav .x [3 :6 ]
127- Px = F @Px @F .T
128- dP = np .diag (Px )
129- dP .flags ['WRITEABLE' ] = True
130- dP [3 :3 + nav .nq ] += nav .q [0 :nav .nq ]* tt
131- else :
132- dP = np .diag (Px )
133- dP .flags ['WRITEABLE' ] = True
134- dP [0 :nav .nq ] += nav .q [0 :nav .nq ]* tt
135- nav .P [0 :na , 0 :na ] = Px
136+
137+ Phi = np .eye (nav .nx )
138+ Phi [0 :3 ,3 :6 ]= np .eye (3 )* tt
139+ nav .P = Phi @nav .P @Phi .T
140+ dP = np .diag (nav .P )
141+ dP .flags ['WRITEABLE' ] = True
142+ dP [0 :nav .nq ] += nav .q [0 :nav .nq ]* tt
136143
137144 # bias
138145 for f in range (nav .nf ):
@@ -141,13 +148,14 @@ def udstate(nav, obs, cs):
141148 for i in range (gn .uGNSS .MAXSAT ):
142149 sat_ = i + 1
143150 nav .outc [i , f ] += 1
144- reset = True if nav .outc [i , f ] > nav .maxout else False
151+ reset = ( nav .outc [i , f ] > nav .maxout )
145152 sys_i , _ = gn .sat2prn (sat_ )
146153 if sys_i not in nav .gnss_t :
147154 continue
148155 j = IB (sat_ , f , nav .na )
149156 if reset and nav .x [j ] != 0.0 :
150- initx (nav , 0.0 , 0.0 , j )
157+ #initx(nav, 0.0, 0.0, j)
158+ #print("reset amb f=%d sat=%d outc=%d" % (f,sat_,nav.outc[i, f]))
151159 nav .outc [i , f ] = 0
152160 # cycle slip check by LLI
153161 for i in range (ns ):
@@ -164,7 +172,7 @@ def udstate(nav, obs, cs):
164172 initx (nav , 0.0 , 0.0 , IB (sat [i ], f , nav .na ))
165173 # bias
166174 bias = np .zeros (ns )
167- offset = 0
175+ offset = 0
168176 na = 0
169177 for i in range (ns ):
170178 if sys [i ] not in nav .gnss_t :
@@ -223,7 +231,7 @@ def zdres(nav, obs, rs, vs, dts, svh, rr, cs):
223231
224232 cs .cpc = np .zeros ((n , nf ))
225233 cs .prc = np .zeros ((n , nf ))
226- cs .osr = np .zeros ((n , 2 * nf + 5 ))
234+ cs .osr = np .zeros ((n , 4 * nf + 5 ))
227235
228236 for i in range (n ):
229237 sat = obs .sat [i ]
@@ -281,10 +289,10 @@ def zdres(nav, obs, rs, vs, dts, svh, rr, cs):
281289 cbias += cs .lc [inet ].cbias [idx_l ][kidx ]
282290 if cs .lc [inet ].pbias is not None :
283291 pbias += cs .lc [inet ].pbias [idx_l ][kidx ]
284- # t1 = timediff(obs.t, cs.lc[0].t0[sCType.ORBIT])
285- # t2 = timediff(obs.t, cs.lc[inet].t0[sCType.PBIAS])
286- # if t1 >= 0 and t1 < 30 and t2 >= 30:
287- # pbias += nav.dsis[sat]
292+ #t1 = timediff(obs.t, cs.lc[0].t0[sCType.ORBIT])
293+ #t2 = timediff(obs.t, cs.lc[inet].t0[sCType.PBIAS])
294+ #if t1 >= 0 and t1 < 30 and t2 >= 30:
295+ # pbias += nav.dsis[sat]
288296
289297 # relativity effect
290298 relatv = shapiro (rs [i , :], rr_ )
@@ -302,8 +310,9 @@ def zdres(nav, obs, rs, vs, dts, svh, rr, cs):
302310 # prc_c += nav.dorb[sat]-nav.dclk[sat]
303311 cs .prc [i , :] = prc_c + iono + cbias
304312 cs .cpc [i , :] = prc_c - iono + pbias + phw
305- cs .osr [i , :] = [pbias [0 ], pbias [1 ], cbias [0 ], cbias [1 ], trop ,
306- iono_ , relatv , nav .dorb [sat ], nav .dclk [sat ]]
313+ cs .osr [i , :] = [pbias [0 ], pbias [1 ], cbias [0 ], cbias [1 ],
314+ antr [0 ], antr [1 ], phw [0 ], phw [1 ],
315+ trop , iono_ , relatv , nav .dorb [sat ], nav .dclk [sat ]]
307316 r += - _c * dts [i ]
308317
309318 for f in range (nf ):
@@ -314,12 +323,22 @@ def zdres(nav, obs, rs, vs, dts, svh, rr, cs):
314323 return y , e , el
315324
316325
326+ def kfupdate (x , P , H , v , R ):
327+ """ kalmanf filter measurement update """
328+ PHt = P @H .T
329+ S = H @PHt + R
330+ K = PHt @np .linalg .inv (S )
331+ x += K @v
332+ P = P - K @H @P
333+
334+ return x , P , S
335+
317336def ppprtkpos (nav , obs , cs ):
318337 """ PPP-RTK positioning """
319338
320- for i in range (gn .uGNSS .MAXSAT ):
321- for j in range (nav .nf ):
322- nav .vsat [j ] = 0
339+ # for i in range(gn.uGNSS.MAXSAT):
340+ # for j in range(nav.nf):
341+ # nav.vsat[j] = 0
323342
324343 rs , vs , dts , svh = satposs (obs , nav , cs )
325344 # Kalman filter time propagation
@@ -337,6 +356,7 @@ def ppprtkpos(nav, obs, cs):
337356 el = elu [iu ]
338357 nav .sat = sat
339358 nav .y = y
359+ ns = len (sat )
340360
341361 logmon (nav , obs .t , sat , cs , iu )
342362
@@ -365,16 +385,19 @@ def ppprtkpos(nav, obs, cs):
365385 if valpos (nav , v , R ):
366386 nav .x = xp
367387 nav .P = Pp
368- ns = len (nav .sat )
369388 nav .ns = 0
370389 for i in range (ns ):
390+ j = sat [i ]- 1
371391 for f in range (nav .nf ):
372- if nav .vsat [sat [ i ] - 1 , f ] == 0 :
392+ if nav .vsat [j , f ] == 0 :
373393 continue
374- nav .lock [sat [ i ] - 1 , f ] += 1
375- nav .outc [sat [ i ] - 1 , f ] = 0
394+ nav .lock [j , f ] += 1
395+ nav .outc [j , f ] = 0
376396 if f == 0 :
377397 nav .ns += 1
398+
399+ else :
400+ nav .smode = 0
378401
379402 nb , xa = resamb_lambda (nav , sat )
380403 nav .smode = 5 # float
0 commit comments