Making a Vehicle Drive Straight

Dear Arduino Forum Members,

I am building a robot with the purpose of just driving straight for a certain distance. I am using an Arduino Uno with an Adafruit motor shield. The problem I am encountering is that the robot refuses to drive straight. Sometimes it veers off to the left, and sometimes it curves to the right.

I have tried adjusting the speed of each motor individually, but strangely it has not been to much avail. The first time I ran the robot, it curved to the right. This lead me to try making the left motor slower. I did this, and experimented with a variety of values, but it started turning to the left. Then, I made the speed of the motors equal, again, and the robot curved to the left.

I have no idea what is causing this, or how to fix it. Any advice would be very appreciated.

Sincerely,

trin1709

I'm sorry, I forgot to say:
I'm using these DC motors: https://www.sparkfun.com/products/13302

Hi,
These are DC motors that have no speed regulation, so they will always vary compared to each other.

You would have to "close the loop", combining information on how far each motor has ACTUALLY turned. This is usually done by adding "encoders" to each motor.

Example HERE

Or see lots of this subject on THESE LINKS

Although, even if you ensure the wheels turn the same revs, that's still no guarantee since the circumferences may be unequal, and there may be more slippage on one side compared to the other.

Your 'bot needs to be able to detect the outside world and steer relative to some external reference point - or maybe you could use a gyro and a compass.

...R

+1 for the compass. Much simpler than using encoders.

A properly calibrated (very, very important!) magnetometer allows your robot to determine its orientation relative to magnetic North.

Use differential steering to maintain the desired orientation or heading as your robot moves, and it will move in a straight line. Add in heading changes and your robot will go anywhere it can.

Accurate wheel diameters and encoders can make straight line progress possible. The smaller/cheaper the motors
and gears, the more friction and random variation will disturb the navigation.

Hi everyone,
Thank you so much for your responses.
It seems to me that perhaps tilts in the floor are the cause of the aberrations. Does that sound correct?
I've looked into compasses and gyros a little bit. Are there any specific ones you recommend?
Are there any tutorials you think are best?

Thanks,
trin1709

A digital compass will need to be sited well away from any motors or other magnetic components, and
you will need to calilbrate it (soft and hard iron correction).