bug fix: altiude and TAS

This commit is contained in:
Junzi Sun 2021-01-23 01:21:54 +01:00
parent 89e67fae31
commit 3bb8c361e9
2 changed files with 45 additions and 38 deletions

View File

@ -34,13 +34,13 @@ def airborne_position(msg0, msg1, t0, t1):
raise RuntimeError("Both even and odd CPR frames are required.") raise RuntimeError("Both even and odd CPR frames are required.")
# 131072 is 2^17, since CPR lat and lon are 17 bits each. # 131072 is 2^17, since CPR lat and lon are 17 bits each.
cprlat_even = common.bin2int(mb0[22:39]) / 131072.0 cprlat_even = common.bin2int(mb0[22:39]) / 131072
cprlon_even = common.bin2int(mb0[39:56]) / 131072.0 cprlon_even = common.bin2int(mb0[39:56]) / 131072
cprlat_odd = common.bin2int(mb1[22:39]) / 131072.0 cprlat_odd = common.bin2int(mb1[22:39]) / 131072
cprlon_odd = common.bin2int(mb1[39:56]) / 131072.0 cprlon_odd = common.bin2int(mb1[39:56]) / 131072
air_d_lat_even = 360.0 / 60 air_d_lat_even = 360 / 60
air_d_lat_odd = 360.0 / 59 air_d_lat_odd = 360 / 59
# compute latitude index 'j' # compute latitude index 'j'
j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5) j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)
@ -64,13 +64,13 @@ def airborne_position(msg0, msg1, t0, t1):
nl = common.cprNL(lat) nl = common.cprNL(lat)
ni = max(common.cprNL(lat) - 0, 1) ni = max(common.cprNL(lat) - 0, 1)
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5) m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
lon = (360.0 / ni) * (m % ni + cprlon_even) lon = (360 / ni) * (m % ni + cprlon_even)
else: else:
lat = lat_odd lat = lat_odd
nl = common.cprNL(lat) nl = common.cprNL(lat)
ni = max(common.cprNL(lat) - 1, 1) ni = max(common.cprNL(lat) - 1, 1)
m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5) m = common.floor(cprlon_even * (nl - 1) - cprlon_odd * nl + 0.5)
lon = (360.0 / ni) * (m % ni + cprlon_odd) lon = (360 / ni) * (m % ni + cprlon_odd)
if lon > 180: if lon > 180:
lon = lon - 360 lon = lon - 360
@ -95,11 +95,11 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
mb = common.hex2bin(msg)[32:] mb = common.hex2bin(msg)[32:]
cprlat = common.bin2int(mb[22:39]) / 131072.0 cprlat = common.bin2int(mb[22:39]) / 131072
cprlon = common.bin2int(mb[39:56]) / 131072.0 cprlon = common.bin2int(mb[39:56]) / 131072
i = int(mb[21]) i = int(mb[21])
d_lat = 360.0 / 59 if i else 360.0 / 60 d_lat = 360 / 59 if i else 360 / 60
j = common.floor(lat_ref / d_lat) + common.floor( j = common.floor(lat_ref / d_lat) + common.floor(
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat 0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
@ -110,9 +110,9 @@ def airborne_position_with_ref(msg, lat_ref, lon_ref):
ni = common.cprNL(lat) - i ni = common.cprNL(lat) - i
if ni > 0: if ni > 0:
d_lon = 360.0 / ni d_lon = 360 / ni
else: else:
d_lon = 360.0 d_lon = 360
m = common.floor(lon_ref / d_lon) + common.floor( m = common.floor(lon_ref / d_lon) + common.floor(
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon 0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
@ -143,9 +143,8 @@ def altitude(msg):
if tc < 19: if tc < 19:
altcode = altbin[0:6] + "0" + altbin[6:] altcode = altbin[0:6] + "0" + altbin[6:]
alt = common.altitude(altcode)
else: else:
altcode = altbin[0:6] + "0" + altbin[6:] alt = common.bin2int(altbin) * 3.28084
alt = common.altitude(altcode)
return alt return alt

View File

@ -24,7 +24,7 @@ def airborne_velocity(msg, source=False):
- Angle (degree), either ground track or heading - Angle (degree), either ground track or heading
- Vertical rate (ft/min) - Vertical rate (ft/min)
- Speed type ('GS' for ground speed, 'AS' for airspeed) - Speed type ('GS' for ground speed, 'AS' for airspeed)
- [Optional] Direction source ('TRUE_NORTH' or 'MAGENTIC_NORTH') - [Optional] Direction source ('TRUE_NORTH' or 'MAGNETIC_NORTH')
- [Optional] Vertical rate source ('BARO' or 'GNSS') - [Optional] Vertical rate source ('BARO' or 'GNSS')
""" """
@ -35,29 +35,35 @@ def airborne_velocity(msg, source=False):
subtype = common.bin2int(mb[5:8]) subtype = common.bin2int(mb[5:8])
if common.bin2int(mb[14:24]) == 0 or common.bin2int(mb[25:35]) == 0:
return None
if subtype in (1, 2): if subtype in (1, 2):
v_ew_sign = -1 if mb[13] == "1" else 1
v_ew = common.bin2int(mb[14:24]) - 1 # east-west velocity
if subtype == 2: # Supersonic
v_ew *= 4
v_ns_sign = -1 if mb[24] == "1" else 1 v_ew = common.bin2int(mb[14:24])
v_ns = common.bin2int(mb[25:35]) - 1 # north-south velocity v_ns = common.bin2int(mb[25:35])
if subtype == 2: # Supersonic
v_ns *= 4
v_we = v_ew_sign * v_ew if v_ew == 0 or v_ns == 0:
v_sn = v_ns_sign * v_ns spd = None
trk_or_hdg = None
vs = None
else:
v_ew_sign = -1 if mb[13] == "1" else 1
v_ew = v_ew - 1 # east-west velocity
if subtype == 2: # Supersonic
v_ew *= 4
spd = math.sqrt(v_sn * v_sn + v_we * v_we) # unit in kts v_ns_sign = -1 if mb[24] == "1" else 1
spd = int(spd) v_ns = v_ns - 1 # north-south velocity
if subtype == 2: # Supersonic
v_ns *= 4
trk = math.atan2(v_we, v_sn) v_we = v_ew_sign * v_ew
trk = math.degrees(trk) # convert to degrees v_sn = v_ns_sign * v_ns
trk = trk if trk >= 0 else trk + 360 # no negative val
spd = math.sqrt(v_sn * v_sn + v_we * v_we) # unit in kts
spd = int(spd)
trk = math.atan2(v_we, v_sn)
trk = math.degrees(trk) # convert to degrees
trk = trk if trk >= 0 else trk + 360 # no negative val
spd_type = "GS" spd_type = "GS"
trk_or_hdg = round(trk, 2) trk_or_hdg = round(trk, 2)
@ -67,13 +73,15 @@ def airborne_velocity(msg, source=False):
if mb[13] == "0": if mb[13] == "0":
hdg = None hdg = None
else: else:
hdg = common.bin2int(mb[14:24]) / 1024.0 * 360.0 hdg = common.bin2int(mb[14:24]) / 1024 * 360.0
hdg = round(hdg, 2) hdg = round(hdg, 2)
trk_or_hdg = hdg trk_or_hdg = hdg
spd = common.bin2int(mb[25:35]) spd = common.bin2int(mb[25:35])
spd = None if spd == 0 else spd - 1 spd = None if spd == 0 else spd - 1
if subtype == 4: # Supersonic if subtype == 4: # Supersonic
spd *= 4 spd *= 4
@ -82,7 +90,7 @@ def airborne_velocity(msg, source=False):
else: else:
spd_type = "TAS" spd_type = "TAS"
dir_type = "MAGENTIC_NORTH" dir_type = "MAGNETIC_NORTH"
vr_source = "GNSS" if mb[35] == "0" else "BARO" vr_source = "GNSS" if mb[35] == "0" else "BARO"
vr_sign = -1 if mb[36] == "1" else 1 vr_sign = -1 if mb[36] == "1" else 1
@ -96,7 +104,7 @@ def airborne_velocity(msg, source=False):
def altitude_diff(msg): def altitude_diff(msg):
"""Decode the differece between GNSS and barometric altitude. """Decode the difference between GNSS and barometric altitude.
Args: Args:
msg (str): 28 hexdigits string, TC=19 msg (str): 28 hexdigits string, TC=19