How to make a robot go straight?

My bot has two rear wheels connected to the motors and a castor wheel in the front.
How domake it move in a straight path.

  1. Should i make use of a ultrasonic sensor and make it follow a wall?

  2. I have read online that rotary encoders can be used too. I did understand the concept but unable to figure out how to implement. Can someone guide me on how to implement the same on my bot

  3. Should i replace the castor wheels when two front wheels. They wont be connected to motors but then i guess they will make the bot more stable with respect to direction. But then it will make turnings difficult since they cannot be controlled in any way(as they are not connected to motors).
    So Castor wheel or Two Front wheels?

Hi,
Even identical motors do not turn at the same speed, so the bot will always tend to drift left or right! You could use encloders but expensive and xomplex to use (I've never tried them) but if you control the motor's speed via PWM you can trim the PWM value on the motor that is in error (too fast or too slow) and do it that way, that's how I do it.

See my bots at www.melsaunders.co.uk under electronics..

Hope it helps, regards.

Mel.