On 1389, we reimplemented PIDController to fit our code design, so I don't have any direct experience with the WPILib version, but here is the process I just used to try to figure out how to use it properly:
check out
this page on using the WPILib encoder class.
The screensteps explains just how to get the information you want from the encoder: use getDistance() or getRate().
With regard to using it with a PIDController:
When you pass an object to a PIDController as a PIDSource, that object must implement the PIDSource interface. Most of the sensor classes in WPILib implement this interface, and can be used as a PIDSource.
The interface includes a method called getPIDSourceType. This is intended to be used by the sensor to tell the PIDController how the sensor should be PID tuned: an ultrasonic sensor would be kDisplacement, a gyro would be kRate (by default) and an encoder can be EITHER rate OR displacement.
If the sensor's getPIDSourceType() method returns kDisplacement, the PIDController will set itself up for distance mode, and if it returns kRate, the PIDController will set itself up for velocity control mode.
As we can see in the
source code for the Encoder class, it already implements the PIDSource interface, which means it can be passed to the PIDController as a source of input. What we need to find out is whether it will be used as a rate source or a displacement source. We can see that the encoder is set up to return either rate or displacement, as set in the instance variable: m_pidSource, but this variable is set to private. by default, it looks like the encoder sets it to kDisplacement
To someone involved with WPILib, what is the intended way of setting the preferred encoder mode to kRate? there appears to be no way to set the mode yourself.
EDIT: you can use encoder.setPIDSourceType() to set the encoder to velocity mode