Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PID by
Revision 12:9d078cd8ca83, committed 2014-10-15
- Comitter:
- oprospero
- Date:
- Wed Oct 15 04:59:05 2014 +0000
- Parent:
- 11:0854d9ff17f8
- Commit message:
- minor changes
Changed in this revision
| PID.cpp | Show annotated file Show diff for this revision Revisions of this file |
| PID.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/PID.cpp Mon Jun 09 00:07:12 2014 +0000
+++ b/PID.cpp Wed Oct 15 04:59:05 2014 +0000
@@ -20,7 +20,7 @@
proportionalGain(proportionalGain),
integralGain(integralGain),
derivativeGain(derivativeGain),
- windupGainGuard(windupGainGuard)
+ windupGainGuard(windupGainGuard/integralGain)
{
// pc.baud(38400);
integralError = 0.0f;
@@ -31,14 +31,6 @@
float PID::correct(const float currentError,const int dt)
{
-// float currentError = 0;
-// float proportionalControl, integralControl, derivativeControl;
-
- // 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.0f;
@@ -49,17 +41,22 @@
integralError = windupGainGuard;
}
-
// Calculate the correction, based on the tuning values
proportionalControl = proportionalGain * currentError;
integralControl = integralError * integralGain;
derivativeControl = derivativeGain * (currentError - previousError) / dt * 1000.0f;
-
// Save current error for next call to correction
previousError = currentError;
-
- return proportionalControl + integralControl + derivativeControl;
+
+ controlTotal = proportionalControl + integralControl + derivativeControl;
+
+ if (controlTotal > CONTROL_LIMIT)
+ return CONTROL_LIMIT;
+ else if (controlTotal < -CONTROL_LIMIT)
+ return -CONTROL_LIMIT;
+
+ return controlTotal;
}
@@ -71,4 +68,4 @@
void PID::updateD(const float dGain)
{
derivativeGain = dGain;
-}
\ No newline at end of file
+}
--- a/PID.h Mon Jun 09 00:07:12 2014 +0000
+++ b/PID.h Wed Oct 15 04:59:05 2014 +0000
@@ -3,6 +3,8 @@
#ifndef UWBQuad__PID__h
#define UWBQuad__PID__h
+#define CONTROL_LIMIT 250
+
/**
* UWB Quadcopter project
*
@@ -47,6 +49,7 @@
void updateP(const float);
void updateD(const float);
+ void setControlLimit(const float);
private:
float proportionalGain;
@@ -58,6 +61,9 @@
float currentError;
float previousError;
float integralError;
+
+ float controlTotal;
+
};
