we have designed the PID controller and made many improvements according to the actual use. In this article, we will discuss how to improve the overshoot of PID controller.
1. Question raised
in the previous article, we have derived the formula of incremental PID controller and discretized it for program implementation. The specific discretization formula is as follows:
based on this formula, the incremental PID controller we realize can realize automatic adjustment only by calculating the increment according to the deviation and adjusting the output. However, we will find that if the parameter setting is inappropriate or the deviation value is relatively large, the calculated increment value will be very large, so the output will change greatly. In this case, overshoot is easy to occur.
Once overshoot occurs, it may take a long time to stabilize the system, and even cause oscillation. Naturally, this is not the result we want, so we hope that the PID controller has the ability to prevent overshoot.
2. Analysis and design
with regard to overshoot, let's first analyze what factors can cause overshoot. The so-called overshoot can be understood as excessive adjustment, which leads to the instability of the system. What on earth will cause excessive adjustment? Generally speaking, too frequent regulation, sudden and large changes of input signal, abrupt changes of output signal and the characteristics of the controlled object.
for the above situation, let's analyze the countermeasures one by one. The first is too frequent regulation. Many times, we may think that fast regulation can speed up the response of the system. But in fact, it is related to the characteristics of the system itself. If the system has no lag or the lag characteristic is very small, there is naturally no problem. But in many cases, the system will have a relatively large lag, so too frequent regulation will quickly accumulate output control, resulting in overshoot. In this case, we can increase the regulation period to stabilize the system.
secondly, let's look at the impact of sudden large changes in the input signal. The input signal we mentioned here refers to the set value of PID controller. In a stable system, a large change in the set value will sharply increase the deviation, and a large deviation will often cause the output of the controller to accumulate rapidly, which will often cause overshoot. In this case, we can control the change speed of the set value to improve. Generally, the set value changes linearly and slowly, and the step value can be adjusted according to the characteristics of the system.
let's take a look at the impact of steep changes in the output signal. Sometimes, even if the deviation changes little, the output will change greatly because of the matching problem between the parameter setting and the system. At this time, the control variable will change greatly, which will increase the deviation and further affect the output, so the cyclic accumulation may produce overshoot. In particular, some systems that react faster are more prone to this situation. Generally, we can prevent this phenomenon by limiting the change of output.
the characteristics of the controlled object are mainly reflected in the lagging characteristics of the system. Generally speaking, the more lagging the system is, the more difficult it is to adjust and stabilize, and the more prone it is to overshoot or even oscillation. In response to this situation, the way of mitigation and adjustment can also be adopted. The specific methods are also the first three.
3. Software implementation
we have analyzed the main causes of overshoot and the countermeasures. Next, we will consider how to improve the PID controller to achieve the effect of preventing overshoot. In view of the above-mentioned situations, we will design the software implementation methods respectively.
for the problem of relatively frequent adjustment, our PID controller has been designed considering that the sampling period is adjustable, so we only need to adjust it appropriately according to different controlled objects. For the two cases of sharp change of set value and steep change of regulated output, we introduce two parameters, one for the smoothing function when switching the set value, and the other for setting the switch of output incremental limiting function. We use two enumerations to realize this function. The specific definitions are as follows:
/*Define setpoint smooth enumeration type*/ typedef enum ClassicPIDSM{ SMOOTH_DISABLE, //Do not enable setpoint smoothing SMOOTH_ENABLE //Enable setpoint smoothing }ClassicPIDSMType; /*Define enumerations that prevent abrupt changes in output*/ typedef enum ClassicPIDPAC{ PREVENT_ABRUPT_DISABLE, //Do not enable output anti abrupt change PREVENT_ABRUPT_ENABLE //Enable output anti abrupt change }ClassicPIDPACType;
similarly, we need to add corresponding attributes in the PID object type. We add the set value smoothing parameter and output incremental limiting parameter to the PID controller object type, so we define the object type of the PID controller as follows:
/*Define PID object type*/ typedef struct CLASSIC { float *pPV; //Measured value pointer float *pSV; //Setpoint pointer float *pMV; //Output value pointer uint16_t *pMA; //Manual automatic operation pointer #if PID_PARAMETER_STYLE > (0) float *pKp; //Scale factor pointer float *pKi; //Integral coefficient pointer float *pKd; //Differential coefficient pointer #else float *pPb; //Proportional band float *pTi; //Integration time, in seconds float *pTd; //Differential time, in seconds float ts; //Sampling period, in seconds #endif float setpoint; //Set value float lasterror; //Previous beat deviation float preerror; //Deviation of the first two beats float deadband; //dead zone float result; //PID controller calculation results float output; //Output value 0-100% float maximum; //Upper limit of output value float minimum; //Lower limit of output value float errorabsmax; //Maximum absolute value of deviation float errorabsmin; //Minimum absolute value of deviation float alpha; //Incomplete differential coefficient float deltadiff; //Differential increment float integralValue; //Integral cumulation float gama; //Differential advance filter coefficient float lastPv; //Process measurement value of the last shot float lastDeltaPv; //Increment of process measurement value of the last shot ClassicPIDDRType direct; //positive reaction ClassicPIDSMType sm; //Set value smoothing ClassicPIDCSType cas; //Cascade setting ClassicPIDPACType pac; //Output anti abrupt change }CLASSICPID;
the definition of PID controller object is modified, and we also need to make necessary improvements to PID controller. We add a set value smoothing operation and control whether the operation is enabled by setting the parameter sm. We add the operation of output anti abrupt change, and decide whether to enable it by configuring the parameter pac. The specific implementation is as follows:
void PIDRegulator(CLASSICPID *vPID) { float thisError; float result; float factor; float increment; float pError,dError,iError; float kp,ki,kd; #if PID_PARAMETER_STYLE > (0) kp=*vPID->pKp; ki=*vPID->pKi; kd=*vPID->pKd; #else if((*vPID->pTi)<vPID->ts) { *vPID->pTi=vPID->ts; } kp=100.0/(*vPID->pPb); ki=kp*(vPID->ts/(*vPID->pTi)); kd=kp*((*vPID->pTd)/vPID->ts); #endif if(*vPID->pMA<1) //Manual mode { vPID->output=*vPID->pMV; //Set undisturbed switching vPID->result=(vPID->maximum-vPID->minimum)*vPID->output/(float)100.0+vPID->minimum; *vPID->pSV=*vPID->pPV; vPID->setpoint=*vPID->pSV; } else //Automatic mode { if(vPID->sm==SMOOTH_ENABLE) //Set value changes smoothly { SmoothSetpoint(vPID); } else { if(vPID->cas==CASCADE) //Cascade processing { vPID->setpoint=(vPID->maximum-vPID->minimum)*(*vPID->pSV)/(float)100.0+vPID->minimum; } else { vPID->setpoint=*vPID->pSV; } } thisError=vPID->setpoint-(*vPID->pPV); //Get the deviation value result=vPID->result; if (fabsf(thisError)>vPID->deadband) { pError=thisError-vPID->lasterror; iError=(thisError+vPID->lasterror)/(float)2.0; dError=thisError-2*(vPID->lasterror)+vPID->preerror; //Variable integral coefficient acquisition factor=VariableIntegralCoefficient(thisError,vPID->errorabsmax,vPID->errorabsmin); //Calculate the increment of differential term with incomplete differential vPID->deltadiff=kd*(1-vPID->alpha)*dError+vPID->alpha*vPID->deltadiff; increment=kp*pError+ki*factor*iError+vPID->deltadiff; //Incremental calculation } else { if((fabsf(vPID->setpoint-vPID->minimum)<vPID->deadband)&&(fabsf((*vPID->pPV)-vPID->minimum)<vPID->deadband)) { result=vPID->minimum; } increment=0.0; } //Output variation amplitude if(vPID->pac==PREVENT_ABRUPT_ENABLE) { increment=fabsf(increment)>fabsf(thisError)?thisError:increment; } //Positive and negative reaction setting if(vPID->direct==DIRECT) { result=result+increment; } else { result=result-increment; } /*For the output limit, the problem of overshooting and integral saturation is avoided*/ if(result>=vPID->maximum) { result=vPID->maximum; } if(result<=vPID->minimum) { result=vPID->minimum; } vPID->preerror=vPID->lasterror; //Store deviation for next operation vPID->lasterror=thisError; vPID->result=result; vPID->output=(vPID->result-vPID->minimum)/(vPID->maximum-vPID->minimum)*(float)100.0; *vPID->pMV=vPID->output; } }
here we fix the smooth step value of the set value according to the scale of the range, but in fact, the smooth step value of the set value should be adjusted according to the sampling period. And appropriate adjustments should also be made in different controlled systems. For the threshold of output anti abrupt change, we adopt the deviation value.
4. Summary
in this article, we analyze several reasons for overshoot and think about their respective coping strategies. Based on these, we have improved the PID controller to have the basic function of anti overshoot. We have actually used the improved PID controller in temperature control and flow control, and the inhibition effect on overshoot is very obvious. However, it should be pointed out that if the smooth step value of the set value is set too small or the threshold of the output incremental limiting is too small, the adjustment process will be extremely slow.
generally speaking, systems with relatively large hysteresis such as temperature and level will have a better effect by using the set value smoothing, while increasing the output increment limit may adjust slowly. For systems with relatively small hysteresis such as flow and pressure, using output incremental limiting will have a better effect, while increasing the set value may make the adjustment slow.
finally, let's briefly talk about the problem of adjusting the cycle. The choice of adjustment cycle is a problem that needs to be seriously considered. Even if we adopt the same parameter setting and the same anti overshoot treatment, the effect may be greatly different when the adjustment cycle is different, so the adjustment cycle must be determined well. Generally speaking, the regulation cycle of the system with large lag needs to be set a little longer, while the regulation cycle of the system with small lag needs to be set a little shorter, and the specific setting needs to be based on the control requirements.