PID控制器解释及整定

PID控制器解释

PID文章索引
模拟器

说明PID:

小明接到这样一个任务:有一个水缸有点漏水(而且漏水的速度还不一定固定不变),要求水面高度维持在某个位置,一旦发现水面高度低于要求位置,就要往水缸里加水。 小明接到任务后就一直守在水缸旁边,时间长就觉得无聊,就跑到房里看小说了,每30分钟来检查一次水面高度。水漏得太快,每次小明来检查时,水都快漏完了,离要求的高度相差很远,小明改为每3分钟来检查一次,结果每次来水都没怎么漏,不需要加水,来得太频繁做的是无用功。几次试验后,确定每10分钟来检查一次。这个检查时间就称为采样周期。 开始小明用瓢加水,水龙头离水缸有十几米的距离,经常要跑好几趟才加够水,于是小明又改为用桶加,一加就是一桶,跑的次数少了,加水的速度也快了,但好几次将缸给加溢出了,不小心弄湿了几次鞋,小明又动脑筋,我不用瓢也不用桶,老子用盆,几次下来,发现刚刚好,不用跑太多次,也不会让水溢出。这个加水工具的大小就称为比例系数

小明又发现水虽然不会加过量溢出了,有时会高过要求位置比较多,还是有打湿鞋的危险。他又想了个办法,在水缸上装一个漏斗,每次加水不直接倒进水缸,而是倒进漏斗让它慢慢加。这样溢出的问题解决了,但加水的速度又慢了,有时还赶不上漏水的速度。于是他试着变换不同大小口径的漏斗来控制加水的速度,最后终于找到了满意的漏斗。漏斗的时间就称为积分时间

小明终于喘了一口,但任务的要求突然严了,水位控制的及时性要求大大提高,一旦水位过低,必须立即将水加到要求位置,而且不能高出太多,否则不给工钱。小明又为难了!于是他又开努脑筋,终于让它想到一个办法,常放一盆备用水在旁边,一发现水位低了,不经过漏斗就是一盆水下去,这样及时性是保证了,但水位有时会高多了。他又在要求水面位置上面一点将水缸要求的水平面处凿一孔,再接一根管子到下面的备用桶里这样多出的水会从上面的孔里漏出来。这个水漏出的快慢就称为微分时间
PID controller design using Arduino
img

A PID (Proportional Integral Derivative) controller works by controlling an output to bring a process value to a desired set point.
PID(比例积分微分)控制器通过控制输出将过程值调到所需的设定点来工作。

Before we dive into the PID controller, there is a few terms that need defined:
在我们深入研究 PID 控制器之前,需要定义几个术语:

PID控制器术语:

2 PID controller Arduino

Set Point 设定点

The set point is normally a user entered value, in cruise control it would be the set speed, or for a heating system, it would be the set temperature.
设定点通常是用户输入的值,在巡航控制中,它是设定速度,或者对于加热系统,它是设定温度。

Process Value 过程值

The process value is the value that is being controlled. For cruise control this would be the actual vehicle speed, or in a heating system, this would be the current temperature of the system.
过程值是正在控制的值。对于巡航控制,这将是实际的车速,或者在加热系统中,这将是系统的当前温度。

Output 输出

The output is the controlled value of a PID controller. In cruise control, the output would be the throttle valve, in a heating system, the output might be a 3 way valve in a heating loop, or the amount of fuel applied to a boiler.
输出是PID控制器的受控值。在巡航控制中,输出是油门阀,在加热系统中,输出可能是加热回路中的三通阀,或者是施加到锅炉的燃料量。

Error 错误

The error value is the value used by the PID controller to determine the how to manipulate the output to bring the process value to the set point.
误差值是 PID 控制器用来确定如何操作输出以使过程值达到设定点的值。

Error = Setpoint – Process Value

PID Controller Explained! PID控制器解释!

The basic explanation of a PID controller. The PID controller is continuously monitoring the error value, and using this value, calculates the proportional, the integral and the derivative values. The controller then adds these three values together to create the output.
PID 控制器的基本解释。 PID 控制器持续监控误差值,并利用该值计算比例值、积分值和导数值。 然后,控制器将这三个值相加,形成输出。

Below we will dive into the proportional, integral and derivative as three separate equations, then add them together to create the output, but first, we need to talk about the user input values in the PID controller… the gain settings (P-Gain, I-Gain and D-Gain).
下面我们将深入研究比例、积分和导数作为三个独立的方程,然后将它们相加以创建输出,但首先,我们需要讨论 PID 控制器中的用户输入值…增益设置(P-Gain、I-Gain 和 D-Gain)。

Gain 增益

Gain is the term used for “multiplication factor”. By adjusting the gain settings (or multiplication factor) of the proportional, the integral and the derivative, the user can control how much effect the PID controller has on the output, and how the controller will react to different changes in the process value.
增益是 "乘法系数 "的术语。 通过调整比例、积分和导数的增益设置(或乘法系数),用户可以控制 PID 控制器对输出的影响程度,以及控制器对过程值不同变化的反应。

P 或比例

ProportionalTuning the Proportional Value
调整比例值

The Proportional is calculated by multiplying the P-Gain by the error. The purpose of the proportional, is to have a large immediate reaction on the output to bring the process value close to the set point. As the error becomes less, the influence of the proportional value on the output becomes less.
比例的计算方法是 P 增益乘以误差。 比例值的目的是对输出产生较大的即时反应,使过程值接近设定点。 误差越小,比例值对输出的影响就越小。

The Proportional math looks like this:
比例运算的结果是这样的:

P = Proportional
kP = Proportional Gain 
SP = Set point
PV = Process Value
Err = Error

Err = SP – PVP = kP x Err

I 或积分

IntegralTuning the Integral Value
调整积分值

The Integral is calculated by multiplying the I-Gain, by the error, then multiplying this by the cycle time of the controller (how often the controller performs the PID calculation) and continuously accumulating this value as the “total integral”.
积分的计算方法是将 I 增益乘以误差,再乘以控制器的周期时间(控制器执行 PID 计算的频率),然后将此值作为 "总积分 "不断累加。

Explained a little further, every time the controller performs the PID calculation (example of a cycle time is every 100 ms), the new calculated integral value, is added to the integral total. The integral will normally not have as much immediate influence on the output as the proportional, but because the integral is continuously accumulating overtime, the longer it takes for the process value to reach the set point, the more effect the integral will have on the output.
再进一步解释,控制器每执行一次 PID 计算(以每 100 毫秒为一个周期为例),新计算出的积分值就会添加到积分总值中。 通常情况下,积分值对输出的直接影响不如比例值大,但由于积分值在超时时间内不断累积,过程值达到设定点所需的时间越长,积分值对输出的影响就越大。

And the Integral math:
积分计算:

I = Integral
kI = Integral Gain
dt = cycle time of the controller
It = Integral Total
I = kI x Err x dt
It = It + I
D or Derivative D 或导数

DerivativeTuning the Derivative Value
调整导数值
img
The derivative is calculated by multiplying the D-Gain by the ramp rate of the process value. The purpose of the derivative is to “predict” where the process value is going, and bias the output in the opposite direction of the proportional and integral, to hopefully prevent the controller from over-shooting the set point if the ramp rate is to fast.
导数的计算方法是将 D 增益乘以过程值的斜率。 导数的目的是 "预测 "过程值的走向,并将输出偏置到比例和积分的相反方向,以防止控制器在斜率过快的情况下过快达到设定点。

Explained a bit simpler, if the process value is approaching the set point to fast, the derivative will limit the output to prevent the process value from overshooting the set point.
解释简单一点,如果过程值接近设定点快,导数将限制输出以防止过程值超过设定点。

The Derivative Math: 导数计算:

D = Derivative
kD = Derivative Gain
dt = cycle time of the controller
pErr = Previous Error
D = kD x (Err – pErr) / dt
Output 输出

The PID controller output is calculated by simply adding the Proportional, the Integral and the Derivative. Depending on the gain setting of these three values, will determine how much effect they will have on the output.
PID控制器输出的计算方法很简单,只需将比例、积分和微分相加即可。根据这三个值的增益设置,将决定它们对输出的影响程度。

PID Controller Output Math:
PID控制器输出数学:

Output = P + It + D
All together a PID control loop looks like this; 总而言之,PID控制回路如下所示;
Err = Sp – PV

P = kP x Err

It = It + (Err x kI x dt)

D = kD x (pErr – Err) / dt

pErr = Err 

Output = P + It + D

Wait dt (100 ms), and perform loop again.
等待 dt (100 ms),然后再次执行循环。

如何调整 PID 控制器

Tuning a PID controller can be difficult knowing where to start, and what direction to go. This article will provide solutions to both of these, setting up a PID controller from scratch and more!
调整 PID 控制器可能很困难,不知道从哪里开始,以及往哪个方向走。本文将为这两个问题提供解决方案,从头开始设置PID控制器等等!

It is good to note early in this post, that there can be many values that work for the same device. The important thing is not to find the “perfect” values, but to find ones that meet the requirements, and provide desired control.
在这篇文章的前面需要注意的是,可以有许多值适用于同一设备。重要的不是找到“完美”的值,而是找到满足要求并提供所需控制的值。

Finding Initial PID Values 查找初始 PID 值

First ensure everything is mechanically sound with the device being controlled. More times than not, people will try to”tune” PID values to fix an issue, but the issue is a physical one, not an automation one. Once everything is verified, we can start to program!
首先,确保在控制设备的情况下,一切都是机械健全的。很多时候,人们会尝试“调整”PID值来解决问题,但问题是物理问题,而不是自动化问题。一旦一切都得到验证,我们就可以开始编程了!

Proportional 比例的

Tuning ProportionalTuning the Proportional Gain
调整比例增益

Start by setting the Integral and Derivative values to 0. Then increase the proportional until the controller starts to become unstable and oscillate.
首先将积分和导数值设置为 0。然后增加比例,直到控制器开始变得不稳定并振荡。

A controller where the oscillations become smaller is considered a “stable” controller, as eventually it will stabilize, and when the oscillations start getting larger is an”unstable” controller.
振荡变小的控制器被认为是“稳定”控制器,因为它最终会稳定下来,而当振荡开始变大时,就是“不稳定”控制器。

Once the proportional value that causes the controller to oscillate is found, take this value and divide it in half. This will be the starting P value.
找到导致控制器振荡的比例值后,将该值除以一半。 这就是起始 P 值。

Example: in the picture, the proportional gain that causes the controller to become unstable is 1000, so the starting proportional value will be 500.
示例:在图中,导致控制器不稳定的比例增益为 1000,因此起始比例值为 500。

Integral 积分

Tuning IntegralTuning the Integral Gain 调整积分增益

Once the proportional value is found, we can start to tune the integral. Always start with small steps when adjusting a PID controller, and give time between each adjustment to see how the controller reacts.
找到比例值后,我们就可以开始调整积分。 调整 PID 控制器时,一定要从小步开始,每次调整之间要留出时间,以观察控制器的反应。

Increase the integral gain in small increments, and with each adjustment, change the set point to see how the controller reacts.
以较小的增量增加积分增益,每次调整都要改变设定点,以观察控制器的反应。

The goal of tuning the integral value, is to achieve an adequate controller response or reaction time (after the initial response from the proportional is set).
调整积分值的目的是在设定比例初始响应后,获得足够的控制器响应或反应时间。
(在设置了比例的初始响应之后)。

If the controller starts to oscillate, or become unstable, adjust the I value in the opposite direction until the controller becomes stable again. Once the controller is stable, and responding desirably… congrats! you now have a working PI controller.
如果控制器开始振荡或变得不稳定,则朝相反方向调整 I 值,直到控制器再次稳定为止。 一旦控制器趋于稳定并做出理想的响应…恭喜!您现在拥有了一个正常工作的 PI 控制器。

Derivative 导数

DerivativeTuning the Derivative Gain
调整导数增益

There are many PI controllers out there, and for certain applications, this is all that is required. But if your application could benefit from the dampening effects of the derivative, you will need to find the value that works!
市面上有许多 PI 控制器,对于某些应用来说,这是足够的。 但是,如果您的应用可以受益于导数的阻尼效应,您就需要找到合适的值!

Now that you have a stable PI controller, start by increasing the derivative value slowly, changing the set point, and allowing time for the controller to stabilize.
现在您已经有了一个稳定的 PI 控制器,可以开始缓慢增加导数值,改变设定点,并给控制器留出稳定的时间。。

The purpose of the D value, is to monitor the ramp rate of the process value, and prevent it from overshooting the set point.
D 值的作用是监控过程值的斜率,防止其超出设定点。

Continue to change the set point and increase the derivative until the overshoot has been dampened to an acceptable level. If the controller starts to react in a negative way (unexpected changes in the output, poor control, or oscillation) lessen the D value until the controller is stable again.
继续改变设定点并增加导数,直到超调被抑制到可接受的水平。 如果控制器开始出现负面反应(输出出现意外变化、控制不佳或振荡),则减小 D 值,直至控制器恢复稳定。

Be careful when adjusting the derivative value, as a higher value is tempting – everyone wants a smooth controller don’t they? – but too high of a derivative will start to effect the output in a negative way and “fight” what the P and I values are trying to accomplish.
调整导数值时要小心,因为较高的导数值很诱人–每个人都想要一个平滑的控制器,不是吗? - 但导数值过高会对输出产生负面影响,与 P 值和 I 值想要达到的效果 “背道而驰”。

The other concern with a high D value,is if there is noise or distortion of the process value feedback, the derivative may see this as a fast change in the ramp rate, and bias the output at an undesired time.
高 D 值的另一个问题是,如果过程值反馈存在噪声或失真,导数可能会将其视为斜率的快速变化,并在不希望的时间偏置输出。

For more on tuning the derivative check out the video below.
欲了解更多关于调整导数的信息,请观看下面的视频。

Advanced Tuning of a PID Controller ,PID控制器的高级调谐

Once the initial values are found (by following the steps above), you can start to change the set point, and put the controller through some simulations to see how it react.
一旦找到初始值(按照上述步骤),就可以开始改变设定点,并对控制器进行一些模拟,看看它是如何反应的。

There is no set formula for advanced tuning of a PID controller, and no step-by-step process that will work in every scenario, but with an understanding of how a PID controller works, and enough practice, it is definitely possible. To practice tuning a PID controller, download the great PID Simulator app from the Microsoft Store!
PID控制器的高级调优没有固定的公式,也没有适用于每种场景的分步过程,但是通过了解PID控制器的工作原理和足够的实践,这绝对是可能的。

Watching how the controller reacts, will lead you towards which value (or values) should be changed.
观察控制器的反应,将引导您确定应该更改哪个值(或多个值)。

The PID controller is not reacting fast enough: PID 控制器的反应速度不够快:

Watch the initial response of the PID controller output, if the initial response is fast (a steep peak in the output) but the following few seconds seems to be slower reacting, then the integral value will need adjusting. Increase the integral gain until the desired reaction time is reached, but be careful not to go too high and cause oscillations.
观察 PID 控制器输出的初始响应,如果初始响应速度很快(输出中出现一个陡峭的峰值),但随后几秒钟的反应速度似乎较慢,则需要调整积分值。 增加积分增益,直到达到所需的反应时间,但要注意不要过高,以免引起振荡。

If the initial PID controller response (immediate response of the output), try increasing the proportional value. Note, if the proportional gain is increased, put the controller through some tests, to see if the derivative gain will also need increased to prevent the overshooting that may occur.
如果初始 PID 控制器响应(输出立即响应),请尝试增加比例值。 注意,如果增加比例增益,则需要对控制器进行一些测试,看看是否也需要增加导数增益,以防止可能出现的过冲。

The PID controller is overshooting: PID 控制器过冲:

Look at the initial response of the PID controller, if the initial response is too high, then decreasing the proportional (or possibly the integral) could correct the overshoot. However, if the reaction time is good an the PID controller is stable, then increasing the derivative slightly may be all that is required, to dampen the overshoot.
查看 PID 控制器的初始响应,如果初始响应过高,那么降低比例(或积分)可以纠正过冲。 但是,如果反应时间良好,PID 控制器稳定,则只需略微增加导数即可抑制超调。

The PID controller is not stable, or oscillating: PID 控制器不稳定或振荡:

An unstable or oscillating PID controller can be one of the most difficult to address. Before adjusting, double check that there is no external or physical forces causing the issue.
不稳定或振荡的PID控制器可能是最难解决的问题之一。在调整之前,请仔细检查是否没有外部或物理力导致问题。

If the oscillations are caused by the output spiking instantly to 100% then down to 0% and back, likely the proportional gain is set too high. Start by decreasing the derivative gain to a low setting (to ensure it is not causing the instability), then decrease the proportional gain until the controller becomes more stable.
如果振荡是由于输出瞬间骤增至 100%,然后又降至 0%,很可能是比例增益设置过高。 首先将导数增益降至较低设置(确保它不会导致不稳定),然后再降低比例增益,直到控制器变得更加稳定。

If the output is not spiking instantly, but seems to be over and undershooting, then the integral value is likely too high. Decrease the integral gain until the controller becomes stable.
如果输出不是瞬间骤增,而是出现过冲和欠冲,则可能是积分值过高。 降低积分增益,直到控制器趋于稳定。

If all else fails, you can re-set the PID values, and set-up the PID controller from the beginning as described above.
如果一切都失败了,可以重新设置 PID 值,并按照上述方法从头开始设置 PID 控制器。
PID SimulatorTo practice PID control loops, download the PID Simulator App from the Microsoft Store!
要练习 PID 控制,请从 Microsoft 商店下载 PID 模拟器应用程序!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蔚蓝慕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值