components/PID/PID_v1.c

changeset 82
7d17e2cb31a8
parent 1
ad2c8b13eb88
--- a/components/PID/PID_v1.c	Sun Jun 07 15:09:23 2020 +0200
+++ b/components/PID/PID_v1.c	Sun Jun 07 16:55:36 2020 +0200
@@ -22,7 +22,6 @@
 double		kd;			// (D)erivative Tuning Parameter
 
 int		controllerDirection;
-int		pOn;
 
 double		*myInput;		// Pointers to the Input, Output, and Setpoint variables
 double		*myOutput;		// This creates a hard link between the variables and the 
@@ -34,7 +33,7 @@
 
 unsigned long	SampleTime;
 double		outMin, outMax;
-bool		inAuto, pOnE;
+bool		inAuto;
 
 
 static const char *TAG = "pid";
@@ -43,7 +42,7 @@
 
 
 
-void PID(double* Input, double* Output, double* Setpoint, double Kp, double Ki, double Kd, PID_PON POn, PID_DIRECTION Direction) {
+void PID(double* Input, double* Output, double* Setpoint, double Kp, double Ki, double Kd, PID_DIRECTION Direction) {
     myOutput = Output;
     myInput = Input;
     mySetpoint = Setpoint;
@@ -54,7 +53,7 @@
     SampleTime = 100;
 
     PID_SetControllerDirection(Direction);
-    PID_SetTunings(Kp, Ki, Kd, POn);
+    PID_SetTunings(Kp, Ki, Kd);
 
     lastTime = (xTaskGetTickCount() * portTICK_PERIOD_MS ) - SampleTime;
 }
@@ -80,22 +79,14 @@
 	double error = *mySetpoint - input;
 	double dInput = (input - lastInput);
 	outputSum+= (ki * error);
-
-	/*Add Proportional on Measurement, if P_ON_M is specified*/
-	if (!pOnE) 
-	    outputSum-= kp * dInput;
+	outputSum-= kp * dInput;
 
 	if (outputSum > outMax)
 	    outputSum= outMax;
 	else if (outputSum < outMin)
 	    outputSum= outMin;
 	
-	/*Add Proportional on Error, if P_ON_E is specified*/
-	double output;
-	if (pOnE)
-	    output = kp * error;
-	else
-	    output = 0;
+	double output = 0;
 
 	/*Compute Rest of PID Output*/
 	output += outputSum - kd * dInput;
@@ -121,19 +112,16 @@
  * it's called automatically from the constructor, but tunings can also
  * be adjusted on the fly during normal operation
  */
-void PID_SetTunings(double Kp, double Ki, double Kd, PID_PON POn)
+void PID_SetTunings(double Kp, double Ki, double Kd)
 {
     if (Kp<0 || Ki<0 || Kd<0) {
 	ESP_LOGE(TAG, "SetTunings negative input");
 	return;
     }
 
-    pOn = POn;
-    pOnE = POn == PID_P_ON_E;
-
     dispKp = Kp; dispKi = Ki; dispKd = Kd;
 
-    ESP_LOGI(TAG, "SetTunings(%.3f, %.3f, %.3f, %s)", Kp, Ki, Kd, (POn) ? "P_ON_E":"P_ON_M"); 
+    ESP_LOGI(TAG, "SetTunings(%.3f, %.3f, %.3f)", Kp, Ki, Kd); 
     double SampleTimeInSec = ((double)SampleTime)/1000;
     kp = Kp;
     ki = Ki * SampleTimeInSec;

mercurial