I am not the most knowledgeable on this subject but, you seem to be taking the distance out of the encoder, since a drivetrain is set up for continuous motion shouldn’t your PID be targeting a specific rate at which the wheels should be spinning? (assuming this is for dynamic input, such as driving in teleop, not autonomous movement) There is a rate output on the encoder, so do you want your code to look a little more like this?
Code: http://i.imgur.com/5Jja5Ce.png
What I have written here may just be a load of garbage. It has not been tested, it just seems logical to me. I tried to comment my thought process.
I may have not been clear as to what this PID is meant to control. We are planning on a swerve type of drive system, where the encoders are meant to keep the wheels at a set “zero” position and then rotate at the direct control of the joystick, with the max position of 90 degrees calculated out to be the 124 pulses or “Distance” value on the encoder. So, in my opinion, no, the rate of the encoder should not be what I am looking for/ trying to control.
My first impression is that your proportional gain is very high, which is likely to result in lots of overshoot and oscillation. My second impression is that your integral time is very short, which is likely to result in lots of overshoot and oscillation.
Start by setting the gain very low and the times to zero (which will disable the integral and derivative terms). Put the appropriate load on the motor and start increasing the gain until it becomes unstable, then back the gain down again. If you don’t get to the set point in a reasonable amount of time, set the integral time to a value slightly longer than you think it should take to get to the set point, and tweak it from there. You might be able to ignore the derivative term completely.
I will do all of this as soon as possible.
You’re being set up for failure if you’re trying to control to +/- 1 sensor tick. I always aim for getting 10 times the resolution compared to the accuracy requirements.
I’m not sure what you mean by getting 10 times the resolution compared to the accuracy requirements.
So from the OP, it appears that you are using a 500 pulse encoder mounted directly on the motor shaft? Do you have any gear box before the wheels and what is the ratio? What size wheels? Assuming a 5:1 gearbox and a 4" wheel (~12.56 circumfrence) would give distance resolution of 0.005" Is that really what your accuracy requirement is? I recommend double checking your requirements.
We are using a seven pulse per rotation encoder mounted on a gearbox with a 71:1 reduction, so there are 497 pulses per motor rotation. Since we are only wanting to rotate 90 degrees clockwise or counterclockwise, we divide that number by 4, getting 124.25, or for our purposes, 124, pulses.
I want to reiterate that we are using these motors and encoders in the context of mounting them on top of our drive motors and rotating them 90 degrees clockwise or counterclockwise, allowing a “sideshifting” motion, increasing field mobility.
Thank you all for your input, and I hope I addressed all the issues properly.