The PID workig mode is fixed

Sun, 07 Jun 2020 16:55:36 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 07 Jun 2020 16:55:36 +0200
changeset 82
7d17e2cb31a8
parent 81
72c715ac0444
child 83
0cc064a4921b

The PID workig mode is fixed

components/PID/PID_v1.c file | annotate | diff | comparison | revisions
components/PID/PID_v1.h file | annotate | diff | comparison | revisions
main/automation.c file | annotate | diff | comparison | revisions
main/config.c file | annotate | diff | comparison | revisions
main/config.h file | annotate | diff | comparison | revisions
main/setup.c file | annotate | diff | comparison | revisions
main/task_driver.c file | annotate | diff | comparison | revisions
--- 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;
--- a/components/PID/PID_v1.h	Sun Jun 07 15:09:23 2020 +0200
+++ b/components/PID/PID_v1.h	Sun Jun 07 16:55:36 2020 +0200
@@ -27,17 +27,6 @@
 } PID_DIRECTION;
 
 /**
- * @brief PID calculation mode.
- */
-typedef enum
-{
-    PID_P_ON_M = 0,		///< PID on Measurement.
-    PID_P_ON_E = 1,		///< PID on Errors.
-} PID_PON;
-
-
-
-/**
  * @brief Setup the PID controller and initialize.
  * @param[in] Input The measured value.
  * @param[in,out] Output The computed result.
@@ -45,10 +34,9 @@
  * @param[in] Kp The Proportional value.
  * @param[in] Ki The Intergral value.
  * @param[in] Kd The Derivate value.
- * @param[in] POn 0 - PID on Measurement, 1 - PID on Error.
  * @param[in] Direction Direct or Reverse action.
  */
-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);
 
 /**
  * @brief sets PID to either Manual or Automatic.
@@ -78,9 +66,8 @@
  * @param[in] Kp The Proportional value.
  * @param[in] Ki The Intergral value.
  * @param[in] Kd The Derivate value.
- * @param[in] POn 0 - PID on Measurement, 1 - PID on Error.
  */
-void PID_SetTunings(double Kp, double Ki, double Kd, PID_PON POn);
+void PID_SetTunings(double Kp, double Ki, double Kd);
 
 /**
  * @brief The PID will either be connected to a DIRECT acting process (+Output leads
--- a/main/automation.c	Sun Jun 07 15:09:23 2020 +0200
+++ b/main/automation.c	Sun Jun 07 16:55:36 2020 +0200
@@ -30,7 +30,7 @@
 uint16_t                        TimeWhirlPool = 0;		///< Whirlpool timer
 uint32_t                        TimeLeft = 0;			///< Time left in this stage
 uint32_t			oldTimeLeft = 0;		///< The previous time left
-uint32_t                        TimeSpent = 0;			///< Tota time spent
+uint32_t                        TimeSpent = 0;			///< Total time spent
 uint32_t                        SecsCount = 0;			///< Seconds counter
 uint32_t                        pumpTime = 0;			///< Pump running time
 uint32_t                        TimeBrewing = 0;		///< Brewing time elapsed
--- a/main/config.c	Sun Jun 07 15:09:23 2020 +0200
+++ b/main/config.c	Sun Jun 07 16:55:36 2020 +0200
@@ -115,11 +115,10 @@
 	equipment.PIDPipe = true;
 	equipment.SSR2 = 0;
 	equipment.TempHLT = 85.0;
-	equipment.PID_kP = 150.0;
-	equipment.PID_kI = 1.5;
-	equipment.PID_kD = 15000.0;
-	equipment.PID_POn = PID_P_ON_E;
-	equipment.SampleTime = 5000;
+	equipment.PID_kP = 200.0;
+	equipment.PID_kI = 2.0;
+	equipment.PID_kD = 1.5;
+	equipment.SampleTime = 3000;
 	append_equipment();
     } else {
 	dst = (uint8_t*)&equipment;
--- a/main/config.h	Sun Jun 07 15:09:23 2020 +0200
+++ b/main/config.h	Sun Jun 07 16:55:36 2020 +0200
@@ -215,7 +215,7 @@
     double	PID_kP;				///< PID P setting.
     double	PID_kI;				///< PID I setting.
     double	PID_kD;				///< PID D setting.
-    bool	PID_POn;			///< PID compute on Measurement or Errors.
+    bool	xPID_POn;
     int		SampleTime;			///< PID sample time in seconds.
 } equipment;					///< Equipment record.
 
--- a/main/setup.c	Sun Jun 07 15:09:23 2020 +0200
+++ b/main/setup.c	Sun Jun 07 16:55:36 2020 +0200
@@ -188,9 +188,8 @@
 			    ShowSSR2(2, 124, equipment.SSR2);
 			    ShowFloat(161, 124, (char *)"Spoelwater", NULL, equipment.TempHLT, 2);
 			    ShowDouble(2, 140, (char *)"PID P", NULL, equipment.PID_kP, 3);
-			    ShowBool(161, 140, (char *)"PID klassiek", equipment.PID_POn);
+			    ShowInteger(161, 140, (char *)"Sample tijd", (char *)"mS", equipment.SampleTime);
 			    ShowDouble(2, 156, (char *)"PID I", NULL, equipment.PID_kI, 3);
-			    ShowInteger(161, 156, (char *)"Sample tijd", (char *)"mS", equipment.SampleTime);
 			    ShowDouble(2, 172, (char *)"PID D", NULL, equipment.PID_kD, 3);
 			    Buttons_Clear();
 			    Buttons_Add(  0, 210, 45, 30, (char *)"Ok"  , 0);
@@ -235,11 +234,10 @@
 					equipment.PIDPipe = true;
 					equipment.SSR2 = 0;
 					equipment.TempHLT = 85.0;
-					equipment.PID_kP = 150.0;
-					equipment.PID_kI = 1.5;
-					equipment.PID_kD = 15000.0;
-					equipment.PID_POn = PID_P_ON_E;
-					equipment.SampleTime = 5000;
+					equipment.PID_kP = 200.0;
+					equipment.PID_kI = 2.0;
+					equipment.PID_kD = 1.5;
+					equipment.SampleTime = 3000;
 					append_equipment();
 					Records++;
 					CurrentRec = Records;
@@ -301,7 +299,6 @@
 			EditFloat((char *)"Spoelwater temp", &equipment.TempHLT, 75, 98, 2);
 			// Round to 0.25 values.
 			equipment.TempHLT = ((int)(equipment.TempHLT * 4)) / 4.0;
-			EditBool((char *)"PID klassiek", &equipment.PID_POn);
 			EditDouble((char *)"PID P",  &equipment.PID_kP, 20, 2000, 3);
 			EditDouble((char *)"PID I",  &equipment.PID_kI, 0, 100, 3);
 			EditDouble((char *)"PID D",  &equipment.PID_kD, 0, 50000, 3);
--- a/main/task_driver.c	Sun Jun 07 15:09:23 2020 +0200
+++ b/main/task_driver.c	Sun Jun 07 16:55:36 2020 +0200
@@ -102,7 +102,7 @@
  * @brief Load PID settings from equipment record.
  */
 void LoadPIDsettings() {
-    PID_SetTunings(equipment.PID_kP, equipment.PID_kI, equipment.PID_kD, equipment.PID_POn);
+    PID_SetTunings(equipment.PID_kP, equipment.PID_kI, equipment.PID_kD);
     PID_SetSampleTime(equipment.SampleTime);
 
     /*
@@ -150,7 +150,7 @@
     driver_state->pump_gpio = SSR_PUMP;
     driver_state->pump_run = 0;
 
-    PID(&Input, &Output, &Setpoint, 150, 1.5, 15000, PID_P_ON_E, PID_DIRECT);
+    PID(&Input, &Output, &Setpoint, 150, 1.5, 15000, PID_DIRECT);
     
     /*
      * One loop must complete in 20 mSecs, that is one mains

mercurial