找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3030|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

求助模糊PID控制如何在stm32中實(shí)現(xiàn)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:262876 發(fā)表于 2017-12-17 21:51 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
有哪位大神知道模糊PID控制如何在stm32中實(shí)現(xiàn)嗎???求告知。。。
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:155507 發(fā)表于 2017-12-18 17:35 | 只看該作者
  1. //======================================================================
  2. //Adjust these three factor ,to achieve the best control effect
  3. //P:1~10之間 I:0-5之間 D:0.1~1
  4. float P_Coefficient=4.75;
  5. float I_Coefficient=0.55;
  6. float D_Coefficient=0.2;
  7. #define Diff_Order 4 /* Differential order*/
  8. int Temp,DestTemp,HeatPower;
  9. int Set_Distant;
  10. long int Integral=5; // Points accumulated
  11. float Prev_Error[10]; // Record ten times before the error
  12. float P,I,D;
  13. float Ek,E;
  14. unsigned char FirstFlag=1;
  15. /*******************************************************************************
  16. * Funtion name:PID Control
  17. * Time:2013/3/5
  18. * Author:zhuhao
  19. *******************************************************************************/
  20. float PID_Control(float Error)
  21. {
  22.         int i;
  23.         float Output;
  24.         float Ture;
  25.         if(FirstFlag)//The first execution
  26.         {
  27.                 FirstFlag=0;
  28.                 for(i=0;i<10;i++)
  29.                 Prev_Error=Error;
  30.         }
  31.         for(i=0;i<10;i++)
  32.         Prev_Error[i+1]=Prev_Error;// Buffer queue
  33.         Prev_Error[0]=Error;//
  34.         Ek=Error-Prev_Error[Diff_Order];//
  35.         E=0.8+Ek*0.2;//IIR
  36.         P=P_Coefficient*Error;// Calculate the proportional component
  37.         I=I_Coefficient*Integral;// Calculate the integral component
  38.         D=D_Coefficient*E;//Calculate the derivative component
  39.         Output=(P+I+D);
  40.         if(Output>0)
  41.         {
  42.                 Ture=Output;
  43.         }
  44.         if(Output>=100||Output<=0||Error<-40||Error>40)//Saturated or large deviation integral
  45.         {
  46.                 if(Integral>0&&Error<0)
  47.                 Integral+=Error;
  48.                 if(Integral<0&&Error>0)
  49.                 Integral+=Error;
  50.         }
  51.         else
  52.         Integral+=Error;
  53.         if(Integral<-10) Integral=-10;
  54.         if(Integral>10) Integral=10;
  55.         if (Output>=100)
  56.         Output=99;
  57.         else if(Output<=0)
  58.         Output=Ture;
  59.         return Output;
  60. }

復(fù)制代碼



初次調(diào)試速度PID全過(guò)程(分享PID函數(shù))
http://www.torrancerestoration.com/bbs/dpj-42514-1.html
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表