Exploration algorithm for robot

Hello arduino folks! I need some guidance of how to build my algorithm for my robot. I want my robot to get as far from its starting point as possible. The robot is fairly simple, I have an arduino which controlls the two motors a servo(180 degrees) a maxsonar distance sensor mounted on the servo

So far I have though of an algorithm which looks something like this

  1. Read the distance from the Sonar at every degree and store them in an array.
  2. Using trigonometric formulas calculate every coordinates distance from origo.(which will be the same place as the robots position in the first cycle)
  3. Chose the coordinate with the greatest value from origo.
  4. Turn robot so its facing in that direction
  5. Drive until the distance sensor gives a reading of 30 cm.

What do you think of that algorithm? It's very easy to write the algorithm like that but when coding it becomes a lot more difficult. In that algorithm for example my robot has to keep track of its own position relative to origo which might be difficult cause i dont have any encoders on my robots wheels. I might also buy a compass sensor so i at least can get the robots exact degree. Thank you very much!

  1. Read the distance from the Sonar at every degree and store them in an array.
  2. Using trigonometric formulas calculate every coordinates distance from origo.(which will be the same place as the robots position in the first cycle)
  3. Chose the coordinate with the greatest value from origo.
  4. Turn robot so its facing in that direction
  5. Drive until the distance sensor gives a reading of 30 cm.

If the distance that the sonar can see when it is pointed in some direction is less than it can see in some other direction, does it make sense to store that value? In the end, you only have one maximum distance, so only one calculation to perform.

How will you turn the robot in that direction? In other words, how will you know that the robot has turned the correct amount?

What makes you think that heading in the most open direction at any given point in time will result in the robot, after several turns, having reached any kind of maximum distance?

As an example, suppose that the robot could go east for 1 meter or west for 1/2 a meter. Suppose that it goes east, for that one meter, and then finds that the only two ways it can go are north for one meter or west for 1.5 meters. Which way would you go? Back the way you came? Or north? Going north gets you farther from the origin, but perhaps if you went west instead, you'd find a path south that got you 20 meters open space.

Just knowing the most open direction at any position is not the way to run away from home the farthest.

So, I guess I don't think much of your algorithm.

which might be difficult cause i dont have any encoders on my robots wheels.

Might is an understatement. Damn near impossible is more accurate.

I might also buy a compass sensor so i at least can get the robots exact degree.

You misspelled approximate.

That was a bit harsh. A :)