There will be a lot to absorb here so just take everything step by step. I definitely didnt figure all this overnight, but took me many many months to get it all working.
If you want to build a robot from 'scratch', check out this how to build a robot tutorial:http://www.societyofrobots.com/step_by_step_robot.shtml
But don't use the ATmega8 as in the tutorial, use the ATmega168 (its basically the same, but more memory):http://www.societyofrobots.com/step_by_step_atmega168_swapout.shtml
The largest map you can get with this is a ~15x15 grid, so if you need more then you will have to go with a larger ATmega. Check the atmel AVR selection site
to choose a different one (the pinout will probably be different).
Then after you have that working, you want to add a sharp IR:http://www.societyofrobots.com/robot_50_robot_sharpIR.shtml
and also encoders
. You can either make them yourself to save money, or buy a kit like this:http://www.acroname.com/robotics/parts/R238-WW01-KIT.html
You will need a PID control algorithm
to get the encoders to work properly. The create does encoders for you, but you aren't allowed direct access to them (or at least I couldnt figure out how).
After you get all the above done, you are ready for mapping:http://www.societyofrobots.com/programming_wavefront.shtml
I also have a doubt about how your robot kept in its memory about the intial and final position.I guess initially you fed the information that there are two points on a straightline seperated by some distancance..is it right?..
nope, when I programmed in the map (a matrix) I prefilled in the goal and starting robot location. As the robot explored, it updated the map for objects it found.
edit: ha! cooldog beat me to half of what I just said
(good job cooldog!)