The following is the text of an email but it goes over the basics of a PID control. There are three links on this page if you want a more formal explanation: I see the question: "What is a PID?" a lot so I'll try to put down what I know here. Hopefully it will be of use.
PID=Proportional, Integral, Derivative
What follows is a non-technical description. For a technical description, visit:
Alex Brown's PID Information (pretty good - not too technical)
Proportional, Integral and Derivative are types of feedback, usually used in a motor control circuit of some sort. Basically, you get encoder feedback from the motor (some sort of feedback that says how fast the motor is turning) and you then manipulate the feedback so that you can adjust the motor speed.
A very good example of a PID is the cruise control on a car.
Proportional feedback is a direct feedback (usually multiplied by a gain factor) that is added to the power applied to the wheels. If the feedback is negative (meaning you are over the speed required) then the power gets decreased and vice versa. Proportional control is derived from the difference between requested speed of the drive and actual speed. This is a very effective method and the use of proportional control alone is probably sufficient for many applications. I went nerdy and decided to implement the other two gains. One disadvantage of proportional only gain is that, under load, the system will settle into a slight offset from requested speed (especially if we are using fractional gains). I added in Integral Feedback to stop the offset issue (which was a non-problem for my robot tolerances).
Integral feedback is an ADDED feedback that is the result of the *accumulation* of the proportional control errors. This sum is then scaled by the integral gain (usually fractional). This stops the motor from running up to a point just above or below the requested speed and then hanging there - not having enough gain to overcome the difference in speed Vs. requested. After a few samples, the integral gain will build to the point that it will overcome the offset.
Derivative feedback is based on the *difference* between *successive* readings of the encoders (encoder input is usually a digital reference of the analog speed - ADC) and is scaled by a gain constant before being *subtracted* from the motor control requested speed. This creates a dampening effect that lessens the tendency for high Pgain feedback loops to overshoot the desired speed and oscillate like crazy. Using derivative feedback, you can get much higher gains in the circuit without going unstable.
Using the PID idea, you can adjust the hardware PWM of a PIC so that the duty cycle to the motors varies according to your desires. The 'bot can turn, go a set distance at a set speed with good accuracy, maintain equal speed on both wheels, etc. For a great discussion on PWM (needed if you do this) then visit the latest Seattle Robotics Society page and click on the September 1999 Encoder http://www.seattlerobotics.org . For a really inadequate Real Movie of a 'bot using the above information to do a 20 foot 'out and back' see: http://126.96.36.199/robots/skinny.html and go to the link at the bottom of the page.
The tricks to doing it in PBasic Pro are mainly centered around getting fractional (decimal) gains and handling negative numbers. Fractional gains can be faked by using 180 to mean 1.8 (as an example). Negative calculations e.g.: negative -100 / 2 will get you a large positive number in PBasic) must be handled by detecting them, and then doing a series of absolute calculations (abs function) ending up with a subtraction from 0.