GPS Float_Latitude_Deg Overflow
Ltech
Posts: 385
Help Please with bug
We use blackbox for position tracking antennas.
We use it for years.
Now the first time we use it in Jakarta 106° South, but the system get in trouble.
I am not in Jakarta and had no idea wath is going wrong.
The hight is updated, the long and lat stops after some minutes.
It works for one minute, then the latitude disappear? Freeze? but sure not update. We can not monitor it
The math is fine, but there is something killing it. Overflow ?
I try with fixed variables, the results are fine.
In the north hemisphere it works great. Denmark, Israel, Italy, Belgium, London (travel over Greanwitch) .....
Parts of the code involved
Thank you if you find something
We use blackbox for position tracking antennas.
We use it for years.
Now the first time we use it in Jakarta 106° South, but the system get in trouble.
I am not in Jakarta and had no idea wath is going wrong.
The hight is updated, the long and lat stops after some minutes.
It works for one minute, then the latitude disappear? Freeze? but sure not update. We can not monitor it
The math is fine, but there is something killing it. Overflow ?
I try with fixed variables, the results are fine.
In the north hemisphere it works great. Denmark, Israel, Italy, Belgium, London (travel over Greanwitch) .....
Parts of the code involved
Pub
NMEA : "GPS_Str_NMEA"
F : "F32_1_6"
Pub Do_The_Job | lnglatitude,lnglongitude,Long_SecondPrev,lngAltitude
Repeat
lnglatitude := f.fround(f.fmul(F.Radians(Float_Latitude_Deg) ,100_000_000.0))
lnglongitude := f.fround(f.fmul(F.Radians(Float_Longitude_Deg) ,100_000_000.0))
lngAltitude :=(f.fround(Float_Altitude_Above_MSL))
if (lnglatitude <> $7FFF_FFFF) and (lnglongitude<>$7FFF_FFFF) and (lnglatitude <> $80000001) and (lnglongitude<> $80000001) ' If data is wrong -1 is part of nmea !
Repeat i from 3 to 0
uarts.tx(0,(lnglatitude.byte[i]))
Repeat i from 3 to 0
uarts.tx(0,(lnglongitude.byte[i]))
Repeat i from 1 to 0
uarts.tx(0,(lngAltitude.byte[i]))
PUB Float_Latitude_Deg : floatVal | p, d, m, mf, fd
'-------------------------------------------------------------------------
'--------------------------┌────────────────────┐-------------------------
'--------------------------│ Float_Latitude_Deg │-------------------------
'--------------------------└────────────────────┘-------------------------
'-------------------------------------------------------------------------
'' Action: It returns Latitude in decimal degrees
'' Parameters: None
'' Results: Latitude in signed float as decimal degrees
''+Reads/Uses: floatNaN
'' +Writes: None
'' Calls: GPS_Str_NMEA-------------->NMEA.Str_Latitude
'' NMEA.Str_Lat_N_S
'' Float32Full--------------->F.FFloat
'' F.FAdd
'' F.FDiv
'-------------------------------------------------------------------------
p := NMEA.Str_Latitude
'Check for not "D", I.e. data received
IF BYTE[p] == "D"
RETURN floatNaN
'Cross check decimal point to be sure
IF BYTE[p + 4] <> "."
RETURN floatNaN
d := 10 * BYTE[p] + BYTE[p + 1] - $210
m := 10 * BYTE[p + 2] + BYTE[p + 3] - $210
CASE STRSIZE(p)
8:
mf := 10*(10*BYTE[p+5]+BYTE[p+6])+BYTE[p+7]-$14D0
fd := 1000.0
9:
mf := 10*(10*(10*BYTE[p+5]+BYTE[p+6])+BYTE[p+7])+BYTE[p+8]-$D050
fd := 10_000.0
m := F.FAdd(F.FFloat(m),F.FDiv(F.FFloat(mf),fd))
d := F.Fadd(F.FFloat(d),F.FDiv(m,60.0))
'Check N S hemispheres
p := NMEA.Str_Lat_N_S
IF BYTE[p] == "S"
d ^= $8000_0000 'Negate it
RETURN d
'-------------------------------------------------------------------------
PUB Float_Longitude_Deg : floatVal | p, d, m, mf, fd
'-------------------------------------------------------------------------
'------------------------┌─────────────────────┐--------------------------
'------------------------│ Float_Longitude_Deg │--------------------------
'------------------------└─────────────────────┘--------------------------
'-------------------------------------------------------------------------
'' Action: It returns Longitude in decimal degrees
'' Parameters: None
'' Results: Longitude in signed float as decimal degrees
''+Reads/Uses: floatNaN
'' +Writes: None
'' Calls: GPS_Str_NMEA-------------->NMEA.Str_Longitude
'' NMEA.Str_Lon_E_W
'' Float32Full--------------->F.FFloat
'' F.FAdd
'' F.FDiv
'-------------------------------------------------------------------------
p := NMEA.Str_Longitude
'Check for not "D", I.e. data received
IF BYTE[p] == "D"
RETURN floatNaN
'Cross check decimal point to be sure
IF BYTE[p + 5] <> "."
RETURN floatNaN
d := 10 * ( 10 * BYTE[p] + BYTE[p + 1]) + BYTE[p + 2] - $14D0
m := 10 * BYTE[p + 3] + BYTE[p + 4] - $210
CASE STRSIZE(p)
9:
mf := 10*(10*BYTE[p+6]+BYTE[p+7])+BYTE[p+8]-$14D0
fd := 1000.0
10:
mf := 10*(10*(10*BYTE[p+6]+BYTE[p+7])+BYTE[p+8])+BYTE[p+9]-$D050
fd := 10_000.0
m := F.FAdd(F.FFloat(m),F.FDiv(F.FFloat(mf),fd))
d := F.Fadd(F.FFloat(d),F.FDiv(m,60.0))
'Check E W hemispheres
p := NMEA.Str_Lon_E_W
IF BYTE[p] == "W"
d ^= $8000_0000 'Negate it
RETURN d
'-------------------------------------------------------------------------
Thank you if you find something
