C語言幾種PID控制碼

來源:互聯網
上載者:User

1.增量式PID控制演算法

void pid_control(void){offside1=standard_speed-actual_speed;//計算當前速度偏差 r1=kp*(offside1-offside2); r2=ki*offside1; pid_result=(unsigned char)(r1+r2);   //浮點數強制轉換為十六進位數 offside2=offside1;}

2.積分分離的PID控制演算法

void pid_control(void){offside1=standard_speed-actual_speed;//計算當前速度偏差r1=kp*(offside1-offside2); if ( offside1<threshold )           //對積分部分的分離計算   r2=ki*offside1;                 //threshold作為門限值 else r2=0; pid_result=(unsigned char)(r1+r2); //浮點數強制轉換為十六進位數 offside2=offside1;}

3.變速積分PID控制演算法

void pid_control(void){ float f;offside1=standard_speed-actual_speed;//計算理論速度和實際速度的偏差 r1=kp*(offside1-offside2);          //計算P參數部分 if(offisde1<=threshold1)           //速度偏差是否小於門限threshold1?   f=1;                          //是,標記f=1 else if(offside1>threshold1+threshold2)//否,再比較偏差是否超過threshold1+threshold2?   f=0;                          //是,標記f=0 else f=(threshold1+threshold2-offside1)/threshold2;  //否,重新計算f r2=ki*offside1*f;             //計算I參數部分pid_result=r1+r2+r3;   //計算出PID計算結果,D參數部分(r3)這裡認為0offside2=offside1;             //計算出速度偏差的偏差}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.