Joe,
Thanks for the info about your system.
I have made some progress tuning my servo over here for a constant 40 RPM. Initially I was seeing the exact same behavior you were reporting. I am using an external counter to verify the velocity I am trying to achieve and at first I was getting a veloicty anywhere between 37 RPM and 42 RPM. After making some changing in my approach to tuning the servo I have been able to get the actual RPMs to stay between 39.2 RPM and 40.15 RPM (a huge improvement). I think I can get much better control if I use a higher resolution encoder (which I am currently working on acquiring). I am currently using a 500 count encoder and have tuned the motor so well that I am always within -1 to 1 count of where the motor is supposed to be. I believe that if I use an encoder with 4 times the resolution, that I should be able to achieve 4 times the accuracy.
Below is the approach I took which allowed me to achieve my current accuracy.
1. I left my Kd constant at 0 and used Kv instead. The Kv constant is extremely similar to Kd, but the Kv constant works much better when trying to achieve precise velocity control, because it is a direct measurement of the motor's velocity instead of the derivative of the position changes of the motor. Making this change reduced my constant following error from 30 counts to 6 or 7 counts.
2. I tuned the motor using the step response tool available in Measurement Automation Explorer (MAX). The catch is that I did not use the default "Step Length" of 1000, rather I tuned my servo so that I had a perfect step response for a step length of 4. The reason I tuned the servo to a step length of 4 instead of 1000 is that a step of 4 more closely simulates the movement of a servo during constant velocity move. When doing a constant velocity move, the servo is recieving a constant command to move the servo a few steps over and over again. For example if I tell the motor to move at a constant velocity of 10 RPM, then the NI-Motion driver (using PID) calculates a target position for the motor. The result is a continuous sequence of individual position moves that result in a constant velocity. The sequency of moves might look like below...
Move to 10, Move to 12, Move to 14, Move to 16, etc., etc.
Likewise if we were trying to move at 20 RPM instead of 10 RPM, the sequence of moves might look like...
Move to 10, Move to 14, Move to 18, Move to 22, etc., etc.
in essence doubling the velocity of the move.
So, tuning to a step response of 4 will result in a servo better tuned for constant velocity, as opposed to tuning to a step response of 1000 which will tune a servo for large position moves.
Using this approach I was able to reduce my following error from 6 or 7 counts to -1 to 1 count.
My final values for the PID loop were...
Kp = 550
Kd = 0
Ki = 50
Kv = 15000
and a loop rate of 250us.
Like I said above, I believe I can achieve better precision with a high count encoder. Once I get my hands on a higher count encoder I will post an update.
Lorne Hengst
Application Engineer
National Instruments