Adaptive mapping for newbie

Hello everybody,
I am new with programming and arduino, so thats why my questions are maybe so stupid..:) Iam trying to write code (my version of adaptive mapping) for this robot platform - http://i40.tinypic.com/tz9kl.jpg
It has two motors and two wheel encoders. Now what about code:
There are three main parts of code:

  1. Robot goes, scans area where he can go and where no, and stores this information(map) to SD.
  2. When the area is scanned and the map is complete. We can give a command to robot - go there or here(go to the target).
  3. If on the way to target the old way (that is stored to SD) not more actual, because there is something on the way (chair or something else). He need to change the map on SD and write that this way is no more possible. Calculate a new way to target and go there.
    The first part of the code I think I know how to write. Map would look like on the picture, should be discretized into square units exactly the same size as the robot. The robot can turn only 90 degrees.
    And I will store the the information to the map like this 500500, the first three digits are X and the second 500 is Y. The docking station will be 500500(X=0,Y=0)
    If x = 12, y = 74 it will be 512574
    If x = -50, y = -20 it will be 450480

And now comes the question:
For example
500500 – Robot is here(docking station).
497502 - Target.

So the code must look something like this
read current position;
read target position;
currentpostion = 500500;
target position = 497502;
if(current position != target position)
and here comes the clever algorithm..:slight_smile: that should tell go to the 500501
if (500501 == free(read PING)) {
go to new postion = 500501;
}
else
write to map(SD) 500501 is not free;
clever algorithm();

So maybe can give me a tip how should look like this clever algorithm that calculate the way to target?

Why Iam I using 500500 and not x=0,y=0, because for me(newbie) this way seem more easy. So the result should be something like this http://www.youtube.com/watch?v=N7zDiSPa3_E P.S. Why I dont use the code from clever guy thats on the video? Because the code is to difficult for me and I cant understand it. So it is better to write my own then I will able to change or to configure it.
Thank you very much!

It is probably a better idea to cut down the problem into two smaller problems: Waking along x and along y axis.

current_x_position = 500
target_x_position = 502

current_x_position = cleveralgorithm( current_x_position, target_x_position )
...

how would you program "cleveralgorithm"?
Hint: Note that target_x_position can be smaller than current_x_position.

Once you have written cleveralgorithm you can apply the same procedure to the y axis.

Oliver

Hallo nach Deutschland:)
Yes you are right maybe it is better to cut it down, but! If for example on the x way is something and to pass it you need to go at first y way..
So I think it would be better that clever algorithm "counts" x and y at the same time.

olikraus:
how would you program "cleveralgorithm"?
Hint: Note that target_x_position can be smaller than current_x_position.

So you think it is better to use start point x = 0, y = 0. But then if I turn left or I go backward, coordinates will be with - (minus)..

Hallo nach Deutschland:)

Grüße zurück aus dem völlig verregneten Deutschland

and, yes, sure, if cleveralgorithm is implemented like this:

a = cleveralgorithm(a, b)

with

cleveralgorithm(a, b)
if a > b then
return a-1
else
return a+1

then, for sure you can interleave x and y axis:

while ( current position has not reached target position )
if current x is not equal to target x
x = cleveralgorithm(x, target x)
if current y is not equal to target y
y = cleveralgorithm(y, target y)

Oliver