Algorithm of popular course of PID algorithm

Source: Internet
Author: User
Tags constant

First of all to help you solve what is the PID adjustment, why should such doubts.

PID is the abbreviation for the first letter of the proportional, integral, differential English word.

Here is an example to illustrate the PID, so that everyone has a sense of understanding,.

A person closed his eyes to walk, assuming he knew he was 100 meters away from the destination, then he can be 1.1-meter steps per second such speed to the destination, 100 meters just good is 100 steps, this is a very idealized phenomenon. Assuming he does not know the destination is how far, the destination may be 1000 meters or maybe 10000 meters, he used every step of 3 meters per second to speed forward, unfortunately, this destination at 80 meters, he walked 26 steps just good 2 meters, walk 27 steps have just good and more 1 meters, this is called the steady state error , if this person knows the destination in about 15 meters in the place, began the person with 1.1-meter steps per second speed, walk a step and then visual how far away from the destination, the results found that there is still about 14 meters, apparently 1.1-meter steps too slow, so this person decided to more than 1.1-meter steps per second, to arrive at a formula,

Y=kp*e (t)

Where y is the next distance to go each step, E (t) for the visual distance, that is, deviation, in other words, the distance you go and the distance to go is the error of the destination, KP is a constant, assuming we set KP to 0.5,

Y=kp*e (t) can be obtained y=7; the next step to 7 meters per second to go, repeat the process,, 7+1 a total of 8 meters, and then see how far from 15 meters away, there are 7 meters error, So the next step is to walk 3.5 meters, and then in the repetition, found that finally there will be a steady state error, that is, one more step will go beyond the destination, less walk and not to the destination. Of course, the above example is very special, you may think that the last of those errors can be ignored, but in practical applications, it is certainly no one to walk so special, according to this linear proportion of the final error will be very large, so the introduction of a concept of integral, the mathematical geometry of the integral is defined in the interval [a, b] The area of a graph with a continuous nonnegative curve and a straight line x=a,x=b. A function can be obtained from the definition of integral

Where TI is the integration time, E (t) is the error. Y is the output, it is an indefinite integral, in fact, it is integrated into the example of the above-mentioned people walk, it is a definite integral, from 0 to t time of the error of the integration of the time, that is, the error curve E (t) and the time axis around the area, integration time TI is a constant, that is, the size of From the upper formula Y is the area of the shape of E (t) and T is divided by the value of Ti,ti larger y smaller, ti smaller y larger, large system will be turbulent, so slowly adjust the coefficient.

Here is a professional description of the points and ratios:

Proportional (P) control

Proportional control is one of the simplest control methods. The output of its controller is proportional to the input error signal. The system output has a steady state error (steady-state error) when only proportional control is present.

Integral (I) control

In integral control, the output of the controller is proportional to the integral of the input error signal. For an automatic control system, if there is a steady state error after entering the steady state, it is said that the control system is a steady state error or a short differential system with steady-state error.

In order to eliminate the steady state error, "integral term" must be introduced in the controller. The integral item pairs the error depends on the time integral, increases with the time, the integral term increases. Thus, even if the error is very small, the integral item will increase with time, it pushes the controller output increase so that the steady-state error further reduced, until equal to zero.

Therefore, the proportional + integral (PI) controller can make the system have no steady state error after entering the steady state.

Differential regulation is the rate of change of the deviation value. For example, if the input deviation value changes linearly, a constant adjustment amount is superimposed on the regulator output side. Most control systems do not need to adjust the differential time. Because only systems with time lag need to attach this parameter. If this parameter is added to the lily, the control of the system will be affected.

For example, people to adjust the temperature of the pit, slowly adjust the knob, so that the temperature gradually become large, to make the temperature reached a certain fixed value, the person can slowly adjust, the side to see the temperature adjustment, if starting from this target temperature far from the fast rotary knob (proportional effect), to the last to make the temperature error small fine tuning And then actually the temperature is there is a inertia in there, beginning you to quickly adjust the speed of the knob when the temperature will not mutate, will not reach a stable value, it slowly increased to the last, but not everyone is so experienced, when he saw the temperature is so far from the target temperature, and speed up the rotary knob, The final result causes the actual temperature to differ very far from the target temperature, the fine adjustment also cannot adjust with this, finally causes the system the instability, but if this person is very experienced, he knew beforehand this temperature to have the inertia, starts it the fast rotation knob to see the temperature rise rate very high, namely the temperature change very fast, he slows down the rotation speed, The final result is to accurately adjust the temperature to the optimal (differential effect).

People can be like this, but the computer can not be adjusted, then a PID to get an output value to adjust.

Here is a professional description of the differential:

The output of the controller is proportional to the differential of the input error signal (i.e. the rate of change of the error). In the process of overcoming the error, the automatic control system may oscillate or even become unstable. The reason is that there is a large inertia component (link) or lag (delay) component, which has the effect of restraining error, and its change always lags behind the change of error. The solution is to make the change of the effect of the inhibition error "ahead", that is, when the error approaches zero, the effect of the suppression error should be zero. That is to say, only the introduction of "proportional" items in the controller is often not enough, the role of the proportional term is only the amplitude of the amplification error, and the current need to increase is "differential term", it can predict the trend of error changes, so that the controller with proportional + differential, can advance the control of the suppression error equal to zero, or even This avoids the severe overshoot of the controlled volume. Therefore, the proportional + differential (PD) controller can improve the dynamic characteristics of the system in the process of regulating the controlled object with greater inertia or hysteresis.

In summary get a formula, this is the analog PID

The following is an application-based, incremental PID algorithm. In fact, the PID algorithm can be done very deep, but not necessary, the general entry-level algorithm has been sufficient in many occasions, the reason for the use of incremental PID algorithm (there are also position PID and so on), because the incremental PID algorithm less computational, is very suitable for the application of single-chip microcomputer.

Obviously want to give a microcontroller operation, it must be digital, and the above PID is analog PID, we want to digitize him, discretization.

The integral in the above mentioned, his geometric meaning is to ask E (t) and the time axis T circumference of the area of the graph, the area is divided into T, t=0 to T=1 and E (t) surrounded by the area plus t=1 to t=2 and E (t) surrounded by the area has been accumulated ... Until the area of T-1 to T and E (t) is exactly the area of the entire E (t) and t time axis, just good is the integral of E (t) T, if the T infinity, then can be divided into an infinite number of small shapes then the area of the graph can be used t[e (1) +e (2) +.........+e (T-1) +e (T)] Instead of the integral effect, which is the point at which the ad is sampled in the entire time axis T, the faster the ad has to sample more points in the same time t, in other words, the T is closer to infinity. So the integral can be used with exhaustion and substitution.

The following is a professional explanation of the integrals

Defined

Set function f (x) bounded on [A, b], arbitrarily inserting several points in [A, b]

A=x0<x1<...<xn-1<xn=b

Divide the interval [a, b] into n small intervals

[X0,x1], ... [Xn-1,xn].

In each small interval [xi-1,xi] Take a little ξi (xi-1≤ξi≤xi), the function value f (ξi) and the small interval length of the product F (Ξi) Xi, and made and

If no matter how to divide [A, b], and no matter how the point ξi in the cell, as long as the length of the interval tends to zero, and s always tend to determine the limit I,

At this point, we call this limit I as the definite integral of the function f (x) on the interval [a, b], as

Differential is substituted by difference, the geometrical meaning of differential is explained first

We can imagine that the F (x) in the image above is replaced by E (t), the x-axis is replaced by the T-axis, the x is replaced by T, and when T is very small, the curve mn is equivalent to a straight line mn, y equals dy, so

can be used Td*[e (t)-E (t-1)]/T, the same T is sampling time ~ the smaller the better.

So the simulation PID discretization gets the output at the k-1 moment.

So get an increment

where T is the sampling time

, if the computer control system uses a constant sampling period t, once the determination of a, B, C (the selection of the coefficients is the key to the PID is not discussed here)

Compared with the position PID algorithm, the incremental PID control algorithm has much less computational capacity and 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:

is a digital recursive PID control algorithm which is widely used in computer control.

Here is the program

typedef struct PID

{

Intsetpoint; Set Target Desiredvalue

Longsumerror; Error accumulation

Doubleproportion; Proportional constant Proportional Const

Doubleintegral; Integral constant Integralconst

doublederivative; Differential constant derivative Const

Intlasterror; ERROR[-1]

Intpreverror; Error[-2]

} PID;

Static PID SPID;

static PID *sptr = &sPID;

/*====================================================================

INITIALIZEPID Structure PID Parameter initialization
===================================================================*/

void Incpidinit (void)

{

Sptr->sumerror= 0;

Sptr->lasterror= 0; ERROR[-1]

Sptr->preverror= 0; Error[-2]

sptr->proportion= 0; Proportional constant Proportional Const

Sptr->integral= 0; Integral constant Integralconst

Sptr->derivative= 0; Differential constant derivative Const

Sptr->setpoint= 0;

}

/*==================================================================== Incremental PID Calculation part
====================================================================*/

int incpidcalc (int nextpoint)

{

Registerint Ierror, Iincpid; Current error

Ierror= sptr->setpoint-nextpoint; Incremental calculation

iincpid= sptr->proportion * Ierror//e[k] Item

-sptr->integral * Sptr->lasterror//e[k-1] Item

+sptr->derivative * sptr->preverror; E[K-2] Item

Storage error, for next calculation

Sptr->preverror= sptr->lasterror;

Sptr->lasterror= Ierror;

Returns the increment value

return (IINCPID);

}

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.