Teach you to read and understand the Arduino PID control library hand by hand - parameter adjustment

Introduction

This article will analyze the third question in " Teach you to understand and understand the Arduino PID control library ": the impact of sudden changes in PID control parameters on the system.

problem definition

In the actual application process of PID control, there may be situations in which the PID tuning parameters Kp, Ki, and Kd need to be changed suddenly. What will be the impact if the tuning parameters are suddenly changed? First look at a picture:

If a large change is made to the tuning parameters during the operation of the system, there will be a sudden change in Output, which is a bit like a "pit". The following figure gives a quantitative analysis of the effect of changing PID parameters on the output:

The above phenomenon describes the change caused by the sudden change of the PID parameters after the system enters the steady state. The main factor that causes the output to change greatly is the I parameter. Since the multiplication factor E of the P parameter in the steady state does not change much, the D parameter also does not change. Large, but the multiplication factor of the I parameter is the integral over time (it is conceivable that if the controlled variable is far away from the set value at the beginning, and the integral represents the area sum with direction, so there must be a direction that will be larger area, see the figure below), therefore, will cause a larger change.

solution

Let's look at a set of formulas first, and then thank the great mathematicians.

The first equation is fine when KI is constant, and needs to be evaluated when it is not. Although not fully true, it is acceptable if E is very small in steady state. This does not seem to be the same as the classic PID equation. From another angle, the classic PID control I term is only determined to eliminate the static error. If under this premise, it is also possible to eliminate the static error in another way, just sacrificing the "strength".

code

/*working variables*/
unsigned long lastTime;
double Input, Output, Setpoint;
double ITerm, lastInput;
double kp, ki, kd;
int SampleTime = 1000; //1 sec
void Compute()
{
   unsigned long now = millis();
   int timeChange = (now - lastTime);
   if(timeChange>=SampleTime)
   {
      /*Compute all the working error variables*/
      double error = Setpoint - Input;
      ITerm += (ki * error);
      double dInput = (Input - lastInput);
 
      /*Compute PID Output*/
      Output = kp * error + ITerm - kd * dInput;
 
      /*Remember some variables for next time*/
      lastInput = Input;
      lastTime = now;
   }
}
 
void SetTunings(double Kp, double Ki, double Kd)
{
  double SampleTimeInSec = ((double)SampleTime)/1000;
   kp = Kp;
   ki = Ki * SampleTimeInSec;
   kd = Kd / SampleTimeInSec;
}
 
void SetSampleTime(int NewSampleTime)
{
   if (NewSampleTime > 0)
   {
      double ratio  = (double)NewSampleTime
                      / (double)SampleTime;
      ki *= ratio;
      kd /= ratio;
      SampleTime = (unsigned long)NewSampleTime;
   }
}

The variable Iterm is used to complete the above algorithm.

result

icon

Quantitative results

As can be seen from the graph, despite the large change in the PID parameters, the output still becomes continuous. In the above process, the "sensitivity" of the response of the system is sacrificed to increase the stability of the control. The sensitivity of the system can often be improved by increasing the calculation frequency, and greatly increasing the sampling frequency can play a role in updating the integral term faster.

At present, this method has better control effect in temperature control.

NOTE: Please let us know if there are any inadequacies. ^.^

The next chapter will introduce the effect on the system if the set value is changed suddenly during the operation of the system.

NEXT

PS: Please indicate the source for reprinting: Ouyang Tianhua

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325474595&siteId=291194637