directory
1. PID algorithm concept
2. PID algorithm parameter debugging
1. PID algorithm concept
PID algorithm is one of the most widely used algorithms in industrial applications. In the control of closed-loop system, it can automatically correct the control system accurately and quickly. PID algorithm has a history of more than 100 years, and has been applied in the scenarios of four-axis aircraft, balancing car, vehicle cruise control, temperature controller and so on.
I have done tracking vehicle project before, simple tracking has a large swing range, and the effect is shown as follows:
After PID algorithm optimization, tracking stability performance is greatly improved, as shown below:
PID algorithm: Proportional, Integral and derivative. It is a common control algorithm of “keeping stability”.
The general analog PID control system principle block diagram is as follows:
Therefore, the relationship between E (t) and u(t) can be concluded:
Among them:
- Kp: proportional gain, is the adjustment parameter;
- Ki: integral gain, also an adjustment parameter;
- Kd: differential gain, also an adjustment parameter;
- E: error = set value (SP) – feedback value (PV);
- T: Current time.
The mathematical formula may be boring, through the following examples, to understand the application of PID algorithm.
For example, use a controller to keep the temperature of a pot of water at 50℃, let it heat if it is less than 50℃, and power off if it is more than 50℃.
Yes, you can do this in a less demanding situation, but if you rephrase it, you know what the problem is.
What if the object of control was a car? If you want the car to stay at 50km/h, this method is problematic.
Imagine, if the car’s cruise control computer at a certain time to measure the speed of 45km/h, it immediately command the engine: speed up!
As a result, the engine suddenly came to a 100% full throttle, hum of the car quickly accelerated to 60km/h, then the computer issued a command: brake! Result passenger vomit……
Therefore, in most occasions, with “switching quantity” to control a physical quantity is relatively simple and rough, sometimes it is unable to maintain stability, because the MCU, sensor is not infinite fast, acquisition, control takes time.
Moreover, the control object has inertia. For example, if the hot water controller is unplugged, its “residual heat”, namely thermal inertia, may make the water temperature continue to rise for a little while.
At this point you need to use the PID control algorithm.
Then WE will understand in detail the PID control algorithm of the three most basic parameters: Kp proportional gain, Ki integral gain, Kd differential gain.
1. Kp proportional gain
Kp proportional control takes the current error, which is multiplied by a positive constant Kp. The quantity we need to control, such as the water temperature, has both its current value and its desired target value.
- When the gap is close, let the heater heat “gently.”
- If, for some reason, the temperature drops a lot, give the heater a “little push.”
- If the current temperature is much lower than the target temperature, run the heater at “full power” to get the water close to the target as soon as possible.
That’s what P does, isn’t it much more “genteel” than the on-off control method?
When actually writing the program, let the deviation (target minus the current) and the adjustment device “adjustment strength”, establish a function of the relationship, you can achieve the most basic “proportional” control ~
The bigger Kp, the more aggressive the regulation, and the smaller Kp, the more conservative the regulation.
If you are making a balancing car, with P, you will find that the balancing car will “shake” back and forth near the balance Angle, which is difficult to keep steady.
2. Kd differential gain
The Kd differential control considers the future error, calculates the first derivative of the error, and multiplicates it by a positive constant Kd.
With the function of P, it is not difficult to find that only P can not make the balance station up, and the water temperature is also controlled wobbly, as if the whole system is not particularly stable and always “shaking”.
Imagine a spring: it’s in equilibrium, you pull it, you let it go, and it oscillates. Because there’s very little resistance, it oscillates for a long time before it comes back to equilibrium.
Imagine immersing the system shown above in water and pulling it again: in this case, it takes much less time to come back to equilibrium.
At this point, a control action is needed to make the “change speed” of the controlled physical quantity approach 0, which is similar to the action of “damping”.
Because, when close to the target, the control effect of P is relatively small, the closer to the target, the more gentle the effect of P, there are many internal or external factors, so that the control quantity has a small range of swing.
The function of D is to make the velocity of the physical quantity go to zero, and whenever the quantity has a velocity, D tries to stop the change by exerting force in the opposite direction.
The larger the Kd parameter, the stronger the braking force in the opposite direction of the speed. If the car is balanced, with P and D control, if the parameters are properly adjusted, it should be able to stand up.
3. Ki integral gain
Ki integral control considers past errors by multiplying the sum of the error values over a period of time by a positive constant Ki.
Let’s take hot water, let’s say someone brings a heater to a very cold place and starts boiling water, and it needs to go to 50 degrees Celsius.
Under the action of P, the water temperature gradually rose until it reached 45℃. Then he found a bad thing: it was too cold, and the rate of water cooling was equal to the rate of heating controlled by P.
What can I do?
- Brother P thinks like this: I am very close to the target, I just need to gently heat it up.
- Brother D thinks like this: heating and cooling are equal, the temperature does not fluctuate, I don’t seem to have to adjust anything.
As a result, the water temperature stays at 45℃ forever and never reaches 50℃.
According to common sense, we know that the heating power should be further increased, but how to calculate how much increase?
The older scientists thought of a really clever method, set a product component, as long as the deviation exists, the deviation is constantly integrated (cumulative), and reflected in the adjustment force.
In this way, even if 45℃ and 50℃ difference is not too big, but as time goes by, as long as the target temperature is not reached, the product component is increasing, the system will slowly realize: has not reached the target temperature, the increase of power!
After reaching the target temperature, assuming that the temperature does not fluctuate, the integral value will not change any more. At this time, the heating power is still equal to the heat dissipation power, but the temperature is a stable 50℃.
The larger the value of Ki is, the larger the coefficient multiplied by the integration will be, and the more obvious the integration effect will be. Therefore, the function of I is to reduce the error in the static case and make the controlled physical quantity as close to the target value as possible.
There is also a problem with the use of I: you need to set integral limits so that when you first start heating up, you don’t get too big of an integral component.
2. PID algorithmParameter debugging
Parameter debugging of PID algorithm refers to the adjustment of control parameters (proportional gain, integral gain/time, differential gain/time) to achieve the best control effect of the system.
Stability (no divergent oscillations) is a primary requirement during debugging, and different systems have different behaviors, different applications have different requirements, and these requirements may conflict with each other.
PID algorithm has only three parameters, easy to explain in principle, but PID algorithm parameter debugging is a difficult work, because to meet some special criteria, and PID control has its limitations.
1. Stability
If the parameters of PID algorithm controller are not properly selected, the controller output may be unstable, that is, its output is divergent, there may be oscillation in the process, or there may be no oscillation, and its output is only limited by saturation or mechanical damage. Instability is generally caused by excessive gain, especially for systems with long delay times.
2, the best performance
The optimal performance of PID controllers may depend on process changes or set point changes, and may vary by application.
The two basic requirements are regulation (interference rejection, keeping the system at a set point) and command following (the speed at which the controller output responds to a change in the set point). Some criteria for command following include rising time and setting time. Some applications may not allow the output to exceed the set point for safety reasons, while others require that the energy needed to reach the set point be minimized.
3. Comparison of debugging methods
4. Adjust the impact of PID parameters on the system
Extended learning:
To understand I2C communication
Understand Modbus protocol
Understand TCP’s three-way handshake and four-way wave
To understand the design and use of three stage tube and field effect tube drive circuit
References:
PID principle and parameter debugging
Who ever thought, listened to a story seconds understand PID!