Skip to content

Commit

Permalink
Fixed bug in pid controller
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebHeydon committed Feb 18, 2020
1 parent 982bcef commit c621826
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/org/aluminati3555/lib/data/AluminatiData.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public final class AluminatiData {
// Library
public static final int LIBRARY_VERSION = 14;
public static final int LIBRARY_VERSION = 15;

// Robot delay
public static double robotDelay = 0.02; // Seconds
Expand Down
7 changes: 5 additions & 2 deletions src/org/aluminati3555/lib/pid/AluminatiPIDController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public String toString() {

private double integral;
private double lastError;
private double currentError;
private double lastTimestamp;

/**
Expand All @@ -68,6 +69,7 @@ protected void setPID(double kP, double kI, double kD) {
public void reset(double timestamp) {
integral = 0;
lastError = 0;
currentError = Double.POSITIVE_INFINITY;
lastTimestamp = timestamp;
}

Expand All @@ -78,9 +80,9 @@ public void reset(double timestamp) {
*/
public boolean isComplete() {
if (allowableErrorEnabled) {
return (Math.abs(lastError) <= allowableError);
return (Math.abs(currentError) <= allowableError);
} else {
return (lastError == 0);
return (currentError == 0);
}
}

Expand All @@ -107,6 +109,7 @@ public double update(double setpoint, double currentPoint, double timestamp) {
double i = kI * integral;
double d = kD * (error - lastError) / dt;
lastError = error;
currentError = error;

double output = p + i + d;
if (output < -maxOutput) {
Expand Down

0 comments on commit c621826

Please sign in to comment.