GPS heading in Python -
i working on gps project in python , need help. can't figure out how heading part work. want statement true heading of e.g. 355
degrees +/- bit of error. problem getting around 360
degrees. like
if ((heading – headerror) % 360) <= gps.heading <= ((heading + headerror) % 360):
if use heading of 355
error of 20
, gps reads 4
, both north.
335 <= 4 <= 15
how can check if it's in range of 335
15
335
360
, 0
15
?
one simple implementation:
def between(head, low, high): """whether heading head between headings low , high.""" head, low, high = map(lambda x: x % 360, (head, low, high)) if high >= low: return low <= head <= high return low <= head < 360 or 0 <= head <= high
first converts arguments headings between 0
, 360
, determines situation we're in, whether can simple comparison, or need account 0
/360
. in latter case, explicitly checks between low
value , 360
, between 0
, high
value.
in use:
>>> between(4, 355-20, 355+20) true
you refactor use e.g. equal(4, 355, 20)
if wanted.
Comments
Post a Comment