commaai / laika

Simple Python GNSS processing library
MIT License
634 stars 178 forks source link

Klobuchar (iono) model doens't seem to respect specification (typo) #164

Open jonathanmuller opened 1 month ago

jonathanmuller commented 1 month ago

Klobuchar model is defined as

def klobuchar(pos, az, el, time, iono_coeffs):
  """
    Details are taken from [5]: IS-GPS-200H, Fig. 20-4
    Note: result is referred to the GPS L₁ frequency;
    if the user is operating on the GPS L₂ frequency, the correction term must
    be multiplied by γ = f₂²/f₁¹ = 0.6071850227694382
    :param pos: [lat, lon, alt] in radians and meters
    """

...

  # ionospheric delay
  amp = iono_coeffs[0] + phi * (iono_coeffs[1] + phi *
                                (iono_coeffs[2] + phi * iono_coeffs[3]))
  per = iono_coeffs[4] + phi * (iono_coeffs[5] + phi *
                                (iono_coeffs[6] + phi * iono_coeffs[7]))
...

But specification ( https://www.gps.gov/technical/icwg/IS-GPS-200H.pdf ) requires amp and per to be image So the 3rd element is currently multiplied by phi to the power of 2, rather than phi to the power of 3

Shall I open a PR ?

haraschax commented 1 month ago

I would have to do some tests to confirm this, not sure when I will have time for that. Can you show what difference that makes in the delay in some realistic cases?

jonathanmuller commented 4 weeks ago

At my current location, time, and with uBlox provided klobuchar parameters, the current version return 4.53[m], and the corrected one 5.98[m].

It seems RTKLib is also using the power 3 calculation : https://github.com/rtklibexplorer/RTKLIB/blob/d2030fbfc8ae71f83d1481dba7b9ad6b4b14b794/src/rtkcmn.c#L3606

Here is some calculated values based on my position (Switzerland) with various elevation / azimuth All values are in meters :

25% quartile 50% quartile 75% quartile
1.2 1.3 1.8
Azimuth Elevation Current Output (Power 2) Corrected Output (Power 3) Difference
π/0 π/0 12.6 16.9 4.3
π/0 π/1 5.8 7.9 2.0
π/0 π/2 3.8 5.2 1.3
π/0 π/3 3.7 5.0 1.3
π/0 π/4 2.5 3.4 0.9
π/1 π/0 13.2 16.4 3.2
π/1 π/1 6.1 8.0 1.9
π/1 π/2 3.9 5.2 1.3
π/1 π/3 3.7 5.0 1.3
π/1 π/4 2.5 3.4 0.9
π/2 π/0 11.6 14.3 2.7
π/2 π/1 6.2 8.0 1.8
π/2 π/2 3.9 5.2 1.3
π/2 π/3 3.7 4.9 1.3
π/2 π/4 2.5 3.4 0.9
π/3 π/0 11.6 14.3 2.7
π/3 π/1 6.2 8.0 1.8
π/3 π/2 3.9 5.2 1.3
π/3 π/3 3.7 4.9 1.3
π/3 π/4 2.5 3.4 0.9
π/4 π/0 13.2 16.4 3.2
π/4 π/1 6.1 8.0 1.9
π/4 π/2 3.9 5.2 1.3
π/4 π/3 3.7 5.0 1.3
π/4 π/4 2.5 3.4 0.9
haraschax commented 3 weeks ago

Will double check next week with my tests and merge if that looks good! Thanks for the help!