change float to double

Fork of PID by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Wed Nov 23 07:13:07 2016 +0000
Parent:
0:6e12a3e5af19
Commit message:
Change float to double

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 6e12a3e5af19 -r ca4077d72c94 PID.cpp
--- a/PID.cpp	Thu Sep 02 16:48:10 2010 +0000
+++ b/PID.cpp	Wed Nov 23 07:13:07 2016 +0000
@@ -44,12 +44,14 @@
  *  http://www.controlguru.com/
  */
 
+// Modified by K.Arai/JH1PJL on June 15th, 2016
+
 /**
  * Includes
  */
 #include "PID.h"
 
-PID::PID(float Kc, float tauI, float tauD, float interval) {
+PID::PID(double Kc, double tauI, double tauD, double interval) {
 
     usingFeedForward = false;
     inAuto           = false;
@@ -77,7 +79,7 @@
 
 }
 
-void PID::setInputLimits(float inMin, float inMax) {
+void PID::setInputLimits(double inMin, double inMax) {
 
     //Make sure we haven't been given impossible values.
     if (inMin >= inMax) {
@@ -101,7 +103,7 @@
 
 }
 
-void PID::setOutputLimits(float outMin, float outMax) {
+void PID::setOutputLimits(double outMin, double outMax) {
 
     //Make sure we haven't been given impossible values.
     if (outMin >= outMax) {
@@ -124,7 +126,7 @@
 
 }
 
-void PID::setTunings(float Kc, float tauI, float tauD) {
+void PID::setTunings(double Kc, double tauI, double tauD) {
 
     //Verify that the tunings make sense.
     if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) {
@@ -136,7 +138,7 @@
     iParam_ = tauI;
     dParam_ = tauD;
 
-    float tempTauR;
+    double tempTauR;
 
     if (tauI == 0.0) {
         tempTauR = 0.0;
@@ -161,7 +163,7 @@
 
 void PID::reset(void) {
 
-    float scaledBias = 0.0;
+    double scaledBias = 0.0;
 
     if (usingFeedForward) {
         scaledBias = (bias_ - outMin_) / outSpan_;
@@ -189,7 +191,7 @@
 
 }
 
-void PID::setInterval(float interval) {
+void PID::setInterval(double interval) {
 
     if (interval > 0) {
         //Convert the time-based tunings to reflect this change.
@@ -201,29 +203,29 @@
 
 }
 
-void PID::setSetPoint(float sp) {
+void PID::setSetPoint(double sp) {
 
     setPoint_ = sp;
 
 }
 
-void PID::setProcessValue(float pv) {
+void PID::setProcessValue(double pv) {
 
     processVariable_ = pv;
 
 }
 
-void PID::setBias(float bias){
+void PID::setBias(double bias){
 
     bias_ = bias;
     usingFeedForward = 1;
 
 }
 
-float PID::compute() {
+double PID::compute() {
 
     //Pull in the input and setpoint, and scale them into percent span.
-    float scaledPV = (processVariable_ - inMin_) / inSpan_;
+    double scaledPV = (processVariable_ - inMin_) / inSpan_;
 
     if (scaledPV > 1.0) {
         scaledPV = 1.0;
@@ -231,14 +233,14 @@
         scaledPV = 0.0;
     }
 
-    float scaledSP = (setPoint_ - inMin_) / inSpan_;
+    double scaledSP = (setPoint_ - inMin_) / inSpan_;
     if (scaledSP > 1.0) {
         scaledSP = 1;
     } else if (scaledSP < 0.0) {
         scaledSP = 0;
     }
 
-    float error = scaledSP - scaledPV;
+    double error = scaledSP - scaledPV;
 
     //Check and see if the output is pegged at a limit and only
     //integrate if it is not. This is to prevent reset-windup.
@@ -247,9 +249,9 @@
     }
 
     //Compute the current slope of the input signal.
-    float dMeas = (scaledPV - prevProcessVariable_) / tSample_;
+    double dMeas = (scaledPV - prevProcessVariable_) / tSample_;
 
-    float scaledBias = 0.0;
+    double scaledBias = 0.0;
 
     if (usingFeedForward) {
         scaledBias = (bias_ - outMin_) / outSpan_;
@@ -275,49 +277,49 @@
 
 }
 
-float PID::getInMin() {
+double PID::getInMin() {
 
     return inMin_;
 
 }
 
-float PID::getInMax() {
+double PID::getInMax() {
 
     return inMax_;
 
 }
 
-float PID::getOutMin() {
+double PID::getOutMin() {
 
     return outMin_;
 
 }
 
-float PID::getOutMax() {
+double PID::getOutMax() {
 
     return outMax_;
 
 }
 
-float PID::getInterval() {
+double PID::getInterval() {
 
     return tSample_;
 
 }
 
-float PID::getPParam() {
+double PID::getPParam() {
 
     return pParam_;
 
 }
 
-float PID::getIParam() {
+double PID::getIParam() {
 
     return iParam_;
 
 }
 
-float PID::getDParam() {
+double PID::getDParam() {
 
     return dParam_;
 
diff -r 6e12a3e5af19 -r ca4077d72c94 PID.h
--- a/PID.h	Thu Sep 02 16:48:10 2010 +0000
+++ b/PID.h	Wed Nov 23 07:13:07 2016 +0000
@@ -44,6 +44,8 @@
  *  http://www.controlguru.com/
  */
 
+// Modified by K.Arai/JH1PJL on June 15th, 2016
+
 #ifndef PID_H
 #define PID_H
 
@@ -76,7 +78,7 @@
      * @param tauD - Tuning parameter
      * @param interval PID calculation performed every interval seconds.
      */
-    PID(float Kc, float tauI, float tauD, float interval);
+    PID(double Kc, double tauI, double tauD, double interval);
 
     /**
      * Scale from inputs to 0-100%.
@@ -84,7 +86,7 @@
      * @param InMin The real world value corresponding to 0%.
      * @param InMax The real world value corresponding to 100%.
      */
-    void setInputLimits(float inMin , float inMax);
+    void setInputLimits(double inMin , double inMax);
 
     /**
      * Scale from outputs to 0-100%.
@@ -92,7 +94,7 @@
      * @param outMin The real world value corresponding to 0%.
      * @param outMax The real world value corresponding to 100%.
      */
-    void setOutputLimits(float outMin, float outMax);
+    void setOutputLimits(double outMin, double outMax);
 
     /**
      * Calculate PID constants.
@@ -103,7 +105,7 @@
      * @param tauI - Tuning parameter
      * @param tauD - Tuning parameter
      */
-    void setTunings(float Kc, float tauI, float tauD);
+    void setTunings(double Kc, double tauI, double tauD);
 
     /**
      * Reinitializes controller internals. Automatically
@@ -124,45 +126,45 @@
      *
      * @param interval PID calculation peformed every interval seconds.
      */
-    void setInterval(float interval);
+    void setInterval(double interval);
     
     /**
      * Set the set point.
      *
      * @param sp The set point as a real world value.
      */
-    void setSetPoint(float sp);
+    void setSetPoint(double sp);
     
     /**
      * Set the process value.
      *
      * @param pv The process value as a real world value.
      */
-    void setProcessValue(float pv);
+    void setProcessValue(double pv);
     
     /**
      * Set the bias.
      *
      * @param bias The bias for the controller output.
      */
-    void setBias(float bias);
+    void setBias(double bias);
 
     /**
      * PID calculation.
      *
-     * @return The controller output as a float between outMin and outMax.
+     * @return The controller output as a double between outMin and outMax.
      */
-    float compute(void);
+    double compute(void);
 
     //Getters.
-    float getInMin();
-    float getInMax();
-    float getOutMin();
-    float getOutMax();
-    float getInterval();
-    float getPParam();
-    float getIParam();
-    float getDParam();
+    double getInMin();
+    double getInMax();
+    double getOutMin();
+    double getOutMax();
+    double getInterval();
+    double getPParam();
+    double getIParam();
+    double getDParam();
 
 private:
 
@@ -170,43 +172,43 @@
     bool inAuto;
 
     //Actual tuning parameters used in PID calculation.
-    float Kc_;
-    float tauR_;
-    float tauD_;
+    double Kc_;
+    double tauR_;
+    double tauD_;
     
     //Raw tuning parameters.
-    float pParam_;
-    float iParam_;
-    float dParam_;
+    double pParam_;
+    double iParam_;
+    double dParam_;
     
     //The point we want to reach.
-    float setPoint_;         
+    double setPoint_;         
     //The thing we measure.
-    float processVariable_;  
-    float prevProcessVariable_;
+    double processVariable_;  
+    double prevProcessVariable_;
     //The output that affects the process variable.
-    float controllerOutput_; 
-    float prevControllerOutput_;
+    double controllerOutput_; 
+    double prevControllerOutput_;
 
     //We work in % for calculations so these will scale from
     //real world values to 0-100% and back again.
-    float inMin_;
-    float inMax_;
-    float inSpan_;
-    float outMin_;
-    float outMax_;
-    float outSpan_;
+    double inMin_;
+    double inMax_;
+    double inSpan_;
+    double outMin_;
+    double outMax_;
+    double outSpan_;
 
     //The accumulated error, i.e. integral.
-    float accError_;
+    double accError_;
     //The controller output bias.
-    float bias_;
+    double bias_;
 
     //The interval between samples.
-    float tSample_;          
+    double tSample_;          
 
     //Controller output as a real world value.
-    volatile float realOutput_;
+    volatile double realOutput_;
 
 };