Miscellaneous PID control algorithms-Article 1: Three Quantities

Source: Internet
Author: User

After training for more than half a summer vacation, people gradually started to get tired. In this case, take a good rest.

You can't just take a rest. Just take the opportunity to sort out the things you have written.

From the first training, we came into contact with a new term, PID control theory. It was quite early to come into contact with this theory. He mentioned this algorithm to me one night when I was talking to a senior. One application he told me at the beginning was to use the pid to keep the speed of the two wheels as close as possible to the same. At that time, I felt very tangled. The speed control was slow on the left side and accelerated on the left side. But when the first question (constant temperature water bottle) is made, it is found that if the traditional method is used for control (that is, if the temperature is high, it is not heated, and the temperature is low, it is heated ), the improvement speed of the control and the over-tuning range of the control value cannot achieve both results (this is one of the reasons why the results we finally made are not very good, because Baidu's pid algorithm on the internet is fake .). Theoretically (PID has not been successfully debugged till now), using the PID algorithm can make the controlled values take into account both efficiency and accuracy.

In the PID theory, there are three quantities. Kp, Ki, Kd.

Let's talk about Kp. K is a constant, and p represents a ratio (proportion). Kp can be said to be an indispensable quantity in the PID algorithm. It cannot be implemented without its control. It is used to obtain the control value based on the difference between the current amount and the set amount. For example, for a temperature control system, we can naturally think that when the temperature is closer to our set value, the more we want to slow down the heating rate. kp is playing such a role. For example, if the kp is set to 10, the constant temperature is set to 60 degrees, and the current temperature is 49 degrees, then the control value I output (using the duty cycle to achieve rapid temperature control) it is 10 * (60-49) = 110; if the current temperature is 20 degrees, my output is 10 * (60-20) = 400, but because 400 is too big, it is bigger than the maximum control value 0xff (255), and I will directly 255. If the current temperature is 61 degrees, the output is 10 * (60-61) =-10 <0, and the output is 0. That is, do not heat it so that it naturally cools down. The formula UKp = Kp * (Uset-Unow) is used to calculate the output control value through the Kp parameter. Uset indicates the set temperature, and Unow indicates the current temperature.

The next step is the Ki volume. I represents integration and points. It's boring to say it's empty. It's still a temperature control system to raise the temperature to 59 degrees (set the temperature to 60 degrees) at this time, the control value I obtained through the Kp above is 10, but the ambient temperature is very low. The energy provided by your 10 control is just enough to offset the heat from the loss to the air. At this time, the temperature is constant at 59 degrees. Of course, this is different from the value we set at 60 degrees. At this time, KI will start to take effect. The basic formula of KI is to multiply the integral value from 0 to the current time point (Uset-Unow) by Ki, but in the single chip microcomputer (also in the computer) there is only a number, so the score is multiplied, and the formula is UKi = UKi + KI * (Uset-Unow) * dt. dt is the sampling period of the system, that is, the Unow is sampled once every dt. This value is relatively small, and most of them are not integers. As we all know, the floating point operation in 51 is slow, so I generally change the formula to UKi = UKi + KI * (Uset-Unow) /F, F is the frequency, generally an integer greater than 1, that is, F = 1/dt. Back to the problem just now, the role of points is very obvious. The system is always at 59 degrees. This KI * (60-59)/F continues to increase points over time. When the control value exceeds a certain value, the system temperature starts to rise, since the value of Uset-Unow is large before approaching the point we set, the value of this part is still credited to Uk, so the role of Ki will lead to a certain amount of overtuning of the final control amount, that is to say, after the Ki is set, the Kp value can be slightly reduced.

The last step is Kd. d Represents differential, that is, speed, which is a prediction of future trends, such as a constant temperature system, after I stop heating, the temperature does not immediately stop increasing (the temperature is too high and the temperature is caused by uneven heating of water). At this time, the output control is reduced by predicting the Rising Speed of the microcomponent, you can avoid "overhead" as much as possible. Formula UKd = UKd + Kd * (Uset-Unow) now-(Uset-Unow) before)/dt. (Uset-Unow) now is the current (Uset-Unow) value, (Uset-Unow) before is the value of the previous moment (Uset-Unow. Convert dt to F, that is, UKd = UKd + Kd * (Uset-Unow) now-(Uset-Unow) before) * F. UKd is the control value corresponding to the differential.

Okay .. The three quantities are all finished, and the final output control value Uk is the sum of these three quantities, namely UK = UKp + UKi + UKd. But in 51 single-chip microcomputer, floating-point calculation will be slow, so apart from 0, we can only set the three parameters of PID to 1, most of the time this 1 is still a very large value. So when we get the final output value, we usually perform shift processing (right shift) on this value, that is, moving n bits is equivalent to dividing by 2 to the Npower. Adjusting this n can make the output within a proper value.

The analysis of the three constants of PID is basically finished .. Eat and go to the bird first .. After dinner, I will start to write the second article-methods for adjusting the three constants of PID.

Read the PID page in Wikipedia in English. The three diagrams clearly describe the functions of these three variables ..

Http://en.wikipedia.org/wiki/PID_controller

Related Article

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.