Unless you have some other form of control on the motor, you need more than 1 encoder count per .001" if you want to position to .001". I heard that a rule of thumb was that you needed 10 encoder counts per the amount you want to position to. The reason for this is that the output is based on error, that is the difference between desired position and actual position. P = error X Kp (proportional gain). D is the rate of change of the error, for example, if you're 2 encoder counts off and the error is getting larger, you can use a larger response. If your 2 encoder counts and zeroing in on the desired position, you can lower the response. The I gain is integrating the error over time, for example if you need to be in position under a load, such as a vertical axis fighting against gravity. Say for example it takes 10% of the motors torque to hold the vertical axis in position. You'll never get in position with just P and D because it take an error to get the 10% torque out of the motor. "I" will slowly (compared to the responsiveness of P & D) build up until the position error is zero and the torque will be the 10% required to hold the position.
There are PIC servo application notes on Microchips website that you can get the actual code, schematics, etc.
This "PIC project idea" that I have involves a second closing of the control loop. The basic idea is to have the PID control the servo, and the CNC controller to command a velocity based on the error between the desired position and the feedback position.
I think the tightest following using servo or steppers would use velocity feed forward, P, and perhaps D to close the position loop. |