There are a number of bugs with the current WPILib PIDController implementation. The python implementation follows the java implementation closely, so it shares these issues. Here are bug reports on WPILib's github site:
- #29: PIDController: setSetpoint causes onTarget to be false
- #30: PIDController: race condition for enable/disable and PIDWrite
- #31: PIDController: getError() is incorrect when setContinuous is True
In particular, #29 is probably the one that is biting you (it bit me for a similar reason). If you keep calling setSetpoint (like that example does), each time it is called it will reset things such that onTarget is false, which means the robot will never stop oscillating.
There are a number of ways of dealing with this problem -- the easiest is to not call setSetpoint if the input is close (within 0.001) to the original input. However, this isn't satisfactory either for a number of reasons... so I ended up writing my
own magicbot-compatible implementation, it'll be part of magicbot next year.