【问题标题】:Compass setting指南针设置
【发布时间】:2020-02-19 16:48:46
【问题描述】:

指南针已正确校准。为了获得指南针角度(360 度),我正在使用代码

        heading = 180 * math.atan2(yh,xh)/math.pi
        if (yh >= 0):
            return heading
        else:
            return 360 + heading

没关系。北指示正确。问题是如何添加或保留结果,例如。 + 20 / -20 度(我需要将指南针放在一个固定位置。)

感谢您的帮助!

【问题讨论】:

    标签: python sensors magnetometer


    【解决方案1】:

    如果您愿意,可以从标题中添加(或减去)并使用模运算符保持在 0-359 之间:

    def rotate(heading, degree_change):
        return (heading + degree_change) % 360
    

    此外,您可以使用模运算符来简化您已有的代码:

    heading = (180 * math.atan2(yh,xh)/math.pi) % 360
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-05
      • 2013-10-11
      • 1970-01-01
      • 2014-09-25
      • 2011-07-02
      • 1970-01-01
      相关资源
      最近更新 更多