... | ... | @@ -112,21 +112,23 @@ public class PIDCarController { |
|
|
|
|
|
LCD.clear();
|
|
|
LCD.drawString("Light: ", 0, 2);
|
|
|
LCD.drawString("Error: ", 0, 3);
|
|
|
LCD.drawString("Turn: ", 0, 4);
|
|
|
LCD.drawString("PowerA: ", 0, 5);
|
|
|
LCD.drawString("PowerC: ", 0, 6);
|
|
|
|
|
|
while (! Button.ESCAPE.isDown())
|
|
|
{
|
|
|
|
|
|
{
|
|
|
LCD.drawInt(LightValue,4,10,2);
|
|
|
LCD.drawInt(error,4,10,3);
|
|
|
LCD.refresh();
|
|
|
|
|
|
int LightValue = light.readValue();
|
|
|
error = LightValue - offset;
|
|
|
|
|
|
|
|
|
|
|
|
//calculates the error by subtracting the offset
|
|
|
error = LightValue - offset;
|
|
|
|
|
|
//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
|
... | ... | |