[200722] PID without a PhD

Learn and practice on “PID without a PhD” by Tim Wescott[3]

Math

time domain

u ( t ) = K p [ e ( t ) + 1 T i ∫ e ( t ) d t + T d ∗ d e ( t ) d t ] u(t) = K_p[e(t)+\frac{1}{T_i}\int e(t)dt + T_d * d\frac{e(t)}{dt}] u(t)=Kp[e(t)+Ti1e(t)dt+Tdddte(t)]

transfer function

G ( s ) = K p ( 1 + T s / T i s + T d T s ∗ s ) G(s) = K_p (1 + \frac{T_s/T_i}{s} + \frac{T_d}{T_s} * s) G(s)=Kp(1+sTs/Ti+TsTds)

This can be simplified as:
G ( s ) = K p + K i s + K d ∗ s G(s) = K_p + \frac{K_i}{s} + K_d * s G(s)=Kp+sKi+Kds
wherein,
K i = K p ∗ T s T i K_i = K_p * \frac{T_s}{T_i} Ki=KpTiTs
K d = K p ∗ T d T s K_d = K_p * \frac{T_d}{T_s} Kd=KpTsTd
T s T_s Ts is the sampling period.

discretization

absolute class

u ( k ) = K p ∗ e ( k ) + K i ∗ ∑ i = 0 k e ( i ) + K d ∗ [ e ( k ) − e ( k − 1 ) ] u(k)= K_p*e(k) + K_i* \sum_{i=0}^{k} e(i) + K_d * [e(k) - e(k-1)] u(k)=Kpe(k)+Kii=0ke(i)+Kd[e(k)e(k1)]
wherein,
K i = K p ∗ T s T i K_i = K_p * \frac{T_s}{T_i} Ki=KpTiTs
K d = K p ∗ T d T s K_d = K_p * \frac{T_d}{T_s} Kd=KpTsTd
T s T_s Ts is the sampling period.

位置式PID是一种非递推式算法,可直接控制执行机构(如平衡小车),u(k)的值和执行机构的实际位置(如小车当前角度)是一一对应的,因此在执行机构不带积分部件的对象中可以很好应用等优点,但每次输出均与过去的状态有关,计算时要对e(k)进行累加,运算工作量大等缺点。[1]

incremental class

根据以上位置式PID算法公式推算增量式PID算法,可以求得如下形式:[1]

u ( k ) = u ( k − 1 ) + Δ u ( k ) u(k) = u(k-1) + \Delta u(k) u(k)=u(k1)+Δu(k)
wherein,
Δ u ( k ) = K p ∗ [ e ( k ) − e ( k − 1 ) ] + K i ∗ e ( k ) + K d [ e ( k ) − 2 e ( k − 1 ) + e ( k − 2 ) ] \Delta u(k) = K_p * [e(k)-e(k-1)] + K_i * e(k) + K_d [e(k)-2e(k-1)+e(k-2)] Δu(k)=Kp[e(k)e(k1)]+Kie(k)+Kd[e(k)2e(k1)+e(k2)]

增量式PID算法是一种递推式算法,误动作时影响小,必要时可用逻辑判断的方法去掉出错数据,手动/自动切换时冲击小,便于实现无扰动切换,当计算机故障时,仍能保持原值,算式中不需要累加,控制增量Δu(k)的确定仅与最近3次的采样值有关等优点,但积分截断效应大,有稳态误差,溢出的影响大,有的被控对象用增量式则不太好等缺点。

Implementation code for PI regulator

absolute class

typedef struct
{
double dState; // Last position input
double iState; // Integrator state
double iMax, iMin;
// Maximum and minimum allowable integrator state
double iGain, // integral gain
pGain, // proportional gain
dGain; // derivative gain
} SPid;
double UpdatePID(SPid * pid, double error, double
position)
{
double pTerm,
dTerm, iTerm;
pTerm = pid->pGain * error;
// calculate the proportional term
// calculate the integral state with appropriate limiting
pid->iState += error;
pid->iState = MAX(pid->iState, pid->iMin);
pid->iState = MIN(pid->iState, pid->iMax);

iTerm = pid->iGain * iState; // calculate the integral term

return pTerm + iTerm;
}

incremental class

To be added.

reference

[1] https://www.cnblogs.com/AChenWeiqiangA/p/12718473.html
[2] https://blog.csdn.net/kilotwo/article/details/79829669
[3] PID without a PhD

你可能感兴趣的:(Control,pid)