A PID controller is done in software. you have to use encoders to measure speed or distance.
example: controlling the rpm of a motor.
collect the number of encoder pulses over a set period of time say 50ms
the amount of pulses will tell you the rpm.
Now you analyze the "feedback" (encoder pulses)
P (proportional): how far from the desired rpm was the motor running?
I (integral): total error. After each sample add the proportional error to this term.
D (derivative) compares the error of the current feedback, to the previous (change in P) error now - error before.
To make the controller work you have to assign constant values for these kp, ki, and kd. These values are dependent on your motors, and must be found experimentally.
the end equation is
for 8-bit pwm
input = kp*P+ki*I+kd*D
//this prevents values from being out of range
if (input >255) input = 255;
else if (input <0) input = 0;
motor_pwm = input;
hope that helps.