Soccer Player Robot -- 2xMotor Control with PID

Hi:

I am working on a project that requires building a robot which collects balls from the field and scores them.

I am stuck on a little programming problem. Here are the parts I am using which are involved in the current problem i am stuck on 1. Arduino UNO Microcontroller: http://arduino.cc/en/Main/ArduinoBoardUno 2. Two Quadrature Encoders: http://www.lynxmotion.com/p-448-quadrature-motor-encoder-wcable.aspx 3. Two Geared Motors (50:1): http://www.lynxmotion.com/p-96-gear-head-motor-72vdc-501-175rpm-6mm-shaft.aspx

PROBLEM: The two motors are not exactly to specs (typical manufacturing problem), which is resulting in them not turning with same speeds. So I tried to program a PID controller, and it proved successful up to a certain extent. So I would rotate one wheel manually and the other would follow. It is still not tuned well.

Now what I was to do is to make a program that would receive a command (I am using the xbee wireless module) of going forward, and then it will move BOTH motors together and adjust them automatically. I am not sure how to structure my code so that I would allow the two wheels to rotate and adjust everytime they receive a command. Currently, I have the PID controller setup in a loop and it will read the encoder value from Motor-1 and adjust Motor-2 accordingly.

What's the best way to make both motors now automatic? Can I create a two loop functions and work it out somehow?

Thanks alot

The two motors are not exactly to specs

Not identical and not within specs are two different things. If one of the motors is not within spec, send it back for a replacement.

What are the encoders doing? They should be providing speed information. For each side, you should be able to tell how many turns a motor or wheel has turned. Knowing the diameter of the wheel on that side, you should be able to determine how far each side has traveled. On the other hand,

I am working on a project that requires building a robot which collects balls from the field

implies outdoors on a grass field, where there is no guarantee that the wheel maintains slip-free contact with the ground.

This isn’t a programming problem as much as it is one of not enough information. You are going to need something else to provide heading information, and to use that heading information to drive the robot. Speed up one side or the other as the actual heading deviates from the desired heading.