最近看到了Brett Beauregard發表的有關PID的系列文章,感覺對於理解PID算法很有幫助,於是將系列文章翻譯過來!在自我提高的過程中,也希望對同道中人有所幫助。作者Brett Beauregard的原文網址:http://brettbeauregard.com/blog/2011/07/pid-when-should-i-compute-the-integral-term/
最近有一個建議張貼到初學者的PID系列。爭議的焦點是,如果您解決拉普拉斯域中的問題,它指定了執行積分項的不同方式。評論人士建議,與其看某一點的誤差總和,不如看最後一個點的總和。
因此,當前的代碼是這樣的:
/*Compute all the working error variables*/
double input = *myInput;
double error = *mySetpoint - input;
ITerm+= (ki * error);
if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
double dInput = (input - lastInput);
/*Compute PID Output*/
double output = kp * error + ITerm- kd * dInput;
建議是這樣的:
/*Compute all the working error variables*/
double input = *myInput;
double error = *mySetpoint - input;
double dInput = (input - lastInput);
/*Compute PID Output*/
double output = kp * error + ITerm- kd * dInput;
ITerm+= (ki * error);
if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
我從未見過這樣做,但我想我應該試一試。我設計的測試是一個簡單的設定值階躍,然後是一個斜坡下降。
當控制器設置爲默認的採樣時間時,差異是無法察覺的。爲了突出這兩種方法之間的差異,我決定將PID採樣時間從默認值100mS提高到5秒。
這裏我們可以看到一個明顯的贏家。現有的PID代碼的性能比建議的要好,這可能是因爲積分項對進程更改的響應要早5秒。但是爲了確保我沒有遺漏任何東西,我決定再做一次測試。我沒有改變設定值,而是在系統中引入了負載變化。
同樣,現有的 PID 代碼性能更好,處理負載變化更快。
那麼判決呢?雖然這是一個有趣的鍛鍊,但我認爲結果很清楚。我會保持原來的代碼。
歡迎關注: