... | ... | @@ -123,12 +123,13 @@ public class PIDCarController { |
|
|
LCD.drawInt(error,4,10,3);
|
|
|
LCD.refresh();
|
|
|
|
|
|
// Current light reading
|
|
|
int LightValue = light.readValue();
|
|
|
|
|
|
//calculates the error by subtracting the offset
|
|
|
// Calculates the error by subtracting the offset
|
|
|
error = LightValue - offset;
|
|
|
|
|
|
//calculates the derivative by subtracting the current error with the last error
|
|
|
// Calculates the derivative by subtracting the current error with the last error
|
|
|
derivative = error - lastError ;
|
|
|
|
|
|
// To avoid wind up and high integral value, we reset it to zero if the error equals
|
... | ... | @@ -138,7 +139,7 @@ public class PIDCarController { |
|
|
integral= 0;
|
|
|
integral = integral + error; }
|
|
|
|
|
|
// Here we calculate the value for the turn
|
|
|
// Calculate the value for the turn
|
|
|
turn = (int) ((Kp * error) + (Ki * integral) + (Kd * derivative));
|
|
|
|
|
|
// Instantiates the power for the two motors
|
... | ... | |