我不知道你所使用的語言(我是一個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
}
}
}
你也可以做兩次掃描與傳感器和比較每個點的距離,看看是否有尖峯,但考慮到你列出的規格應該工作。
1-2%的折扣是什麼?無論是什麼,都很難實現。有任何想法嗎?你嘗試過什麼嗎? (這裏被認爲是需要獲得幫助的要求) – Piglet