寻找机器人导航的算法

时间:2016-04-12 09:27:40

标签: python algorithm computer-vision robotics

我有一个移动机器人,它有一个距离传感器连接到平移伺服电机。电机连续旋转,将传感器从0度移动到180度并返回。

距离传感器每隔几毫秒发送一个信号,扫描周围的障碍物。人们可以看到距离传感器生成的数据,如下所示:

enter image description here

我希望创建一种算法,让机器人在可用空间最多(或障碍最少)的方向上移动。

更正式地说,我可以代表输入和输出,如:

  • 输入:每个电机旋转角度到最近对象的距离数组。

  • 输出:表示最佳角度的单个值。

算法的要求是:

  • 不应该容易受到数据中的异常值的影响(传感器有时会出现不可预测的峰值)
  • 不需要绝对优化,可以接受1-2%的折扣
  • 高效(这将在小型微处理器上运行)
  • 对业余爱好者来说是可以理解的(我不是ML专家;))

1 个答案:

答案 0 :(得分:0)

我不知道您使用的语言(我是Java和C#人),所以我只使用伪代码:

EPSILON : Float = .02f -> this is our margin of error

DIRECTION : Integer = 0 -> the best direction to go

DISTANCE : Float = 0 -> the furthest distance from the robot

DISTANCES : Float[181] -> the values you get from your sensor

DISTANCE = DISTANCES[DIRECTION] // set the first distance

     for(int index = 1; index < size_of(DISTANCES)-1; index++) {
        //we are checking if the value is within 2% of the previous and next values
        if((DISTANCES[index-1] * (1+EPSILON) >= DISTANCES[index] AND
            DISTANCES[index-1] * (1-EPSILON) <= DISTANCES[index]) OR 
           (DISTANCES[index+1] * (1+EPSILON) >= DISTANCES[index] AND
            DISTANCES[index+1] * (1-EPSILON) <= DISTANCES[index])) {
       //if the distance at index is greater than the current max distance,
       //we set that to be the new max distance
        if(DISTANCES[index] > DISTANCE) {
           DISTANCE = DISTANCES[index]
           DIRECTION = index
          }
        }
     }

您还可以使用传感器进行两次扫描,并比较每个点的距离,看看是否有任何尖峰,但鉴于您列出的规格,这应该有效。