欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 增量式PID代碼C語言實現實現代碼 [打印本頁]

作者: jackhanhan    時間: 2019-3-17 11:00
標題: 增量式PID代碼C語言實現實現代碼
增量式pid語言代碼,初學者可以參考下


源程序如下:
  1. #define _PID_C
  2. #include "pid.h"
  3. #include <math.h>

  4. #define MAXOUT 1000                                //輸出最大值

  5. void IncPIDInit(void)
  6. {
  7.         sptr                        = &sPID;
  8.         sptr->SetPoint        = 700;                //設定值
  9.         sptr->BitMove        = 0;                //返回結果比例

  10.         sptr->LastError = 0;                //前2次誤差值
  11.         sptr->PrevError = 0;                //前1次誤差值

  12.         sptr->Proportion = 3;                //比例
  13.         sptr->Integral         = 0;                //積分
  14.         sptr->Derivative = 0;                //微分

  15.         sptr->iError = 0;                        //當前誤差
  16.         sptr->iIncpid=0;                        //增量誤差

  17.         sptr->Uk = 0;                                //輸出返回值
  18. }

  19. int IncPIDCalc(int NextPoint)
  20. {
  21.         //當前誤差
  22.         sptr->iError = sptr->SetPoint - NextPoint;
  23.         //增量誤差
  24.         sptr->iIncpid= sptr->Proportion * sptr->iError
  25.                                 - sptr->Integral * sptr->LastError
  26.                                 + sptr->Derivative * sptr->PrevError;
  27.         //存儲誤差,用于下次計算
  28.         sptr->PrevError = sptr->LastError;
  29.         sptr->LastError = sptr->iError;

  30.         sptr->Uk += sptr->iIncpid;

  31.         //輸出值限幅
  32.         if ((sptr->Uk>>sptr->BitMove) >= MAXOUT)
  33.         {
  34.                 sptr->Uk = MAXOUT;
  35.         }
  36.         else if((sptr->Uk>>sptr->BitMove) <= 0)
  37.         {
  38.                 sptr->Uk = 0;
  39.         }
  40.         else        sptr->Uk = sptr->Uk>>sptr->BitMove;
  41.        
  42.         return(sptr->Uk);
  43. }
復制代碼
  1. #ifndef _PID_H
  2. #ifndef _PID_H

  3. #ifdef _PID_C
  4.     #define PID_EXT
  5. #else
  6.     #define PID_EXT extern
  7. #endif

  8. typedef struct PID
  9. {
  10.         int SetPoint;
  11.        
  12.         unsigned char BitMove;
  13.        
  14.         float Proportion;
  15.         float Integral;
  16.         float Derivative;
  17.        
  18.         int iError;
  19.         int iIncpid;
  20.        
  21.         int LastError;
  22.         int PrevError;
  23.        
  24.         int Uk;
  25. }PID,*pPID;

  26. PID_EXT PID sPID;
  27. PID_EXT pPID sptr;

  28. void IncPIDInit(void);
  29. int IncPIDCalc(int NextPoint);

  30. #endif
復制代碼


所有資料51hei提供下載:
增量式PID代碼C語言實現實現.rar (1.19 KB, 下載次數: 45)







歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1