PID algorithm realization and parameter setting plot (with code)

Source: Internet
Author: User

First, the meaning of PID

PID is the abbreviation of the English word ratio (proportion), integral (Integral), differential (differential coefficient). PID regulation is actually composed of three kinds of adjustment methods, such as proportion, integral and differential, and their respective functions are as follows:

Proportional adjustment function: is proportional reaction system deviation, once the system has a deviation, the proportional adjustment immediately produces the adjustment function to reduce the deviation. The proportional action is large, can speed up the adjustment, reduces the error, but the excessive proportion, causes the system stability to descend, even causes the system instability.

Integral adjustment function: is to make the system eliminate the steady state error, improve the non-difference degree. Because there is error, the integral adjustment is carried out, until no difference, integral adjustment stop, integral adjustment output a constant value. The strength of integral action depends on the smaller the integral time constant Ti,ti, the stronger the integral function. On the other hand, TI is weak and integral adjustment can decrease the stability of the system and slow the dynamic response. The integral function is often combined with another two regulation rules to form PI regulator or PID regulator.

Differential regulation: The differential action reflects the change rate of the system deviation signal, has the foresight, can foresee the tendency of the deviation change, so it can produce the leading control function, which has been eliminated by the differential regulation before the deviation has not formed. Therefore, the dynamic performance of the system can be improved. In the case of differential time selection, the overshoot can be reduced and the adjustment time reduced. The differential action amplifies the noise disturbance, so the excessive differential regulation is disadvantageous to the system anti-interference. In addition, the differential reaction is the rate of change, and when the input does not change, the differential action output is zero. The differential action cannot be used alone, and it needs to be combined with two other regulating laws to form a PD or PID controller.

discrete-PID It is divided into position type and increment type.

Second, PID Position Calculation formula:

(Formula 1-1)

In the formula, U (n)-the control of the K sampling time, t--the sampling period.

Since the output U (k) of the computer directly controls the actuator (for example, the valve), the value of U (k) corresponds to the position of the actuator (e.g. valve opening) one by one, so the normally called (1-1) is a position-based PID control algorithm.

Third, PID Incremental Calculation formula:

The incremental formula can be deduced from (Equation 1-1):

The output value of the k-1 sampling moment (1-1) that can be obtained from the controller is:

(1-2)

by subtracting (1-1) from (1-2) and collating, we can get the Increment PID control algorithm formula:

(1-3 )

which

By (1-3) can be seen, if the computer control system using a constant sampling period t, once the determination of a, B, C, as long as the use of the deviation of three measurements before and after the value, it can be (1-3) to find out the control amount.

Compared with the position PID algorithm (1-1), the incremental PID control algorithm has much less computational capacity, so it is widely used in practice.

The position-based PID control algorithm can also be used to introduce the recursive formula by the incremental control algorithm:

(1-4 )

(1-4) is a digital recursive PID control algorithm which is widely used in computer control.

Type ( 1-3 ) is also:

Δu (k) =u (k)-U (k-1) = Kp*δe (k) + ki*e (k) + kd*[δe (k)-δe (k-1)], type Δe (k) =e (k)-E (k-1)

= Kp*[e (k)-E (k-1) + (T/ti) *e (k) + td* ((e (k) -2*e (k-1) +e (k-2))/T)] (formula 1-2)

= kp* (1+t/ti+td/t) *e (k)-kp* (1+2*td/t) *e (k-1) + kp*td/t*e (k-2)

= A*e (k)-b*e (k-1) + c*e (k-2) (type 1-3)

In the formula:

Δu (k)-The output increment of the controller (also called the regulator);

E (k)-the input of the controller (often the difference between the setpoint and the controlled amount, i.e. E (k) =r (k)-C (k));

Ki= (kp*t)/ti as integral factor

Kd= (KP*TD)/T for differential coefficients

In the formula:

T: The sampling period of the computer control system is not changed when it is selected. The selection principle is as small as possible within the response time requirement of the feedback signal of the controlled system. But too little will increase the amount of computation.

The proportional magnification factor of the kp--controller;

ti--the integration time of the controller;

td--the differential time of the controller.

Four, Pros and cons

A) incremental algorithm Advantages: ① formulas do not need to accumulate. The determination of control increment δu (k) is only related to the last 3 sampling values, and it is easy to obtain better control effect by weighted processing. ② computer output control increment at each time, that is, the change of the corresponding actuator position, so the impact of the machine failure is small, will not seriously affect the production process; ③ manual-Automatic switch with small impact. When control is switched from manual to Automatic, no disturbance can be switched.

b) The disadvantage of position-based PID control algorithm: the output of the current sampling time is related to the various states of the past, the calculation of E (k) to accumulate, the computation is large, and the controller output u (k) corresponds to the actual position of the actuator, if the computer fails, u (k) Significant changes in the location of the actuator.

Five, different from the contact:

1, in fact, the position and the increment is the same, the final output of the incremental solution and the position of the same type. Incremental PID can get position output via U (k) = U (k-1) +δu (k)

2, incremental algorithm and location-based algorithm comparison:

(1) Incremental algorithm does not need to do accumulate, calculate the error after the calculation of the accuracy of the problem, the calculation of the control amount of less impact. The position-based algorithm uses the accumulated error of the past, and it is easy to produce a large accumulative error.

(2) incremental algorithm is the increment of control, the effect of misoperation is small, if necessary, by logic to determine the limit or prohibit the output, will not affect the work of the system. The output of the position-based algorithm is the total output of the control quantity, and the influence of Misoperation is great.
(3) Yes, the main advantage of incremental algorithm is embodied in the processing of integral link , the cumulative effect of integral effect will affect the accuracy of the output.
(4) Upstairs, I have benefited a lot, has not understood the "avoid misoperation" reason. In addition, the incremental algorithm is easy to realize manual and automatic non-disturbance switching.

Six, incremental PID tuning summary 1. Negative feedback

The theory of automatic control is also called negative feedback control theory. First check the system wiring, determine the system feedback is negative feedback. For example, the motor speed control system, the input signal is positive, require the motor is rotating, the feedback signal is also positive (PID algorithm, error = input-feedback), while the higher the motor speed, the greater the feedback signal. The rest of the system is with this method.

2. General principles of PID debugging

A. Increase the proportional gain p when the output does not oscillate.
B. When the output does not oscillate, reduce the integration time constant TI.
C. When the output does not oscillate, increase the differential time constant TD.

3. General steps

A. first select the appropriate sampling period T, here first select 0.05S ... after the rest of the parameters are well-tuned, you can then modify the sample period T.

% t:0.05 kp:0.85 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

% t:0.1 kp:0.85 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

% t:0.2 kp:0.85 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/mi

% t:0.3 kp:0.85 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

% t:0.01 kp:0.85 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min
B. determining the proportional gain p

When the proportional gain p is determined, the integral term and the differential term of the PID are removed, and the PID is generally adjusted by the ti=0, td=0 (see the parameter setting of the PID). The input is set to the maximum allowable value of the system, and the proportional gain p is gradually increased by 0, until the system oscillates, and in turn, the proportional gain p from this time is gradually reduced until the system oscillation disappears, the proportional gain p is recorded at this time, and the proportional gain p of the PID is 60%~70% to the current value of 60%~70%. Proportional gain p debug complete.

t:0.05 kp:3 ti:0 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed is added to a 400r/min (experiment proves that speed is not 1)

t:0.05 kp:3 ti:0.3 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed to one gear 400r/min (at this point speed can reach 1, but overshoot too large)

t:0.05 kp:2 ti:0.3 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

% t:0.05 kp:1 ti:0.3 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

c. Determining the integration time constant TI

After the proportional gain p is determined, the initial value of a large integral time constant TI is set, then the TI is gradually reduced until the system oscillates, and then in turn, the TI is gradually enlarged until the system oscillation disappears. Recording Ti at this time, set the integration time constant of the PID ti is the 150%~180% of the current value. Integration time constant TI debugging completed.

% t:0.05 kp:1 ti:0.4 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

% t:0.05 kp:1 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

% t:0.05 kp:0.85 ti:0.45 td:0 Duty ratio initial value (motor start voltage corresponds to duty ratio): 1620 speed added to one gear 400r/min

d. determining the differential time constant TD

The integral time constant TD generally does not need to set, is 0 can. To set the same method as determining P and Ti, take 30% when not oscillating.

E. system no-load, with load-fed, and then to the PID The parameters are fine-tuned until the requirements are met.

PID algorithm realization and parameter setting plot (with code)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.