Line follower PD problem in the curves

Hi everybody I need help with a small problem, i am using baby orangutan b328, sensors 8QTRC, and two motor 10:1;
i am programing in Arduino IDE with the library of QTR and OrangutanMotors

void loop()
{
  ///////////
  unsigned int sensors[6];
  ///////////
  int position= qtr.readLine(sensors);
  //////////
  int error = position - 2500;
 
  ///////////  
  int motorSpeed = KP * error + KD * (error - lastError);
  ///////////
  lastError = error;
  
  ////
  int M1=80;
  int M2=80;
  ///////////
  int m1Speed = M1 + motorSpeed;
  int m2Speed = M2 - motorSpeed;
  ///////////
 if (m1Speed <0)
    m1Speed = 0;
 if (m2Speed <0)
    m2Speed = 0 ;
/////////
//////////  
 motors.setSpeeds(m1Speed, -m2Speed);

I need help, how make that my follower aplicate brakes in the curves, my follower is ok when follows straight line but when is a curve, it is unstable.

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