PID control library forked from Aaron Berk. Make sure to read articles from www.controlguru.com to properly understand how to instantiate the PID loop.

Fork of PID by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
pHysiX
Date:
Mon May 12 13:15:56 2014 +0000
Parent:
1:ae1c6d19f4c6
Commit message:
Added in ability to set Proportional Gain only

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
diff -r ae1c6d19f4c6 -r b55a16b5f05c PID.cpp
--- a/PID.cpp	Sat May 03 02:55:01 2014 +0000
+++ b/PID.cpp	Mon May 12 13:15:56 2014 +0000
@@ -24,7 +24,7 @@
  * THE SOFTWARE.
  *
  * @section DESCRIPTION
- * 
+ *
  * A PID controller is a widely used feedback controller commonly found in
  * industry.
  *
@@ -49,7 +49,8 @@
  */
 #include "PID.h"
 
-PID::PID(float Kc, float tauI, float tauD, float interval) {
+PID::PID(float Kc, float tauI, float tauD, float interval)
+{
 
     usingFeedForward = false;
     inAuto           = false;
@@ -72,12 +73,13 @@
 
     accError_ = 0.0;
     bias_     = 0.0;
-    
+
     realOutput_ = 0.0;
 
 }
 
-void PID::setInputLimits(float inMin, float inMax) {
+void PID::setInputLimits(float inMin, float inMax)
+{
 
     //Make sure we haven't been given impossible values.
     if (inMin >= inMax) {
@@ -101,7 +103,8 @@
 
 }
 
-void PID::setOutputLimits(float outMin, float outMax) {
+void PID::setOutputLimits(float outMin, float outMax)
+{
 
     //Make sure we haven't been given impossible values.
     if (outMin >= outMax) {
@@ -124,7 +127,8 @@
 
 }
 
-void PID::setTunings(float Kc, float tauI, float tauD) {
+void PID::setTunings(float Kc, float tauI, float tauD)
+{
 
     //Verify that the tunings make sense.
     if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) {
@@ -159,7 +163,13 @@
 
 }
 
-void PID::reset(void) {
+void PID::setKP(float KP)
+{
+    Kc_ = KP;
+}
+
+void PID::reset(void)
+{
 
     float scaledBias = 0.0;
 
@@ -177,7 +187,8 @@
 
 }
 
-void PID::setMode(int mode) {
+void PID::setMode(int mode)
+{
 
     //We were in manual, and we just got set to auto.
     //Reset the controller internals.
@@ -189,7 +200,8 @@
 
 }
 
-void PID::setInterval(float interval) {
+void PID::setInterval(float interval)
+{
 
     if (interval > 0) {
         //Convert the time-based tunings to reflect this change.
@@ -201,26 +213,30 @@
 
 }
 
-void PID::setSetPoint(float sp) {
+void PID::setSetPoint(float sp)
+{
 
     setPoint_ = sp;
 
 }
 
-void PID::setProcessValue(float pv) {
+void PID::setProcessValue(float pv)
+{
 
     processVariable_ = pv;
 
 }
 
-void PID::setBias(float bias){
+void PID::setBias(float bias)
+{
 
     bias_ = bias;
     usingFeedForward = 1;
 
 }
 
-float PID::compute() {
+float PID::compute()
+{
 
     //Pull in the input and setpoint, and scale them into percent span.
     float scaledPV = (processVariable_ - inMin_) / inSpan_;
@@ -275,49 +291,57 @@
 
 }
 
-float PID::getInMin() {
+float PID::getInMin()
+{
 
     return inMin_;
 
 }
 
-float PID::getInMax() {
+float PID::getInMax()
+{
 
     return inMax_;
 
 }
 
-float PID::getOutMin() {
+float PID::getOutMin()
+{
 
     return outMin_;
 
 }
 
-float PID::getOutMax() {
+float PID::getOutMax()
+{
 
     return outMax_;
 
 }
 
-float PID::getInterval() {
+float PID::getInterval()
+{
 
     return tSample_;
 
 }
 
-float PID::getPParam() {
+float PID::getPParam()
+{
 
     return pParam_;
 
 }
 
-float PID::getIParam() {
+float PID::getIParam()
+{
 
     return iParam_;
 
 }
 
-float PID::getDParam() {
+float PID::getDParam()
+{
 
     return dParam_;
 
diff -r ae1c6d19f4c6 -r b55a16b5f05c PID.h
--- a/PID.h	Sat May 03 02:55:01 2014 +0000
+++ b/PID.h	Mon May 12 13:15:56 2014 +0000
@@ -103,6 +103,15 @@
      * @param tauD - Tuning parameter
      */
     void setTunings(float Kc, float tauI, float tauD);
+    
+    /**
+     * Set Proportional Gain
+     *
+     * Change Proportional Gain only
+     *
+     * @param Kc - Proportional gain
+     */
+     void setKP(float KP);
 
     /**
      * Reinitializes controller internals. Automatically