PID and Compass

Hello everyone,

Recently I bought a pair of motors in Pololu http://www.pololu.com/catalog/product/1093 and a Shield H Bridge for the Arduino. I made ??a cart with the engines, but when i turn on, sending a PWM signal equal to the two engines they rotate in the same direction except that a motor turns faster than the other so that the cart be turning around its own axis. I was desperate because I thought that the engines because they are quality and identical, have a minimum of semelhançana speed, but not what happened.

With this project, I want to build a robot, which will have the magnetometer being used as a compass.
I'd like to hear from you regarding this difference in speed of the motors, in which case, I can not at least make the robot go straight in one direction.

I've been reading on the PID control of motors, but do not know how to use it with a compass. Do you have another idea what I could do to these engines to walk straight?

Since you already appreciate the help from everyone.

Sorry for my bad english.

a hug.

For a PID loop you only need to measure the difference between what the sensors are reading and what you want them to read. It works for controlling temperature if the sensor is a thermometer. It works for motor speed if the sensor is a motor speed sensor. It should work for keeping a magnetic heading when the sensor is a compass. You can control one one motor for speed and let the PID loop control the other motor to maintain a magnetic heading.