2

I have a mobile robot that has a distance sensor attached to a panning servo motor. The motor rotates continuously to move the sensor from 0 to 180 degrees and back.

The distance sensor sends a signal every few miliseconds to scan its surroundings for obstacles. One can visualise the data generated by the distance sensor like this:

enter image description here

I wish to create an algorithm that allows the robot to move in the direction where there is the most space available (or the least obstacles).

More formally, I can represent the inputs and outputs like:

  • input: array of distances to the nearest object for each angle of motor rotation.

  • output: a single value representing the optimal angle.

The requirements for the algorithm are:

  • should not be susceptible to outliers in data (the sensors sometimes spike unpredictably)
  • does not need to be absolutely optimal, 1-2% off is acceptable
  • efficient (this will run on a small microprocessor)
  • understandable to a hobbyist (I am not a ML expert ;) )
Michał Czapliński
  • 1,332
  • 1
  • 14
  • 24
  • 1
    1-2% off of what? whatever it is it will be pretty hard to achieve. any ideas? did you try anything? (this is considered a requirement here to get help) – Piglet Apr 12 '16 at 13:51

1 Answers1

0

I don't know the language you are using (I am a Java and C# guy), so I will just use pseudo code:

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
          }
        }
     }

You could also do two sweeps with the sensor and compare the distances at each point to see if there are any spikes, but given the specs you listed this should work.

Jedi_Maseter_Sam
  • 753
  • 4
  • 24