I know there were many similar topics, but I am still confused. I cannot get the right values of pid. I know the whole 'procedure' or finding pid values. I tried many times, many combinations. Still nothing. It is even hard to find the value of kP when the robot oscillates, because it's kind of vibrating at balanced position for most of the time. The best I did, it was vibrating for 3 seconds and then falling over. I tried with only PD, only PI or all PID. The other thing is I had to 'move' the speed from 0->255 to 70 -> 255 because my motors don't move at low values. These are motors I am using: http://www.ebay.ie/itm/141580923267?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
float lastError = 0;
float integrated = 0;
float setPoint = 0;
float error = 0;
float Pterm = 0;
float Iterm = 0;
float Dterm = 0;
// set PID gains
float kP = 120;
float kI = 0;
float kD = 190;
// set max and min outputs
int outMax = 255;
int outMin = -255;
float calcPid(float currentInput)
{
error = setPoint - currentInput;
Pterm = error * kP;
integrated += error;
Iterm = kI * constrain(integrated, outMin, outMax);
Dterm = (error - lastError) * kD;
float calcPID = Pterm + Iterm - Dterm;
if(calcPID > 0) calcPID = calcPID + 70;
if(calcPID < 0) calcPID = calcPID - 70;
calcPID = constrain(calcPID, outMin, outMax);
// remember variables
lastError = error;
// send pid to drive motors
return calcPID;
}