【问题标题】:Arduino algorithm - Compass directionArduino算法 - 指南针方向
【发布时间】:2014-09-26 13:46:22
【问题描述】:

我一直在做一个爱好项目,我现在需要你的帮助!我正在使用带有 Uno 板的 Arduino。我的项目是一个移动的车辆,4 个轮子。我有一个指南针,上面写着 x= 0-360。但是,我希望能够写“Kurs:”0-360,并且车辆将旋转,因此车辆的前部朝向该罗盘方向。我也希望它以最短的方式到达那个方向。如何在 Arduino 中编写算法来做到这一点?

【问题讨论】:

    标签: arduino


    【解决方案1】:

    如果您可以阅读指南针并记住所需的航向,则伪代码很简单:

    # Start by defaulting to left rotation.
    
    direction = left
    rotation = readCompass() - desiredHeading
    
    # Handle case where current heading was _less_ than desired heading.
    
    if rotation < 0:
        rotation = rotation + 360
    
    if rotation > 180:
        direction = right
        rotation = 360 -rotation
    
    # Now rotate <rotation> degrees in <direction> direction
    

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 1970-01-01
      • 2011-05-17
      • 2015-09-07
      • 2022-01-02
      相关资源
      最近更新 更多