我有一个移动机器人,有一个距离传感器连接到一个摇摄伺服电机。电机连续旋转,将传感器从0度移动到180度,然后向后移动。
距离传感器每隔几毫秒发送一个信号,扫描周围的障碍物。我们可以像这样可视化距离传感器生成的数据:

我希望创建一种算法,允许机器人向有最多可用空间(或最小障碍)的方向移动。
更正式地说,我可以表示输入和输出,例如:
该算法的要求是:
发布于 2016-04-21 20:23:42
我不知道您正在使用的语言(我是一个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
}
}
}你也可以用传感器做两次扫描,并比较每个点的距离,看看是否有尖峰,但是根据你列出的规格,这应该是可行的。
https://stackoverflow.com/questions/36569078
复制相似问题