from greg

Fork of PID by Greg Abdo

Files at this revision

API Documentation at this revision

Comitter:
oprospero
Date:
Mon Jun 09 00:07:12 2014 +0000
Parent:
10:3296a2150efe
Child:
12:9d078cd8ca83
Commit message:
changed dt back to mircoseconds

Changed in this revision

PID.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PID.cpp	Sun May 25 22:53:48 2014 +0000
+++ b/PID.cpp	Mon Jun 09 00:07:12 2014 +0000
@@ -37,8 +37,10 @@
     // How far away we are from the target
 //    currentError = targetPosition - currentPosition;
 
+    
+
     // Sum of the errors the controller has incurred over time
-    integralError += currentError * dt / 1000;
+    integralError += currentError * dt / 1000.0f;
 
     // Cap the sum of errors to prevent excessive correction
     if (integralError < -windupGainGuard) {
@@ -51,7 +53,7 @@
     // Calculate the correction, based on the tuning values
     proportionalControl = proportionalGain * currentError;
     integralControl = integralError * integralGain;
-    derivativeControl = derivativeGain * (currentError - previousError) / dt;
+    derivativeControl = derivativeGain * (currentError - previousError) / dt * 1000.0f;
 
 
     // Save current error for next call to correction