I think it is just you proportional and derivative is too small or to big.
Try setting d to 0 then increasing p until it is oscillating, then increase derivative until it fixes it.
First of all I would recommend reading this article - Introduction to PID as well as this pdf - Documents. In your code you are making the velocity for the motors way more complicated than it needs to be. You can completely get rid of the mPRM rariable and toTravel variable. All you need to do is feed the power variable to the motor velocity. Another problem is that your wait time is way to long, I would recommend 5-10 milliseconds. You are waiting 15 seconds for your loop which means that if you set the left motor velocity to let’s say 50% from the PID loop and -50% for the right motor velocity. This will cause your robot to turn right. If you want to go to for example 90 degrees then your robot might turn to 90 degrees in 2 seconds. For the next 13 seconds the robot will continue turning causing error. I would also add the I part of the PID loop so that your robot isn’t too slow. This is also an unused variable that I would get rid of distTraveled = distTraveled + toTravel
It looks like it is converting the rpm to distance in some sort of unit, for my PID loop I use the motor encoders directy, here is how I do it -
-- Note this code is in C++
leftwheeldist = leftdrivemotor.position(degrees) * (wheel_circumference / 360) / gear_ratio;
rightwheeldist = rightdrivemotor.position(degrees) * (wheel_circumference / 360) / gear_ratio;
I would also add another PID loop for error with heading so that if your robot gets hit off in the wrong direction by a certain amount of degrees it can correct itself. I would also add a function for turning.
This is replying to Banana Pi, it is probably because it is running into an infinite loop error, try setting the wait time to something very small, see to my other post