u4099 created page: Lesson4Week6 authored by Daniel Jung Moltzen's avatar Daniel Jung Moltzen
......@@ -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
......
......