meassuring distance and keeping directions

im working on a small robot, and i need a way to know its position. im currently making a tachometer out of an old PS2 mouse’s optical sensor. however it will only think that it is going in a straight line. ive been suggested using the mouse wheel encoder, that came with the same mouse, by placing it on the wheel. but in this case its not an option because the whole body tracks and wheels are premade. http://www.thingiverse.com/thing:19170

So can anyone suggest sth that would work as a compas for my robot?

Please and Thank You!

How accurately do you want to know the position?

Encoders on the tracks will give rough position information, but tracks always slip to varying degrees.

An overhead video camera connected to a PC will give accurate position information.

Any magnetometer will tell you what direction the robot is pointing, but it must be placed as far as possible from the servo motors and calibrated in the robot.

im planing on using a magnetometer (http://www.adafruit.com/products/1746) but it would be quite close to servos, within 10 cm. is that too close?

At the very least, you will have to recalibrate the magnetometer because of the magnets in the servos.

Many people put the magnetometers up on poles to lessen the problem.