用Python标题的GPS

时间:2015-04-14 18:38:12

标签: python gps heading

我正在使用Python进行GPS项目并需要一些帮助。我无法弄清楚如何使标题部分工作。我希望该陈述是真实的,例如标题为355度+/-有点误差。我的问题是360度。像

if ((heading – headerror) % 360) <= Gps.heading <= ((heading + headerror) % 360):

如果我使用355的标题,错误为20,而gps则显示4,这两个标题都是关于北方的。

335 <= 4 <= 15

如何检查它是否在33515的范围内,实际上是3353600到{ {1}}?

1 个答案:

答案 0 :(得分:0)

一个简单的实现:

def between(head, low, high):
    """Whether the heading head is between headings low and 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

首先,它将所有参数转换为0360之间的标题,然后确定我们处于哪种情况,我们是否可以进行简单比较,还是需要考虑{{1} } / 0。在后一种情况下,它会明确检查360值与low之间以及3600之间的值。

使用中:

high

你可以重构这个来使用它,例如>>> between(4, 355-20, 355+20) True 如果你愿意的话。