Hello.
I looked over your code and did not notice anything obviously wrong. It sounds like it might be a problem with the tuning of your PID constants, since your line-following robot can follow a straight line just fine. You can find some helpful hints in this post by Ben on how to tune PID constants.
- Amanda